59 return { ++Current_ };
79 template<
typename K,
typename V,
typename CS = CacheStrat::LRU>
86 typename CS::ValueAddon CacheInfo_;
89 QHash<K, ValueHolder> Hash_;
91 size_t CurrentCost_ = 0;
92 const size_t MaxCost_;
97 : MaxCost_ { maxCost }
101 size_t size ()
const;
110 template<
typename K,
typename V,
typename CS>
113 return Hash_.size ();
116 template<
typename K,
typename V,
typename CS>
120 CacheStratState_.Clear ();
123 template<
typename K,
typename V,
typename CS>
126 return Hash_.contains (k);
129 template<
typename K,
typename V,
typename CS>
132 if (!Hash_.contains (key))
134 Hash_.insert (key, { {}, 1, CacheStratState_.CreateInfo () });
140 CacheStratState_.Touch (Hash_ [key].CacheInfo_);
142 return Hash_ [key].V_;
145 template<
typename K,
typename V,
typename CS>
148 while (CurrentCost_ > MaxCost_)
150 const auto pos = std::min_element (Hash_.begin (), Hash_.end (),
151 [] (
const ValueHolder& left,
const ValueHolder& right)
152 {
return left.CacheInfo_ < right.CacheInfo_; });
153 CurrentCost_ -= pos->Cost_;
void Touch(ValueAddon &add)
AssocCache(size_t maxCost)
bool contains(const K &) const
bool operator<(const LRU::ValueAddon &v1, const LRU::ValueAddon &v2)
V & operator[](const K &)