template<typename T, typename U, typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
class cache::LruMap< T, U, Hash, Equal >
LRU key value storage (LRU cache), thread safety matches Standard Library thread safety
Definition at line 18 of file lru_map.hpp.
|
| LruMap (size_t max_size, const Hash &hash=Hash(), const Equal &equal=Equal()) |
|
| LruMap (LruMap &&lru) noexcept=default |
|
| LruMap (const LruMap &lru)=delete |
|
LruMap & | operator= (LruMap &&lru) noexcept=default |
|
LruMap & | operator= (const LruMap &lru)=delete |
|
bool | Put (const T &key, U value) |
|
template<typename... Args> |
U * | Emplace (const T &key, Args &&... args) |
|
void | Erase (const T &key) |
| Removes key from LRU.
|
|
U * | Get (const T &key) |
|
U | GetOr (const T &key, const U &default_value) |
|
U * | GetLeastUsed () |
|
void | SetMaxSize (size_t new_max_size) |
| Sets the max size of the LRU, truncates values if new_max_size < GetSize()
|
|
void | Clear () |
| Removes all the elements.
|
|
template<typename Function > |
void | VisitAll (Function &&func) const |
| Call Function(const T&, const U&) for all items.
|
|
template<typename Function > |
void | VisitAll (Function &&func) |
| Call Function(const T&, U&) for all items.
|
|
size_t | GetSize () const |
|
std::size_t | GetCapacity () const |
|
template<typename T , typename U , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
template<typename... Args>
U * cache::LruMap< T, U, Hash, Equal >::Emplace |
( |
const T & | key, |
|
|
Args &&... | args ) |
|
inline |
Returns pointer to value if the key is in LRU and updates its usage; constructs and adds a new key/value otherwise.
- Warning
- Returned pointer may be freed on the next map access!
Definition at line 36 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
void cache::LruMap< T, U, Hash, Equal >::SetMaxSize |
( |
size_t | new_max_size | ) |
|
|
inline |
Sets the max size of the LRU, truncates values if new_max_size < GetSize()
Definition at line 62 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
template<typename Function >
void cache::LruMap< T, U, Hash, Equal >::VisitAll |
( |
Function && | func | ) |
|
|
inline |
Call Function(const T&, U&) for all items.
Definition at line 75 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
template<typename Function >
void cache::LruMap< T, U, Hash, Equal >::VisitAll |
( |
Function && | func | ) |
const |
|
inline |
Call Function(const T&, const U&) for all items.
Definition at line 69 of file lru_map.hpp.