24 template <
typename Key,
typename Value,
typename Compare = std::less<Key>>
28 using List = std::list<value_type>;
44 Value&
at(
const Key& key,
bool touching =
true) {
47 throw std::out_of_range(
"Key not found");
50 touch(lookup_it->second);
52 return lookup_it->second->second;
56 void insert(
const Key& key,
const Value& value) {
59 touch(lookup_it->second);
60 lookup_it->second->second = value;
75 touch(lookup_it->second);
76 return lookup_it->second->second;
85 return new_iter->second;
96 touch(lookup_it->second);
98 return lookup_it->second;
102 bool contains(
const Key& key,
bool touching =
true) {
103 return find(key, touching) !=
end();
Definition: lru_cache.hh:25
typename List::const_iterator const_iterator
Definition: lru_cache.hh:30
iterator find(const Key &key, bool touching=true)
Definition: lru_cache.hh:90
iterator erase(iterator &it)
Definition: lru_cache.hh:122
size_t size_type
Definition: lru_cache.hh:31
void touch(iterator &it)
Definition: lru_cache.hh:37
void resize(size_t new_size)
Definition: lru_cache.hh:146
Value & at(const Key &key, bool touching=true)
Definition: lru_cache.hh:44
bool empty() const
Definition: lru_cache.hh:135
void evict()
Definition: lru_cache.hh:164
LRUcache(size_t capacity)
Definition: lru_cache.hh:34
Value & operator[](const Key &key)
Definition: lru_cache.hh:71
iterator begin()
Definition: lru_cache.hh:154
std::map< Key, iterator, Compare > cache_lookup
Definition: lru_cache.hh:161
size_t size() const
Definition: lru_cache.hh:140
void insert(const Key &key, const Value &value)
Definition: lru_cache.hh:56
size_t erase(const Key &key)
Definition: lru_cache.hh:107
void clear()
Definition: lru_cache.hh:129
size_t max_size
Definition: lru_cache.hh:162
List cache_list
Definition: lru_cache.hh:160
iterator end()
Definition: lru_cache.hh:155
std::pair< Key, Value > value_type
Definition: lru_cache.hh:27
typename List::iterator iterator
Definition: lru_cache.hh:29
std::list< value_type > List
Definition: lru_cache.hh:28
bool contains(const Key &key, bool touching=true)
Definition: lru_cache.hh:102
iterator erase(const_iterator &it)
Definition: lru_cache.hh:118