20#include <unordered_map>
30template<
typename K,
typename V>
35 using iterator =
typename std::list<kv_pair>::iterator;
44 [[maybe_unused]] V *
insert(
const K &key,V &&value)
54 std::exchange(it->second->second,value);
55 return &it->second->second;
67 [[maybe_unused]] V *
insert(
const K &key,
const V &value)
77 it->second->second = value;
78 return &it->second->second;
116 return &it->second->second;
std::pair< K, V > kv_pair
V * insert(const K &key, V &&value)
Inserts value under key in the cache.
std::list< kv_pair > m_cacheItemList
V * insert(const K &key, const V &value)
Inserts value under key in the cache.
typename std::list< kv_pair >::const_iterator const_iterator
V * find(const K &key)
Finds a value in the cache given the corresponding key.
const_iterator begin() const
size_t capacity() const
Returns the maximum number of values that can be stored in the cache.
typename std::list< kv_pair >::iterator iterator
size_t size() const
Returns the number of values stored in the cache.
const_iterator end() const
void clear()
Clears all values in the cache.
Cache(size_t capacity)
creates a cache that can hold capacity elements
uint64_t misses() const
Returns how many of the find() calls did not found a value in the cache.
void remove(const K &key)
Removes entry key from the cache.
std::unordered_map< K, iterator > m_cacheItemMap
uint64_t hits() const
Returns how many of the find() calls did find a value in the cache.