LRUHashMap< K, V, MAXENTRIES > Class Template Reference

#include <lruhashmap.h>

详细描述

template<typename K, typename V, Int MAXENTRIES>
class maxon::LRUHashMap< K, V, MAXENTRIES >

LRUHashMap is a specialized HashMap which is able to restrict the number of elements in the HashMap . The map keeps the LRU (last recently used) elements and destroys the most unused values if a the number of elements exceeds the limit (MAXENTRIES). The class can be used to cache a limited number of elements.

Template Parameters
K KEY type of the hash map.
V VALUE type of the hash map.
MAXENTRIES Maximum number of elements to store.

公共成员函数

  ~LRUHashMap ()
template<typename KEY >
ResultRef < V >  InsertKey (KEY &&key, Bool &created= BoolLValue ())
template<typename KEY >
const V *  FindValue (const KEY &key) const
template<typename KEY >
V *  FindValue (const KEY &key)
Int   GetCount () const
void  重置 ()
template<typename KEY >
ResultOk < void >  Erase (const KEY &key)

Private Types

using  ListNodeType = BaseListNode < V >
using  LastNodeHead = BaseListHead < V, ListNodeType >
using  HashMapType = HashMap < K, ListNodeType >

私有成员函数

void  UpdateEntry (typename HashMapType::Entry *entry) const

Private Attributes

HashMapType   _hashMap
LastNodeHead   _lastUsed

Member Typedef Documentation

◆  ListNodeType

using ListNodeType = BaseListNode <V>
private

◆  LastNodeHead

using LastNodeHead = BaseListHead <V, ListNodeType >
private

◆  HashMapType

using HashMapType = HashMap <K, ListNodeType >
private

构造函数 & 析构函数文档编制

◆  ~LRUHashMap()

~ LRUHashMap ( )

成员函数文档编制

◆  InsertKey()

ResultRef <V> InsertKey ( KEY &&  key ,
Bool created = BoolLValue()  
)

Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).

参数
[in] key Key of the value to find or create.
[out] created This will be set to true if a new entry has been created successfully, otherwise it will be set to false.
返回
Pointer to value for the given key, or nullptr if an entry didn't exist and allocation of a new entry failed.

◆  FindValue() [1/2]

const V* FindValue ( const KEY &  key ) const

Finds the value associated with the given key in this map.

Template Parameters
KEY Type of key.
参数
[in] key Key to search for.
返回
Pointer to value for the given key, or nullptr if no entry exists for the key.

◆  FindValue() [2/2]

V* FindValue ( const KEY &  key )

Finds the value associated with the given key in this map.

Template Parameters
KEY Type of key.
参数
[in] key Key to search for.
返回
Pointer to value for the given key, or nullptr if no entry exists for the key.

◆  GetCount()

Int GetCount ( ) const

Returns the number of entries in this map.

返回
Number of entries.

◆  Reset()

void Reset ( )

Resets the map. This destructs all entries and frees any memory held by the map, so the map will be in a state as if it had been newly constructed.

另请参阅
Flush()

◆  Erase()

ResultOk <void> Erase ( const KEY &  key )

Removes an entry with the given key from this HashMap (if possible). In case of a multi-map, this only removes a single entry. The type KEY of the given key need not be the same as K, but then you have to provide an additional class KEYHASH to compute the hash code of the specified key (function KEYHASH::GetHashCode(const KEY&)), and to compare a key of type KEY with a key of type K for equality (function KEYHASH::IsEqual(const KEY&, const K&)) unless the default HASH class is already able to do so.

Template Parameters
KEY Type of key.
参数
[in] key An entry having this key shall be removed.
返回
Always true for a HashMap (even if key isn't contained in the map). For a general map, false indicates an out-of-memory condition on removal, but this cannot happen for a HashMap .

◆  UpdateEntry()

void UpdateEntry ( typename HashMapType::Entry *  entry ) const
private

Member Data Documentation

◆  _hashMap

HashMapType _hashMap
private

◆  _lastUsed

LastNodeHead _lastUsed
private