|
nfx-containers 0.6.0
Modern C++20 header-only library providing high-performance hash containers with Robin Hood and perfect hashing
|
Hash map with Robin Hood hashing for bounded probe distances. More...
#include <nfx/containers/FastHashMap.h>
Classes | |
| class | Iterator |
| Iterator for HashMap that skips empty buckets. More... | |
| class | ConstIterator |
| Const iterator for HashMap that skips empty buckets. More... | |
Public Types | |
| using | key_type = TKey |
| Type alias for key type. | |
| using | mapped_type = TValue |
| Type alias for mapped value type. | |
| using | value_type = std::pair<const TKey, TValue> |
| Type alias for key-value pair type. | |
| using | hasher = THasher |
| Type alias for hasher type. | |
| using | key_equal = KeyEqual |
| Type alias for key equality comparator. | |
| using | hash_type = HashType |
| Type alias for hash type (uint32_t or uint64_t). | |
| using | size_type = size_t |
| Type alias for size type. | |
| using | difference_type = std::ptrdiff_t |
| Type alias for difference type. | |
| using | iterator = Iterator |
| Type alias for iterator. | |
| using | const_iterator = ConstIterator |
| Type alias for const iterator. | |
Public Member Functions | |
| FastHashMap () | |
| Default constructor with initial capacity of 32 elements. | |
| FastHashMap (std::initializer_list< std::pair< TKey, TValue > > init) | |
| Construct map from initializer_list. | |
| template<typename InputIt> | |
| FastHashMap (InputIt first, InputIt last) | |
| Construct map from iterator range. | |
| FastHashMap (size_t initialCapacity) | |
| Constructor with specified initial capacity. | |
| FastHashMap (FastHashMap &&) noexcept | |
| Move constructor. | |
| FastHashMap & | operator= (FastHashMap &&) noexcept |
| Move assignment operator. | |
| FastHashMap (const FastHashMap &)=default | |
| Copy constructor. | |
| FastHashMap & | operator= (const FastHashMap &)=default |
| Copy assignment operator. | |
| ~FastHashMap ()=default | |
| Destructor. | |
| template<typename KeyType = TKey> | |
| TValue * | find (const KeyType &key) noexcept |
| Fast lookup with heterogeneous key types (C++ idiom: pointer return). | |
| template<typename KeyType = TKey> | |
| const TValue * | find (const KeyType &key) const noexcept |
| Fast const lookup with heterogeneous key types (C++ idiom: pointer return). | |
| template<typename KeyType = TKey> | |
| bool | contains (const KeyType &key) const noexcept |
| Check if a key exists in the map. | |
| TValue & | at (const TKey &key) |
| Checked element access with bounds checking. | |
| const TValue & | at (const TKey &key) const |
| Checked const element access with bounds checking. | |
| TValue & | operator[] (const TKey &key) |
| STL-compatible subscript operator (insert-if-missing). | |
| TValue & | operator[] (TKey &&key) |
| STL-compatible subscript operator with move semantics. | |
| template<typename KeyType = TKey> | |
| TValue & | at (const KeyType &key) |
| Checked element access with bounds checking. | |
| template<typename KeyType = TKey> | |
| const TValue & | at (const KeyType &key) const |
| Checked const element access with bounds checking. | |
| bool | insert (const TKey &key, const TValue &value) |
| Insert a key-value pair only if key doesn't exist (copy semantics). | |
| bool | insert (const TKey &key, TValue &&value) |
| Insert a key-value pair only if key doesn't exist (move semantics). | |
| bool | insert (TKey &&key, TValue &&value) |
| Insert a key-value pair only if key doesn't exist (perfect forwarding). | |
| void | insertOrAssign (const TKey &key, TValue &&value) |
| Insert or update a key-value pair (move semantics). | |
| void | insertOrAssign (const TKey &key, const TValue &value) |
| Insert or update a key-value pair (copy semantics). | |
| void | insertOrAssign (TKey &&key, TValue &&value) |
| Insert or update a key-value pair (perfect forwarding for both key and value). | |
| template<typename... Args> | |
| void | emplace (const TKey &key, Args &&... args) |
| Emplace a value in-place for the given key. | |
| template<typename... Args> | |
| void | emplace (TKey &&key, Args &&... args) |
| Emplace a value in-place for the given key (move key). | |
| template<typename... Args> | |
| std::pair< Iterator, bool > | tryEmplace (const TKey &key, Args &&... args) |
| Try to emplace a value if key doesn't exist. | |
| template<typename... Args> | |
| std::pair< Iterator, bool > | tryEmplace (TKey &&key, Args &&... args) |
| Try to emplace a value if key doesn't exist. | |
| void | reserve (size_t minCapacity) |
| Reserve capacity for at least the specified number of elements. | |
| template<typename KeyType = TKey> | |
| bool | erase (const KeyType &key) noexcept |
| Remove a key-value pair from the map. | |
| Iterator | erase (ConstIterator pos) noexcept |
| Erase element at iterator position. | |
| Iterator | erase (ConstIterator first, ConstIterator last) noexcept |
| Erase range of elements. | |
| void | clear () noexcept |
| Clear all elements from the map. | |
| template<typename KeyType = TKey> | |
| std::optional< std::pair< TKey, TValue > > | extract (const KeyType &key) |
| Extract a key-value pair from the map without destroying it. | |
| void | merge (FastHashMap &other) |
| Merge another FastHashMap into this one. | |
| void | merge (FastHashMap &&other) |
| Merge another FastHashMap into this one (rvalue overload). | |
| size_t | size () const noexcept |
| Get the number of elements in the map. | |
| size_t | capacity () const noexcept |
| Get the current capacity of the hash table. | |
| bool | isEmpty () const noexcept |
| Check if the map is empty. | |
| void | swap (FastHashMap &other) noexcept |
| Swap contents with another map. | |
| Iterator | begin () noexcept |
| Get iterator to beginning of occupied buckets. | |
| ConstIterator | begin () const noexcept |
| Get const iterator to beginning of occupied buckets. | |
| Iterator | end () noexcept |
| Get iterator to end (past last occupied bucket). | |
| ConstIterator | end () const noexcept |
| Get const iterator to end (past last occupied bucket). | |
| ConstIterator | cbegin () const noexcept |
| Get const iterator to beginning of occupied buckets (explicit const). | |
| ConstIterator | cend () const noexcept |
| Get const iterator to end (explicit const). | |
| bool | operator== (const FastHashMap &other) const noexcept |
| Compare two HashMaps for equality. | |
Hash map with Robin Hood hashing for bounded probe distances.
| TKey | Key type (supports heterogeneous lookup for compatible types) |
| TValue | Value type |
| HashType | Hash type - uint32_t or uint64_t (default: uint32_t) |
| Seed | Hash seed value for initialization (default: FNV offset basis for HashType) |
| THasher | Hash functor type (default: hashing::Hasher<HashType, Seed>) |
| KeyEqual | Key equality comparator (default: std::equal_to<> for transparent comparison) |
Definition at line 74 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::const_iterator = ConstIterator |
Type alias for const iterator.
Definition at line 129 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::difference_type = std::ptrdiff_t |
Type alias for difference type.
Definition at line 123 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::hash_type = HashType |
Type alias for hash type (uint32_t or uint64_t).
Definition at line 117 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::hasher = THasher |
Type alias for hasher type.
Definition at line 111 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::iterator = Iterator |
Type alias for iterator.
Definition at line 126 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::key_equal = KeyEqual |
Type alias for key equality comparator.
Definition at line 114 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::key_type = TKey |
Type alias for key type.
Definition at line 102 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::mapped_type = TValue |
Type alias for mapped value type.
Definition at line 105 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::size_type = size_t |
Type alias for size type.
Definition at line 120 of file FastHashMap.h.
| using nfx::containers::FastHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::value_type = std::pair<const TKey, TValue> |
Type alias for key-value pair type.
Definition at line 108 of file FastHashMap.h.
|
inline |
Construct map from initializer_list.
| init | Initializer list of key/value pairs |
|
inline |
Construct map from iterator range.
| InputIt | Input iterator type (must dereference to std::pair-like type) |
| first | Beginning of range to copy from |
| last | End of range (exclusive) |
|
inlineexplicit |
Constructor with specified initial capacity.
| initialCapacity | Minimum initial capacity (rounded up to power of 2) |
|
inline |
Checked element access with bounds checking.
| KeyType | Key type (supports heterogeneous lookup) |
| key | The key to access |
| std::out_of_range | if key is not found |
|
inline |
Checked const element access with bounds checking.
| KeyType | Key type (supports heterogeneous lookup) |
| key | The key to access |
| std::out_of_range | if key is not found |
|
inline |
Checked element access with bounds checking.
| key | The key to access |
| std::out_of_range | if key is not found |
|
inline |
Checked const element access with bounds checking.
| key | The key to access |
| std::out_of_range | if key is not found |
|
nodiscardnoexcept |
Get const iterator to beginning of occupied buckets.
|
nodiscardnoexcept |
Get iterator to beginning of occupied buckets.
|
inlinenodiscardnoexcept |
Get the current capacity of the hash table.
|
nodiscardnoexcept |
Get const iterator to beginning of occupied buckets (explicit const).
|
nodiscardnoexcept |
Get const iterator to end (explicit const).
|
inlinenodiscardnoexcept |
Check if a key exists in the map.
| KeyType | Key type (supports heterogeneous lookup for compatible types) |
| key | The key to search for |
|
inline |
Emplace a value in-place for the given key.
| Args | Variadic template for value constructor arguments |
| key | The key to insert or update |
| args | Arguments forwarded to TValue constructor |
|
inline |
Emplace a value in-place for the given key (move key).
| Args | Variadic template for value constructor arguments |
| key | The key to insert or update (rvalue reference - moved) |
| args | Arguments forwarded to TValue constructor |
|
nodiscardnoexcept |
Get const iterator to end (past last occupied bucket).
|
nodiscardnoexcept |
Get iterator to end (past last occupied bucket).
|
inlinenoexcept |
Remove a key-value pair from the map.
| KeyType | Key type (supports heterogeneous lookup for compatible types) |
| key | The key to remove |
|
inlinenoexcept |
Erase range of elements.
| first | Beginning of range to erase |
| last | End of range to erase (exclusive) |
|
inlinenoexcept |
Erase element at iterator position.
| pos | Iterator to element to erase |
|
inlinenodiscard |
Extract a key-value pair from the map without destroying it.
| KeyType | Key type (supports heterogeneous lookup for compatible types) |
| key | The key to extract |
Removes the element from the map and returns it without invoking destructors. This is useful for transferring ownership or moving elements between containers.
|
inlinenodiscardnoexcept |
Fast const lookup with heterogeneous key types (C++ idiom: pointer return).
| KeyType | Key type (supports heterogeneous lookup for compatible types) |
| key | The key to search for |
|
inlinenodiscardnoexcept |
Fast lookup with heterogeneous key types (C++ idiom: pointer return).
| KeyType | Key type (supports heterogeneous lookup for compatible types) |
| key | The key to search for |
|
inline |
Insert a key-value pair only if key doesn't exist (copy semantics).
| key | The key to insert |
| value | The value to associate with the key (copied) |
|
inline |
Insert a key-value pair only if key doesn't exist (move semantics).
| key | The key to insert |
| value | The value to associate with the key (moved) |
|
inline |
Insert a key-value pair only if key doesn't exist (perfect forwarding).
| key | The key to insert (moved) |
| value | The value to associate with the key (moved) |
|
inline |
Insert or update a key-value pair (copy semantics).
| key | The key to insert or update |
| value | The value to associate with the key (copied) |
|
inline |
Insert or update a key-value pair (move semantics).
| key | The key to insert or update |
| value | The value to associate with the key (moved) |
|
inline |
Insert or update a key-value pair (perfect forwarding for both key and value).
| key | The key to insert or update (forwarded) |
| value | The value to associate with the key (forwarded) |
|
inlinenodiscardnoexcept |
Check if the map is empty.
|
inline |
Merge another FastHashMap into this one (rvalue overload).
| other | The map to merge from (elements are moved) |
Same as merge(FastHashMap&) but accepts rvalue references.
|
inline |
Merge another FastHashMap into this one.
| other | The map to merge from (elements are moved, not copied) |
Attempts to insert each element from other into this map. Elements that already exist in this map are left in other. After the operation, other contains only elements that were not inserted.
|
default |
Copy assignment operator.
|
noexcept |
Move assignment operator.
|
nodiscardnoexcept |
Compare two HashMaps for equality.
| other | The other HashMap to compare with |
|
inline |
STL-compatible subscript operator (insert-if-missing).
| key | The key to access or insert |
If key doesn't exist, inserts default-constructed value. Requires TValue to be default-constructible.
|
inline |
STL-compatible subscript operator with move semantics.
| key | The key to access or insert (moved if new) |
If key doesn't exist, inserts default-constructed value. Requires TValue to be default-constructible.
|
inline |
Reserve capacity for at least the specified number of elements.
| minCapacity | Minimum capacity to reserve |
|
inlinenodiscardnoexcept |
Get the number of elements in the map.
|
inlinenoexcept |
Swap contents with another map.
| other | Map to swap with |
|
inline |
Try to emplace a value if key doesn't exist.
| Args | Variadic template for value constructor arguments |
| key | The key to insert (const reference) |
| args | Arguments forwarded to TValue constructor (only used if key doesn't exist) |
|
inline |
Try to emplace a value if key doesn't exist.
| Args | Variadic template for value constructor arguments |
| key | The key to insert (rvalue reference - moved only if inserted) |
| args | Arguments forwarded to TValue constructor (only used if key doesn't exist) |