11#ifndef INCLUDED_O3TL_LRU_MAP_HXX
12#define INCLUDED_O3TL_LRU_MAP_HXX
17#include <unordered_map>
64template <
typename Key,
typename Value,
class KeyHash = std::hash<Key>,
65 class KeyEqual = std::equal_to<Key>,
class ValueSize =
void>
72 typedef std::list<key_value_pair_t>
list_t;
76 typedef std::unordered_map<Key, list_iterator_t, KeyHash, KeyEqual>
map_t;
87 if constexpr (!std::is_void_v<ValueSize>)
88 this->mCurrentSize += ValueSize()(
value);
94 if constexpr (!std::is_void_v<ValueSize>)
96 size_t itemSize = ValueSize()(
value);
97 assert(itemSize <= this->mCurrentSize);
98 this->mCurrentSize -= itemSize;
113 if constexpr (std::is_void_v<ValueSize>)
129 if constexpr (!std::is_void_v<ValueSize>)
139 if constexpr (std::is_void_v<ValueSize>)
146 while (this->mCurrentSize >
mMaxSize)
153 if constexpr (!std::is_void_v<ValueSize>)
158 assert(this->mCurrentSize == 0);
160 this->mCurrentSize = 0;
210 i->second->second = rPair.second;
225 mLruList.push_front(std::move(rPair));
236 i->second->second = std::move(rPair.second);
260 template <
class UnaryPredicate>
void remove_if(UnaryPredicate pred)
269 it =
decltype(it){
mLruList.erase(std::next(it).base()) };
size_t total_size() const
void insert(key_value_pair_t &rPair)
list_const_iterator_t const_iterator
std::list< key_value_pair_t > list_t
void addSize(const Value &value)
void checkLRUItemInsert()
map_t::const_iterator map_const_iterator_t
void checkLRUItemUpdate()
void removeSize(const Value &value)
list_const_iterator_t end() const
void remove_if(UnaryPredicate pred)
std::unordered_map< Key, list_iterator_t, KeyHash, KeyEqual > map_t
list_t::const_iterator list_const_iterator_t
std::pair< Key, Value > key_value_pair_t
list_const_iterator_t begin() const
map_t::iterator map_iterator_t
list_t::iterator list_iterator_t
list_const_iterator_t find(const Key &key)
void insert(key_value_pair_t &&rPair)
void setMaxSize(size_t nMaxSize)