userver: cache::LruSet< T, Hash, Equal > Class Template Reference
Loading...
Searching...
No Matches
cache::LruSet< T, Hash, Equal > Class Template Referencefinal

#include <userver/cache/lru_set.hpp>

Detailed Description

template<typename T, typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
class cache::LruSet< T, Hash, Equal >

LRU set, thread safety matches Standard Library thread safety

Definition at line 17 of file lru_set.hpp.

Public Member Functions

 LruSet (size_t max_size, const Hash &hash=Hash(), const Equal &equal=Equal())
 
 LruSet (LruSet &&lru) noexcept=default
 
 LruSet (const LruSet &lru)=delete
 
LruSetoperator= (LruSet &&lru) noexcept=default
 
LruSetoperator= (const LruSet &lru)=delete
 
bool Put (const T &key)
 
void Erase (const T &key)
 Removes key from LRU.
 
bool Has (const T &key)
 Checks whether the key in LRU and updates its usage.
 
void SetMaxSize (size_t new_max_size)
 Sets the max size of the LRU, truncates values if new_max_size < GetSize()
 
void Invalidate ()
 Removes all the elements.
 
template<typename Function >
void VisitAll (Function &&func) const
 Call Function(const T&) for all items.
 
size_t GetSize () const
 
const T * GetLeastUsed ()
 

Constructor & Destructor Documentation

◆ LruSet()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
cache::LruSet< T, Hash, Equal >::LruSet ( size_t max_size,
const Hash & hash = Hash(),
const Equal & equal = Equal() )
inlineexplicit

Definition at line 19 of file lru_set.hpp.

Member Function Documentation

◆ Erase()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
void cache::LruSet< T, Hash, Equal >::Erase ( const T & key)
inline

Removes key from LRU.

Definition at line 33 of file lru_set.hpp.

◆ GetLeastUsed()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
const T * cache::LruSet< T, Hash, Equal >::GetLeastUsed ( )
inline

Returns pointer to the least recently used element or nullptr if LruSet is empty.

Warning
Returned pointer may be freed on the next set access!

Definition at line 58 of file lru_set.hpp.

◆ GetSize()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
size_t cache::LruSet< T, Hash, Equal >::GetSize ( ) const
inline

Definition at line 53 of file lru_set.hpp.

◆ Has()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
bool cache::LruSet< T, Hash, Equal >::Has ( const T & key)
inline

Checks whether the key in LRU and updates its usage.

Definition at line 36 of file lru_set.hpp.

◆ Invalidate()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
void cache::LruSet< T, Hash, Equal >::Invalidate ( )
inline

Removes all the elements.

Definition at line 44 of file lru_set.hpp.

◆ Put()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
bool cache::LruSet< T, Hash, Equal >::Put ( const T & key)
inline

Adds key to the LRU or updates its usage

Returns
true if key is a new one

Definition at line 30 of file lru_set.hpp.

◆ SetMaxSize()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
void cache::LruSet< T, 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 39 of file lru_set.hpp.

◆ VisitAll()

template<typename T , typename Hash = std::hash<T>, typename Equal = std::equal_to<T>>
template<typename Function >
void cache::LruSet< T, Hash, Equal >::VisitAll ( Function && func) const
inline

Call Function(const T&) for all items.

Definition at line 48 of file lru_set.hpp.


The documentation for this class was generated from the following file: