28 #ifndef YSL_INC_Core_Cache_hpp_
29 #define YSL_INC_Core_Cache_hpp_ 1
32 #include YFM_YSLib_Core_YShellDefinition
34 #include YFM_YSLib_Adaptor_YContainer
45 template<
typename _tKey,
typename _tMapped,
typename _fHash = std::hash<_tKey>,
46 typename _fEqual = std::equal_to<_tKey>,
47 class _tAlloc = std::allocator<pair<const _tKey, _tMapped>>>
49 :
private unordered_map<_tKey, _tMapped, _fHash, _fEqual, _tAlloc>
52 using Map = unordered_map<_tKey, _tMapped, _fHash, _fEqual, _tAlloc>;
54 using UseCache = unordered_multimap<_tKey,
typename UseList::iterator,
55 _fHash, _fEqual, _tAlloc>;
56 using typename Map::const_iterator;
57 using typename Map::iterator;
58 using typename Map::key_type;
59 using typename Map::size_type;
95 SetMaxUse(size_type
s)
114 template<
typename... _tParams>
115 pair<typename Map::iterator, bool>
128 const auto& k(pr.first->first);
180 template<
class _tMap,
typename _tKey,
typename _fCallable,
typename... _tParams>
183 _tParams&&...
args) -> decltype((cache.begin()->second))
185 auto i(cache.find(key));
189 const auto pr(cache.emplace(key, init(
yforward(
args)...)));
iterator find(const key_type &k)
yconstfn const string _tParams && args
DefDeMoveCtor(GMRUCache) private
unordered_multimap< YSLib::Drawing::Typeface::BitmapKey, typename UseList::iterator, YSLib::Drawing::Typeface::BitmapKeyHash, _fEqual, _tAlloc > UseCache
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
GMRUCache(size_type s=15U)
#define YB_UNLIKELY(expr)
分支预测提示。
size_type max_use
保持可以再增加一个缓存项的最大容量。
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
unordered_map< YSLib::Drawing::Typeface::BitmapKey, YSLib::Drawing::Typeface::SmallBitmapData, YSLib::Drawing::Typeface::BitmapKeyHash, _fEqual, _tAlloc > Map
const_iterator find(const key_type &k) const
DefGetter(const ynothrow, size_type, MaxUse, max_use) void SetMaxUse(size_type s)
list< YSLib::Drawing::Typeface::BitmapKey, _tAlloc > UseList
auto CacheLookup(_tMap &cache, const _tKey &key, _fCallable init, _tParams &&...args) -> decltype((cache.begin() ->second))
以指定的关键字查找作为缓存的无序关联容器, 若没有找到使用指定的可调用对象和参数初始化内容。 ...
pair< typename Map::iterator, bool > emplace(_tParams &&...args)
bool is_undereferenceable(const any_input_iterator< _type, _tDifference, _tPointer, _tReference > &i)
#define ynoexcept(...)
YSLib 无异常抛出保证:指定特定的异常规范。
#define YAssert(_expr, _msg)