template<typename T, typename U, typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
class cache::LruMap< T, U, Hash, Equal >
LRU key value storage (LRU cache), thread safety matches Standard Library thread safety
Definition at line 22 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) |
|
template<class Key > |
U * | GetTransparent (const Key &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<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<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 40 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
Returns pointer to value if the key is in LRU and updates its usage; returns nullptr otherwise.
- Warning
- Returned pointer may be freed on the next map access!
Definition at line 50 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
Returns pointer to the least recently used value; returns nullptr if LRU is empty.
- Warning
- Returned pointer may be freed on the next map access!
Definition at line 71 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
U cache::LruMap< T, U, Hash, Equal >::GetOr |
( |
const T & |
key, |
|
|
const U & |
default_value |
|
) |
| |
|
inline |
Returns value by key and updates its usage; returns default_value otherwise without modifying the cache.
Definition at line 62 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
template<class Key >
U * cache::LruMap< T, U, Hash, Equal >::GetTransparent |
( |
const Key & |
key | ) |
|
|
inline |
Returns pointer to value if the key is in LRU and updates its usage; returns nullptr otherwise.
- Warning
- Returned pointer may be freed on the next map access!
Definition at line 56 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<T>>>
bool cache::LruMap< T, U, Hash, Equal >::Put |
( |
const T & |
key, |
|
|
U |
value |
|
) |
| |
|
inline |
Adds or rewrites key/value, updates its usage
- Returns
- true if key is a new one
Definition at line 34 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<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 74 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<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 87 of file lru_map.hpp.
template<typename T , typename U , typename Hash = std::hash<impl::StringToStringView<T>>, typename Equal = std::equal_to<impl::StringToStringView<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 81 of file lru_map.hpp.