nfx-containers 0.6.0
Modern C++20 header-only library providing high-performance hash containers with Robin Hood and perfect hashing
Loading...
Searching...
No Matches
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > Class Template Referencefinal

Hash map with Robin Hood hashing and insertion-order preservation. More...

#include <nfx/containers/OrderedHashMap.h>

Classes

class  Iterator
 Iterator for OrderedHashMap that follows insertion order. More...
class  ConstIterator
 Const iterator for OrderedHashMap that follows insertion order. 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

 OrderedHashMap ()
 Default constructor with initial capacity of 32 elements.
 OrderedHashMap (std::initializer_list< std::pair< TKey, TValue > > init)
 Construct map from initializer_list.
template<typename InputIt>
 OrderedHashMap (InputIt first, InputIt last)
 Construct map from iterator range.
 OrderedHashMap (size_t initialCapacity)
 Constructor with specified initial capacity.
 OrderedHashMap (OrderedHashMap &&other) noexcept
 Move constructor.
OrderedHashMapoperator= (OrderedHashMap &&other) noexcept
 Move assignment operator.
 OrderedHashMap (const OrderedHashMap &other)
 Copy constructor.
OrderedHashMapoperator= (const OrderedHashMap &other)
 Copy assignment operator.
 ~OrderedHashMap ()
 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 and remove a key-value pair from the map.
void merge (OrderedHashMap &other)
 Merge elements from another map into this map.
void merge (OrderedHashMap &&other)
 Merge elements from another map into this map (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 (OrderedHashMap &other) noexcept
 Swap contents with another map.
Iterator begin () noexcept
 Get iterator to first element in insertion order.
ConstIterator begin () const noexcept
 Get const iterator to first element in insertion order.
Iterator end () noexcept
 Get iterator to end (past last element in insertion order).
ConstIterator end () const noexcept
 Get const iterator to end (past last element in insertion order).
ConstIterator cbegin () const noexcept
 Get const iterator to first element in insertion order (explicit const).
ConstIterator cend () const noexcept
 Get const iterator to end (explicit const).
bool operator== (const OrderedHashMap &other) const noexcept
 Compare two OrderedHashMaps for equality.

Detailed Description

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
class nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >

Hash map with Robin Hood hashing and insertion-order preservation.

Template Parameters
TKeyKey type (supports heterogeneous lookup for compatible types)
TValueValue type
HashTypeHash type - uint32_t or uint64_t (default: uint32_t)
SeedHash seed value for initialization (default: FNV offset basis for HashType)
THasherHash functor type (default: hashing::Hasher<HashType, Seed>)
KeyEqualKey equality comparator (default: std::equal_to<> for transparent comparison)

Combines O(1) hash table lookups with stable insertion-order iteration. Uses Robin Hood hashing for the hash table and an intrusive doubly-linked list to maintain insertion order. Iteration follows insertion order, not bucket order.

Definition at line 78 of file OrderedHashMap.h.

Member Typedef Documentation

◆ const_iterator

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::const_iterator = ConstIterator

Type alias for const iterator.

Definition at line 133 of file OrderedHashMap.h.

◆ difference_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::difference_type = std::ptrdiff_t

Type alias for difference type.

Definition at line 127 of file OrderedHashMap.h.

◆ hash_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::hash_type = HashType

Type alias for hash type (uint32_t or uint64_t).

Definition at line 121 of file OrderedHashMap.h.

◆ hasher

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::hasher = THasher

Type alias for hasher type.

Definition at line 115 of file OrderedHashMap.h.

◆ iterator

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::iterator = Iterator

Type alias for iterator.

Definition at line 130 of file OrderedHashMap.h.

◆ key_equal

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::key_equal = KeyEqual

Type alias for key equality comparator.

Definition at line 118 of file OrderedHashMap.h.

◆ key_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::key_type = TKey

Type alias for key type.

Definition at line 106 of file OrderedHashMap.h.

◆ mapped_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::mapped_type = TValue

Type alias for mapped value type.

Definition at line 109 of file OrderedHashMap.h.

◆ size_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::size_type = size_t

Type alias for size type.

Definition at line 124 of file OrderedHashMap.h.

◆ value_type

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
using nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::value_type = std::pair<const TKey, TValue>

Type alias for key-value pair type.

Definition at line 112 of file OrderedHashMap.h.

Constructor & Destructor Documentation

◆ OrderedHashMap() [1/5]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::OrderedHashMap ( std::initializer_list< std::pair< TKey, TValue > > init)
inline

Construct map from initializer_list.

Parameters
initInitializer list of key/value pairs

◆ OrderedHashMap() [2/5]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename InputIt>
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::OrderedHashMap ( InputIt first,
InputIt last )
inline

Construct map from iterator range.

Template Parameters
InputItInput iterator type (must dereference to std::pair-like type)
Parameters
firstBeginning of range to copy from
lastEnd of range (exclusive)

◆ OrderedHashMap() [3/5]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::OrderedHashMap ( size_t initialCapacity)
inlineexplicit

Constructor with specified initial capacity.

Parameters
initialCapacityMinimum initial capacity (rounded up to power of 2)

◆ OrderedHashMap() [4/5]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::OrderedHashMap ( OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > && other)
noexcept

Move constructor.

Parameters
otherMap to move from

◆ OrderedHashMap() [5/5]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::OrderedHashMap ( const OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > & other)

Copy constructor.

Parameters
otherMap to copy from (preserves insertion order)

Member Function Documentation

◆ at() [1/4]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::at ( const KeyType & key)
inline

Checked element access with bounds checking.

Template Parameters
KeyTypeKey type (supports heterogeneous lookup)
Parameters
keyThe key to access
Returns
Reference to the value associated with the key
Exceptions
std::out_of_rangeif key is not found

◆ at() [2/4]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
const TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::at ( const KeyType & key) const
inline

Checked const element access with bounds checking.

Template Parameters
KeyTypeKey type (supports heterogeneous lookup)
Parameters
keyThe key to access
Returns
Const reference to the value associated with the key
Exceptions
std::out_of_rangeif key is not found

◆ at() [3/4]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::at ( const TKey & key)
inline

Checked element access with bounds checking.

Parameters
keyThe key to access
Returns
Reference to the value associated with the key
Exceptions
std::out_of_rangeif key is not found

◆ at() [4/4]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
const TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::at ( const TKey & key) const
inline

Checked const element access with bounds checking.

Parameters
keyThe key to access
Returns
Const reference to the value associated with the key
Exceptions
std::out_of_rangeif key is not found

◆ begin() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
ConstIterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::begin ( ) const
nodiscardnoexcept

Get const iterator to first element in insertion order.

Returns
Const iterator pointing to first inserted key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ begin() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
Iterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::begin ( )
nodiscardnoexcept

Get iterator to first element in insertion order.

Returns
Iterator pointing to first inserted key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ capacity()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
size_t nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::capacity ( ) const
inlinenodiscardnoexcept

Get the current capacity of the hash table.

Returns
Maximum elements before resize (always power of 2)

◆ cbegin()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
ConstIterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::cbegin ( ) const
nodiscardnoexcept

Get const iterator to first element in insertion order (explicit const).

Returns
Const iterator pointing to first inserted key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ cend()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
ConstIterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::cend ( ) const
nodiscardnoexcept

Get const iterator to end (explicit const).

Returns
Const iterator pointing past the last key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ contains()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::contains ( const KeyType & key) const
inlinenodiscardnoexcept

Check if a key exists in the map.

Template Parameters
KeyTypeKey type (supports heterogeneous lookup for compatible types)
Parameters
keyThe key to search for
Returns
true if key exists, false otherwise
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ emplace() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename... Args>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::emplace ( const TKey & key,
Args &&... args )
inline

Emplace a value in-place for the given key.

Template Parameters
ArgsVariadic template for value constructor arguments
Parameters
keyThe key to insert or update
argsArguments forwarded to TValue constructor
Note
New keys are appended to end of insertion order

◆ emplace() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename... Args>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::emplace ( TKey && key,
Args &&... args )
inline

Emplace a value in-place for the given key (move key).

Template Parameters
ArgsVariadic template for value constructor arguments
Parameters
keyThe key to insert or update (rvalue reference - moved)
argsArguments forwarded to TValue constructor
Note
New keys are appended to end of insertion order

◆ end() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
ConstIterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::end ( ) const
nodiscardnoexcept

Get const iterator to end (past last element in insertion order).

Returns
Const iterator pointing past the last key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ end() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
Iterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::end ( )
nodiscardnoexcept

Get iterator to end (past last element in insertion order).

Returns
Iterator pointing past the last key-value pair
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ erase() [1/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::erase ( const KeyType & key)
inlinenoexcept

Remove a key-value pair from the map.

Template Parameters
KeyTypeKey type (supports heterogeneous lookup for compatible types)
Parameters
keyThe key to remove
Returns
true if the key was found and removed, false otherwise
Note
Preserves insertion order of remaining elements

◆ erase() [2/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
Iterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::erase ( ConstIterator first,
ConstIterator last )
inlinenoexcept

Erase range of elements.

Parameters
firstBeginning of range to erase (in insertion order)
lastEnd of range to erase (exclusive)
Returns
Iterator to the element following the last erased element

◆ erase() [3/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
Iterator nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::erase ( ConstIterator pos)
inlinenoexcept

Erase element at iterator position.

Parameters
posIterator to element to erase
Returns
Iterator to the element following the erased element in insertion order
Note
Iterator becomes invalid after erase

◆ extract()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
std::optional< std::pair< TKey, TValue > > nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::extract ( const KeyType & key)
inlinenodiscard

Extract and remove a key-value pair from the map.

Template Parameters
KeyTypeKey type (supports heterogeneous lookup for compatible types)
Parameters
keyThe key to extract
Returns
std::optional containing the extracted key-value pair if found, std::nullopt otherwise

Removes the key-value pair from the map and returns it. If the key is not found, returns std::nullopt. This operation invalidates iterators to the extracted element. The insertion order of remaining elements is preserved.

Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ find() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
const TValue * nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::find ( const KeyType & key) const
inlinenodiscardnoexcept

Fast const lookup with heterogeneous key types (C++ idiom: pointer return).

Template Parameters
KeyTypeKey type (supports heterogeneous lookup for compatible types)
Parameters
keyThe key to search for
Returns
Const pointer to the value if found, nullptr otherwise

◆ find() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename KeyType = TKey>
TValue * nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::find ( const KeyType & key)
inlinenodiscardnoexcept

Fast lookup with heterogeneous key types (C++ idiom: pointer return).

Template Parameters
KeyTypeKey type (supports heterogeneous lookup for compatible types)
Parameters
keyThe key to search for
Returns
Pointer to the value if found, nullptr otherwise

◆ insert() [1/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insert ( const TKey & key,
const TValue & value )
inline

Insert a key-value pair only if key doesn't exist (copy semantics).

Parameters
keyThe key to insert
valueThe value to associate with the key (copied)
Returns
true if key was inserted, false if key already exists (value unchanged)
Note
Does NOT overwrite existing values (unlike insertOrAssign)
New keys are appended to end of insertion order

◆ insert() [2/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insert ( const TKey & key,
TValue && value )
inline

Insert a key-value pair only if key doesn't exist (move semantics).

Parameters
keyThe key to insert
valueThe value to associate with the key (moved)
Returns
true if key was inserted, false if key already exists (value unchanged)
Note
Does NOT overwrite existing values (unlike insertOrAssign)
New keys are appended to end of insertion order

◆ insert() [3/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insert ( TKey && key,
TValue && value )
inline

Insert a key-value pair only if key doesn't exist (perfect forwarding).

Parameters
keyThe key to insert (moved)
valueThe value to associate with the key (moved)
Returns
true if key was inserted, false if key already exists (value unchanged)
Note
Does NOT overwrite existing values (unlike insertOrAssign)
New keys are appended to end of insertion order

◆ insertOrAssign() [1/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insertOrAssign ( const TKey & key,
const TValue & value )
inline

Insert or update a key-value pair (copy semantics).

Parameters
keyThe key to insert or update
valueThe value to associate with the key (copied)
Note
Updating existing keys does NOT change their position in insertion order
New keys are appended to end of insertion order

◆ insertOrAssign() [2/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insertOrAssign ( const TKey & key,
TValue && value )
inline

Insert or update a key-value pair (move semantics).

Parameters
keyThe key to insert or update
valueThe value to associate with the key (moved)
Note
Updating existing keys does NOT change their position in insertion order
New keys are appended to end of insertion order

◆ insertOrAssign() [3/3]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::insertOrAssign ( TKey && key,
TValue && value )
inline

Insert or update a key-value pair (perfect forwarding for both key and value).

Parameters
keyThe key to insert or update (forwarded)
valueThe value to associate with the key (forwarded)
Note
Updating existing keys does NOT change their position in insertion order
New keys are appended to end of insertion order

◆ isEmpty()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::isEmpty ( ) const
inlinenodiscardnoexcept

Check if the map is empty.

Returns
true if size() == 0, false otherwise

◆ merge() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::merge ( OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > && other)
inline

Merge elements from another map into this map (rvalue overload).

Parameters
otherSource map to merge from (modified - unique elements are moved out)

◆ merge() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::merge ( OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > & other)
inline

Merge elements from another map into this map.

Parameters
otherSource map to merge from (modified - unique elements are moved out)

Attempts to move each element from 'other' into this map in insertion order. Elements that already exist in this map (duplicates) remain in 'other'. After merge, 'other' contains only elements that were duplicates. Insertion order is preserved for both maps.

◆ operator=() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
OrderedHashMap & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::operator= ( const OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > & other)

Copy assignment operator.

Parameters
otherMap to copy from (preserves insertion order)
Returns
Reference to this map

◆ operator=() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
OrderedHashMap & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::operator= ( OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > && other)
noexcept

Move assignment operator.

Parameters
otherMap to move from
Returns
Reference to this map

◆ operator==()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
bool nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::operator== ( const OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > & other) const
nodiscardnoexcept

Compare two OrderedHashMaps for equality.

Parameters
otherThe other OrderedHashMap to compare with
Returns
true if both maps contain the same key-value pairs in the same insertion order
Note
This function is marked [[nodiscard]] - the return value should not be ignored

◆ operator[]() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::operator[] ( const TKey & key)
inline

STL-compatible subscript operator (insert-if-missing).

Parameters
keyThe key to access or insert
Returns
Reference to the value associated with the key

If key doesn't exist, inserts default-constructed value at end of insertion order. Requires TValue to be default-constructible.

Note
This function is NOT marked noexcept as it may insert/resize

◆ operator[]() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
TValue & nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::operator[] ( TKey && key)
inline

STL-compatible subscript operator with move semantics.

Parameters
keyThe key to access or insert (moved if new)
Returns
Reference to the value associated with the key

If key doesn't exist, inserts default-constructed value at end of insertion order. Requires TValue to be default-constructible.

Note
This function is NOT marked noexcept as it may insert/resize

◆ reserve()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::reserve ( size_t minCapacity)
inline

Reserve capacity for at least the specified number of elements.

Parameters
minCapacityMinimum capacity to reserve
Note
Preserves insertion order during rehashing

◆ size()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
size_t nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::size ( ) const
inlinenodiscardnoexcept

Get the number of elements in the map.

Returns
Current number of key-value pairs stored

◆ swap()

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
void nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::swap ( OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual > & other)
inlinenoexcept

Swap contents with another map.

Parameters
otherMap to swap with
Note
noexcept operation - just swaps internal pointers/values

◆ tryEmplace() [1/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename... Args>
std::pair< Iterator, bool > nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::tryEmplace ( const TKey & key,
Args &&... args )
inline

Try to emplace a value if key doesn't exist.

Template Parameters
ArgsVariadic template for value constructor arguments
Parameters
keyThe key to insert (const reference)
argsArguments forwarded to TValue constructor (only used if key doesn't exist)
Returns
Pair of iterator to element and bool (true if inserted, false if key existed)
Note
More efficient than emplace() - doesn't construct value if key exists
New keys are appended to end of insertion order

◆ tryEmplace() [2/2]

template<typename TKey, typename TValue, hashing::Hash32or64 HashType = uint32_t, HashType Seed = ( sizeof( HashType ) == 4 ? hashing::constants::FNV_OFFSET_BASIS_32 : hashing::constants::FNV_OFFSET_BASIS_64 ), typename THasher = hashing::Hasher<HashType, Seed>, typename KeyEqual = std::equal_to<>>
template<typename... Args>
std::pair< Iterator, bool > nfx::containers::OrderedHashMap< TKey, TValue, HashType, Seed, THasher, KeyEqual >::tryEmplace ( TKey && key,
Args &&... args )
inline

Try to emplace a value if key doesn't exist.

Template Parameters
ArgsVariadic template for value constructor arguments
Parameters
keyThe key to insert (rvalue reference - moved only if inserted)
argsArguments forwarded to TValue constructor (only used if key doesn't exist)
Returns
Pair of iterator to element and bool (true if inserted, false if key existed)
Note
More efficient than emplace() - doesn't construct value if key exists
New keys are appended to end of insertion order

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