ezEngine  Release 25.03
ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper > Class Template Reference

#include <HashTable.h>

Inheritance diagram for ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper >:

Public Member Functions

 ezHashTable (ezAllocator *pAllocator)
 
 ezHashTable (const ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper > &other)
 
 ezHashTable (const ezHashTableBase< KeyType, ValueType, Hasher > &other)
 
 ezHashTable (ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper > &&other)
 
 ezHashTable (ezHashTableBase< KeyType, ValueType, Hasher > &&other)
 
void operator= (const ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper > &rhs)
 
void operator= (const ezHashTableBase< KeyType, ValueType, Hasher > &rhs)
 
void operator= (ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper > &&rhs)
 
void operator= (ezHashTableBase< KeyType, ValueType, Hasher > &&rhs)
 
- Public Member Functions inherited from ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > >
bool operator== (const ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &rhs) const
 Compares this table to another table.
 
 EZ_ADD_DEFAULT_OPERATOR_NOTEQUAL (const ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &)
 
void Reserve (ezUInt32 uiCapacity)
 Expands the hashtable by over-allocating the internal storage so that the load factor is lower or equal to 60% when inserting the given number of entries.
 
void Compact ()
 Tries to compact the hashtable to avoid wasting memory. More...
 
ezUInt32 GetCount () const
 Returns the number of active entries in the table.
 
bool IsEmpty () const
 Returns true, if the hashtable does not contain any elements.
 
void Clear ()
 Clears the table.
 
bool Insert (CompatibleKeyType &&key, CompatibleValueType &&value, ValueType *out_pOldValue=nullptr)
 Inserts the key value pair or replaces value if an entry with the given key already exists. More...
 
bool Insert (CompatibleKeyType &&key, CompatibleValueType &&value, V *out_pOldValue)
 
bool Remove (const CompatibleKeyType &key, ValueType *out_pOldValue=nullptr)
 Removes the entry with the given key. Returns whether an entry was removed and optionally writes out the old value to out_oldValue.
 
Iterator Remove (const Iterator &pos)
 Erases the key/value pair at the given Iterator. Returns an iterator to the element after the given iterator.
 
void Remove (const ConstIterator &pos)=delete
 Cannot remove an element with just a ezHashTableBaseConstIterator.
 
bool Remove (const CompatibleKeyType &key, V *out_pOldValue)
 
bool TryGetValue (const CompatibleKeyType &key, ValueType &out_value) const
 Returns whether an entry with the given key was found and if found writes out the corresponding value to out_value.
 
bool TryGetValue (const CompatibleKeyType &key, const ValueType *&out_pValue) const
 Returns whether an entry with the given key was found and if found writes out the pointer to the corresponding value to out_pValue.
 
bool TryGetValue (const CompatibleKeyType &key, ValueType *&out_pValue) const
 Returns whether an entry with the given key was found and if found writes out the pointer to the corresponding value to out_pValue.
 
bool TryGetValue (const CompatibleKeyType &key, V &out_value) const
 
bool TryGetValue (const CompatibleKeyType &key, const V *&out_pValue) const
 
bool TryGetValue (const CompatibleKeyType &key, V *&out_pValue) const
 
ConstIterator Find (const CompatibleKeyType &key) const
 Searches for key, returns a ezHashTableBaseConstIterator to it or an invalid iterator, if no such key is found. O(1) operation.
 
Iterator Find (const CompatibleKeyType &key)
 Searches for key, returns an Iterator to it or an invalid iterator, if no such key is found. O(1) operation.
 
const ValueType * GetValue (const CompatibleKeyType &key) const
 Returns a pointer to the value of the entry with the given key if found, otherwise returns nullptr.
 
ValueType * GetValue (const CompatibleKeyType &key)
 Returns a pointer to the value of the entry with the given key if found, otherwise returns nullptr.
 
const V * GetValue (const CompatibleKeyType &key) const
 
V * GetValue (const CompatibleKeyType &key)
 
ValueType & operator[] (const KeyType &key)
 Returns the value to the given key if found or creates a new entry with the given key and a default constructed value.
 
ValueType & FindOrAdd (const KeyType &key, bool *out_pExisted=nullptr)
 Returns the value stored at the given key. If none exists, one is created. bExisted indicates whether an element needed to be created.
 
bool Contains (const CompatibleKeyType &key) const
 Returns if an entry with given key exists in the table.
 
EZ_FORCE_INLINE bool Contains (const CompatibleKeyType &key) const
 
Iterator GetIterator ()
 Returns an Iterator to the very first element.
 
ConstIterator GetIterator () const
 Returns a constant Iterator to the very first element.
 
Iterator GetEndIterator ()
 Returns an Iterator to the first element that is not part of the hash-table. Needed to support range based for loops.
 
ConstIterator GetEndIterator () const
 Returns a ezHashTableBaseConstIterator to the first element that is not part of the hash-table. Needed to support range based for loops.
 
ezAllocatorGetAllocator () const
 Returns the allocator that is used by this instance.
 
ezUInt64 GetHeapMemoryUsage () const
 Returns the amount of bytes that are currently allocated on the heap.
 
void Swap (ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &other)
 Swaps this map with the other one.
 
EZ_ALWAYS_INLINE ezUInt32 FindEntry (const CompatibleKeyType &key) const
 

Additional Inherited Members

- Public Types inherited from ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > >
using Iterator = ezHashTableBaseIterator< KeyType, ValueType, ezHashHelper< KeyType > >
 
using ConstIterator = ezHashTableBaseConstIterator< KeyType, ValueType, ezHashHelper< KeyType > >
 
- Protected Member Functions inherited from ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > >
 ezHashTableBase (ezAllocator *pAllocator)
 Creates an empty hashtable. Does not allocate any data yet.
 
 ezHashTableBase (const ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &rhs, ezAllocator *pAllocator)
 Creates a copy of the given hashtable.
 
 ezHashTableBase (ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &&rhs, ezAllocator *pAllocator)
 Moves data from an existing hashtable into this one.
 
 ~ezHashTableBase ()
 Destructor.
 
void operator= (const ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &rhs)
 Copies the data from another hashtable into this one.
 
void operator= (ezHashTableBase< KeyType, ValueType, ezHashHelper< KeyType > > &&rhs)
 Moves data from an existing hashtable into this one.
 

Detailed Description

template<typename KeyType, typename ValueType, typename Hasher = ezHashHelper<KeyType>, typename AllocatorWrapper = ezDefaultAllocatorWrapper>
class ezHashTable< KeyType, ValueType, Hasher, AllocatorWrapper >

See also
ezHashTableBase

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