LibreOffice Module stoc (master) 1
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey > Class Template Reference

Implementation of a least recently used (lru) cache. More...

#include <lru_cache.h>

Collaboration diagram for stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >:
[legend]

Classes

struct  Entry
 

Public Member Functions

 lru_cache ()
 Default Ctor. More...
 
t_val const * lookup (t_key const &key) const
 Retrieves a pointer to value in cache. More...
 
void set (t_key const &key, t_val const &val)
 Sets a value to be cached for given key. More...
 
void setSize (::std::size_t size)
 Sets the number of elements to be cached. More...
 

Private Types

typedef std::unordered_map< t_key, Entry *, t_hashKey, t_equalKey > t_key2element
 

Private Member Functions

void toFront (Entry *entry) const
 

Private Attributes

t_key2element m_key2element
 
::std::size_t m_size
 
std::unique_ptr< Entry[]> m_block
 
Entrym_head
 
Entrym_tail
 

Detailed Description

template<typename t_key, typename t_val, typename t_hashKey, typename t_equalKey>
class stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >

Implementation of a least recently used (lru) cache.

Definition at line 41 of file lru_cache.h.

Member Typedef Documentation

◆ t_key2element

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
typedef std::unordered_map< t_key, Entry *, t_hashKey, t_equalKey > stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::t_key2element
private

Definition at line 50 of file lru_cache.h.

Constructor & Destructor Documentation

◆ lru_cache()

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lru_cache
inline

Default Ctor.

Does not cache.

Definition at line 107 of file lru_cache.h.

Member Function Documentation

◆ lookup()

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
t_val const * stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::lookup ( t_key const &  key) const
inline

Retrieves a pointer to value in cache.

Returns 0, if none was found.

Parameters
keya key
Returns
pointer to value or 0

Definition at line 139 of file lru_cache.h.

References stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::Entry::m_key, stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::Entry::m_val, and SAL_INFO.

◆ set()

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
void stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::set ( t_key const &  key,
t_val const &  val 
)
inline

Sets a value to be cached for given key.

Parameters
keya key
vala value

Definition at line 163 of file lru_cache.h.

References stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::Entry::m_key, stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::Entry::m_val, and SAL_INFO.

◆ setSize()

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
void stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::setSize ( ::std::size_t  size)
inline

Sets the number of elements to be cached.

This will clear previous entries.

Parameters
cacheSizenumber of elements to be cached

Definition at line 86 of file lru_cache.h.

References stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::Entry::m_pred, nPos, and size.

◆ toFront()

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
void stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::toFront ( Entry entry) const
inlineprivate

Member Data Documentation

◆ m_block

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
std::unique_ptr<Entry[]> stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::m_block
private

Definition at line 54 of file lru_cache.h.

◆ m_head

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
Entry* stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::m_head
mutableprivate

Definition at line 55 of file lru_cache.h.

◆ m_key2element

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
t_key2element stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::m_key2element
private

Definition at line 51 of file lru_cache.h.

◆ m_size

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
::std::size_t stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::m_size
private

Definition at line 52 of file lru_cache.h.

◆ m_tail

template<typename t_key , typename t_val , typename t_hashKey , typename t_equalKey >
Entry* stoc_sec::lru_cache< t_key, t_val, t_hashKey, t_equalKey >::m_tail
mutableprivate

Definition at line 56 of file lru_cache.h.


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