tlx
Loading...
Searching...
No Matches
LruCacheSet< Key, Alloc > Class Template Reference

This is an expected O(1) LRU cache which contains a set of key-only elements. More...

#include <lru_cache.hpp>

Public Member Functions

 LruCacheSet (const Alloc &alloc=Alloc())
void clear ()
 clear LRU
void put (const Key &key)
 put or replace/touch item in LRU cache
void touch (const Key &key)
 touch value from LRU cache for key.
bool touch_if_exists (const Key &key) noexcept
 touch value from LRU cache for key.
void erase (const Key &key)
 remove key from LRU cache
bool erase_if_exists (const Key &key) noexcept
 remove key from LRU cache
bool exists (const Key &key) const
 test if key exists in LRU cache
size_t size () const noexcept
 return number of items in LRU cache
Key pop ()
 return the least recently used key value pair

Protected Types

using List
using ListIterator
using Map

Private Attributes

List list_
 list of entries in least-recently used order.
Map map_
 map for accelerated access to keys

Detailed Description

template<typename Key, typename Alloc = std::allocator<Key>>
class tlx::LruCacheSet< Key, Alloc >

This is an expected O(1) LRU cache which contains a set of key-only elements.

Elements can be put() into LRU cache, and tested for existence using exists(). Insertion and touch() will remark the elements as most recently used, pushing all other back in priority. The LRU cache itself does not limit the number of items, because it has no eviction mechanism. Instead, the user program must check size() after an insert and may extract the least recently used element.

Definition at line 42 of file lru_cache.hpp.

Member Typedef Documentation

◆ List

template<typename Key, typename Alloc = std::allocator<Key>>
using List
protected

Definition at line 45 of file lru_cache.hpp.

◆ ListIterator

template<typename Key, typename Alloc = std::allocator<Key>>
using ListIterator
protected

Definition at line 46 of file lru_cache.hpp.

◆ Map

template<typename Key, typename Alloc = std::allocator<Key>>
using Map
protected

Definition at line 48 of file lru_cache.hpp.

Constructor & Destructor Documentation

◆ LruCacheSet()

template<typename Key, typename Alloc = std::allocator<Key>>
LruCacheSet ( const Alloc & alloc = Alloc())
inlineexplicit

Definition at line 54 of file lru_cache.hpp.

Member Function Documentation

◆ clear()

template<typename Key, typename Alloc = std::allocator<Key>>
void clear ( )
inline

clear LRU

Definition at line 59 of file lru_cache.hpp.

◆ erase()

template<typename Key, typename Alloc = std::allocator<Key>>
void erase ( const Key & key)
inline

remove key from LRU cache

Definition at line 102 of file lru_cache.hpp.

◆ erase_if_exists()

template<typename Key, typename Alloc = std::allocator<Key>>
bool erase_if_exists ( const Key & key)
inlinenoexcept

remove key from LRU cache

Definition at line 114 of file lru_cache.hpp.

◆ exists()

template<typename Key, typename Alloc = std::allocator<Key>>
bool exists ( const Key & key) const
inline

test if key exists in LRU cache

Definition at line 125 of file lru_cache.hpp.

◆ pop()

template<typename Key, typename Alloc = std::allocator<Key>>
Key pop ( )
inline

return the least recently used key value pair

Definition at line 135 of file lru_cache.hpp.

◆ put()

template<typename Key, typename Alloc = std::allocator<Key>>
void put ( const Key & key)
inline

put or replace/touch item in LRU cache

Definition at line 65 of file lru_cache.hpp.

◆ size()

template<typename Key, typename Alloc = std::allocator<Key>>
size_t size ( ) const
inlinenoexcept

return number of items in LRU cache

Definition at line 130 of file lru_cache.hpp.

◆ touch()

template<typename Key, typename Alloc = std::allocator<Key>>
void touch ( const Key & key)
inline

touch value from LRU cache for key.

Definition at line 80 of file lru_cache.hpp.

◆ touch_if_exists()

template<typename Key, typename Alloc = std::allocator<Key>>
bool touch_if_exists ( const Key & key)
inlinenoexcept

touch value from LRU cache for key.

Definition at line 92 of file lru_cache.hpp.

Member Data Documentation

◆ list_

template<typename Key, typename Alloc = std::allocator<Key>>
List list_
private

list of entries in least-recently used order.

Definition at line 147 of file lru_cache.hpp.

◆ map_

template<typename Key, typename Alloc = std::allocator<Key>>
Map map_
private

map for accelerated access to keys

Definition at line 149 of file lru_cache.hpp.


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