StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual > Class Template Referencefinal

Unique-key hash map stored on Base's heap. More...

#include <StormByte/safe/unordered_map.hxx>

Classes

class  BasicIterator
 Forward cursor over Base-owned hash nodes. More...
class  node_type
 Owning handle to one extracted Base node. More...
struct  insert_return_type
 Result of inserting an extracted node. More...

Public Types

using key_type = K
 Key type.
using mapped_type = V
 Mapped type.
using value_type = Pair<const K, V>
 Entry type. The key is immutable.
using hasher = Hash
 Key hash.
using key_equal = KeyEqual
 Key equality.
using size_type = Size
 Element count. Size, not std::size_t.
using difference_type = std::ptrdiff_t
 Iterator distance type.
using reference = value_type&
 Mutable entry reference.
using const_reference = const value_type&
 Read-only entry reference.
using iterator = BasicIterator<false>
 Mutable iterator.
using const_iterator = BasicIterator<true>
 Read-only iterator.
using insert_result = Pair<iterator, bool>
 Iterator to the entry and whether it was inserted.

Public Member Functions

 UnorderedMap () noexcept
 Construct an empty map.
 UnorderedMap (size_type buckets, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual())
 Construct an empty map with a bucket count and predicates.
 UnorderedMap (const UnorderedMap &other)
 Copy every node into new Base blocks.
 UnorderedMap (UnorderedMap &&other) noexcept
 Take the table.
 ~UnorderedMap () noexcept
 Destroy every node and the bucket array through Base.
UnorderedMap & operator= (const UnorderedMap &other)
 Copy-assign.
UnorderedMap & operator= (UnorderedMap &&other) noexcept
 Move-assign.
STORMBYTE_FORCE_INLINE UnorderedMap (const std::unordered_map< K, V > &other)
 Copy a caller-owned STL map.
STORMBYTE_FORCE_INLINE UnorderedMap (std::unordered_map< K, V > &&other)
 Move elements from a caller-owned STL map and leave it empty.
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, value_type>
STORMBYTE_FORCE_INLINE UnorderedMap (std::from_range_t, R &&range)
 Copy the entries of range.
 UnorderedMap (std::initializer_list< value_type > values)
 Insert every entry of an initializer list.
UnorderedMap & operator= (std::initializer_list< value_type > values)
 Replace the contents with an initializer list.
iterator begin () noexcept
 Return the first occupied node.
iterator end () noexcept
 Return the past-the-end iterator.
const_iterator begin () const noexcept
 Return the first occupied node.
const_iterator end () const noexcept
 Return the past-the-end iterator.
const_iterator cbegin () const noexcept
 Return the first occupied node.
const_iterator cend () const noexcept
 Return the past-the-end iterator.
bool empty () const noexcept
 Test whether the map holds no entries.
size_type size () const noexcept
 Return the entry count.
size_type max_size () const noexcept
 Return the maximum entry count this map can report.
void clear () noexcept
 Destroy every entry.
insert_result insert (const value_type &value)
 Insert a copy of value when the key is absent.
insert_result insert (value_type &&value)
 Insert a moved value when the key is absent.
void insert (std::initializer_list< value_type > values)
 Insert every entry of an initializer list.
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, value_type>
STORMBYTE_FORCE_INLINE void insert_range (R &&range)
 Insert every entry of range.
template<class... Args>
insert_result emplace (Args &&... args)
 Construct an entry in place when the key is absent.
template<class... Args>
insert_result try_emplace (const K &key, Args &&... args)
 Construct the mapped value in place when the key is absent.
insert_result insert_or_assign (const K &key, V mapped)
 Insert or replace the mapped value.
iterator erase (const_iterator position)
 Erase the entry at position.
size_type erase (const K &key)
 Erase the entry with key.
node_type extract (const_iterator position)
 Unlink the entry at position.
node_type extract (const K &key)
 Unlink the entry with key.
insert_return_type insert (node_type &&node)
 Link an extracted node.
void merge (UnorderedMap &other)
 Move entries whose keys are absent from other.
void swap (UnorderedMap &other) noexcept
 Exchange tables.
V & at (const K &key)
 Return the mapped value.
const V & at (const K &key) const
 Return the mapped value.
V & operator[] (const K &key)
 Return the mapped value, inserting a value-initialized one when absent.
iterator find (const K &key)
 Find an entry.
const_iterator find (const K &key) const
 Find an entry.
size_type count (const K &key) const
 Count entries with key.
bool contains (const K &key) const
 Test whether key is present.
size_type bucket_count () const noexcept
 Return the bucket count.
size_type bucket_size (size_type index) const
 Return the number of entries in index.
size_type bucket (const K &key) const
 Return the bucket of key.
float load_factor () const noexcept
 Return the current load factor.
float max_load_factor () const noexcept
 Return the load factor that triggers a rehash.
void max_load_factor (float factor) noexcept
 Set the load factor that triggers a rehash.
void rehash (size_type buckets)
 Replace the bucket array.
void reserve (size_type count)
 Reserve room for count entries without exceeding the load factor.
Hash hash_function () const
 Return the stored hash.
KeyEqual key_eq () const
 Return the stored equality predicate.
bool operator== (const UnorderedMap &other) const
 Compare entries by key and mapped value.
STORMBYTE_FORCE_INLINE operator std::unordered_map< K, V > () const
 Copy the entries into caller-owned STL storage.

Detailed Description

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
class StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >

Unique-key hash map stored on Base's heap.

Template Parameters
KSafe key type. It must be hashable by Hash.
VSafe mapped type.
HashCross-module hash. A stateless hash does not allocate. A stateful one is stored in the map and must itself be Safe.
KeyEqualKey equality. A stateless predicate does not allocate. A stateful one is stored in the map and must itself be Safe.

Nodes and the bucket array are allocated with Heap::Allocate. There is no allocator. Iterators are forward and point at Base nodes. A cursor keeps the map so it can leave an empty bucket. Dereference returns a real Pair reference. Public results are Pair, never std::pair. node_type owns a Base node. It is not std::unordered_map::node_type. extract unlinks that node. It does not copy it. The default hash is Hash, not std::hash. A conversion to or from std::unordered_map<K, V> copies the entries. It does not reuse the STL hasher.

Member Typedef Documentation

◆ const_iterator

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::const_iterator = BasicIterator<true>

Read-only iterator.

◆ const_reference

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::const_reference = const value_type&

Read-only entry reference.

◆ difference_type

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::difference_type = std::ptrdiff_t

Iterator distance type.

◆ hasher

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::hasher = Hash

Key hash.

◆ insert_result

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert_result = Pair<iterator, bool>

Iterator to the entry and whether it was inserted.

◆ iterator

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::iterator = BasicIterator<false>

Mutable iterator.

◆ key_equal

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::key_equal = KeyEqual

Key equality.

◆ key_type

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::key_type = K

Key type.

◆ mapped_type

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::mapped_type = V

Mapped type.

◆ reference

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::reference = value_type&

Mutable entry reference.

◆ size_type

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::size_type = Size

Element count. Size, not std::size_t.

◆ value_type

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::value_type = Pair<const K, V>

Entry type. The key is immutable.

Constructor & Destructor Documentation

◆ UnorderedMap() [1/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( )
noexcept

Construct an empty map.

◆ UnorderedMap() [2/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( size_type buckets,
const Hash & hash = Hash(),
const KeyEqual & equal = KeyEqual() )
explicit

Construct an empty map with a bucket count and predicates.

Parameters
bucketsInitial bucket count. Rounded up to a power of two. Zero selects the default.
hashKey hash.
equalKey equality.
Exceptions
AllocationErrorThe bucket array could not be allocated.

◆ UnorderedMap() [3/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( const UnorderedMap< K, V, Hash, KeyEqual > & other)

Copy every node into new Base blocks.

Parameters
otherSource.
Exceptions
AllocationErrorA block could not be allocated.

◆ UnorderedMap() [4/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( UnorderedMap< K, V, Hash, KeyEqual > && other)
noexcept

Take the table.

other is left empty.

Parameters
otherSource.

◆ ~UnorderedMap()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::~UnorderedMap ( )
noexcept

Destroy every node and the bucket array through Base.

◆ UnorderedMap() [5/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
STORMBYTE_FORCE_INLINE StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( const std::unordered_map< K, V > & other)
inlineexplicit

Copy a caller-owned STL map.

Its state is unchanged. Its hasher is not reused.

Parameters
otherSource.
Exceptions
AllocationErrorA block could not be allocated.

◆ UnorderedMap() [6/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
STORMBYTE_FORCE_INLINE StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( std::unordered_map< K, V > && other)
inlineexplicit

Move elements from a caller-owned STL map and leave it empty.

Its hasher is not reused.

Parameters
otherSource. Cleared before this function returns.
Exceptions
AllocationErrorA block could not be allocated.

◆ UnorderedMap() [7/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, value_type>
STORMBYTE_FORCE_INLINE StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( std::from_range_t ,
R && range )
inlineexplicit

Copy the entries of range.

Template Parameters
RInput range of value_type.
Parameters
rangeSource. Instantiated in the caller.
Exceptions
AllocationErrorA block could not be allocated.

◆ UnorderedMap() [8/8]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::UnorderedMap ( std::initializer_list< value_type > values)

Insert every entry of an initializer list.

Parameters
valuesEntries.
Exceptions
AllocationErrorA block could not be allocated.

Member Function Documentation

◆ at() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
V & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::at ( const K & key)

Return the mapped value.

Parameters
keyKey.
Returns
Mapped value. Valid until the entry is erased or the map is rehashed.
Exceptions
OutOfBoundsErrorThe key is absent.

◆ at() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const V & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::at ( const K & key) const

Return the mapped value.

Parameters
keyKey.
Returns
Mapped value. Valid until the entry is erased or the map is rehashed.
Exceptions
OutOfBoundsErrorThe key is absent.

◆ begin() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const_iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::begin ( ) const
noexcept

Return the first occupied node.

Returns
Read-only iterator, or end when empty.

◆ begin() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::begin ( )
noexcept

Return the first occupied node.

Returns
Mutable iterator, or end when empty.

◆ bucket()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::bucket ( const K & key) const

Return the bucket of key.

Parameters
keyKey.
Returns
Bucket index. Zero when the table has no buckets.

◆ bucket_count()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::bucket_count ( ) const
inlinenoexcept

Return the bucket count.

Returns
Bucket count. Zero before the first allocation.

◆ bucket_size()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::bucket_size ( size_type index) const

Return the number of entries in index.

Parameters
indexBucket index. Not checked.
Returns
Entry count in that bucket.

◆ cbegin()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const_iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::cbegin ( ) const
inlinenoexcept

Return the first occupied node.

Returns
Read-only iterator.

◆ cend()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const_iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::cend ( ) const
inlinenoexcept

Return the past-the-end iterator.

Returns
Read-only iterator.

◆ clear()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::clear ( )
noexcept

Destroy every entry.

The bucket array stays.

◆ contains()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
bool StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::contains ( const K & key) const

Test whether key is present.

Parameters
keyKey.
Returns
Whether the key is present.

◆ count()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::count ( const K & key) const

Count entries with key.

Parameters
keyKey.
Returns
Zero or one.

◆ emplace()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class... Args>
insert_result StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::emplace ( Args &&... args)

Construct an entry in place when the key is absent.

Template Parameters
ArgsConstructor argument types of value_type.
Parameters
argsArguments forwarded to value_type.
Returns
Iterator to the entry and whether it was inserted.
Exceptions
AllocationErrorA node could not be allocated.

◆ empty()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
bool StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::empty ( ) const
inlinenoexcept

Test whether the map holds no entries.

Returns
Whether the map is empty.

◆ end() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const_iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::end ( ) const
inlinenoexcept

Return the past-the-end iterator.

Returns
Read-only iterator.

◆ end() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::end ( )
inlinenoexcept

Return the past-the-end iterator.

Returns
Mutable iterator.

◆ erase() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::erase ( const K & key)

Erase the entry with key.

Parameters
keyKey.
Returns
Number of erased entries, zero or one.

◆ erase() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::erase ( const_iterator position)

Erase the entry at position.

Parameters
positionIterator to an entry. Not end.
Returns
Iterator to the following entry, across buckets.

◆ extract() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
node_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::extract ( const K & key)

Unlink the entry with key.

The node is not copied.

Parameters
keyKey.
Returns
Owning handle, empty when the key is absent.

◆ extract() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
node_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::extract ( const_iterator position)

Unlink the entry at position.

The node is not copied.

Parameters
positionIterator to an entry. Not end.
Returns
Owning handle.

◆ find() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::find ( const K & key)

Find an entry.

Parameters
keyKey.
Returns
Iterator to the entry, or end.

◆ find() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
const_iterator StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::find ( const K & key) const

Find an entry.

Parameters
keyKey.
Returns
Read-only iterator to the entry, or end.

◆ hash_function()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
Hash StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::hash_function ( ) const
inline

Return the stored hash.

Returns
Key hash.

◆ insert() [1/4]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
insert_result StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert ( const value_type & value)

Insert a copy of value when the key is absent.

Parameters
valueEntry.
Returns
Iterator to the entry and whether it was inserted.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert() [2/4]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
insert_return_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert ( node_type && node)

Link an extracted node.

A duplicate key is returned in the result.

Parameters
nodeHandle. Left empty when inserted.
Returns
Insertion result.
Exceptions
AllocationErrorThe bucket array could not grow.

◆ insert() [3/4]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert ( std::initializer_list< value_type > values)

Insert every entry of an initializer list.

Parameters
valuesEntries.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert() [4/4]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
insert_result StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert ( value_type && value)

Insert a moved value when the key is absent.

Parameters
valueEntry.
Returns
Iterator to the entry and whether it was inserted.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert_or_assign()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
insert_result StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert_or_assign ( const K & key,
V mapped )

Insert or replace the mapped value.

Parameters
keyKey.
mappedMapped value.
Returns
Iterator to the entry and whether it was inserted.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert_range()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_reference_t<R>, value_type>
STORMBYTE_FORCE_INLINE void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::insert_range ( R && range)
inline

Insert every entry of range.

Template Parameters
RInput range of value_type.
Parameters
rangeSource. Instantiated in the caller.
Exceptions
AllocationErrorA node could not be allocated.

◆ key_eq()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
KeyEqual StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::key_eq ( ) const
inline

Return the stored equality predicate.

Returns
Key equality.

◆ load_factor()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
float StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::load_factor ( ) const
noexcept

Return the current load factor.

Returns
Entry count divided by bucket count, or zero when there are no buckets.

◆ max_load_factor() [1/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
float StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::max_load_factor ( ) const
inlinenoexcept

Return the load factor that triggers a rehash.

Returns
Maximum load factor.

◆ max_load_factor() [2/2]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::max_load_factor ( float factor)
inlinenoexcept

Set the load factor that triggers a rehash.

Parameters
factorMaximum load factor. Not checked.

◆ max_size()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::max_size ( ) const
inlinenoexcept

Return the maximum entry count this map can report.

Returns
Maximum count.

◆ merge()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::merge ( UnorderedMap< K, V, Hash, KeyEqual > & other)

Move entries whose keys are absent from other.

Parameters
otherSource. Extracted nodes are unlinked, not copied.
Exceptions
AllocationErrorThe bucket array could not grow.

◆ operator std::unordered_map< K, V >()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
STORMBYTE_FORCE_INLINE StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator std::unordered_map< K, V > ( ) const
inlineexplicit

Copy the entries into caller-owned STL storage.

The STL hasher is std::hash.

Returns
An std::unordered_map owned by the caller.

◆ operator=() [1/3]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
UnorderedMap & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator= ( const UnorderedMap< K, V, Hash, KeyEqual > & other)

Copy-assign.

The previous table is released only after the copy exists.

Parameters
otherSource.
Returns
This map.
Exceptions
AllocationErrorA block could not be allocated.

◆ operator=() [2/3]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
UnorderedMap & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator= ( std::initializer_list< value_type > values)

Replace the contents with an initializer list.

Parameters
valuesEntries.
Returns
This map.
Exceptions
AllocationErrorA block could not be allocated.

◆ operator=() [3/3]

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
UnorderedMap & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator= ( UnorderedMap< K, V, Hash, KeyEqual > && other)
noexcept

Move-assign.

other is left empty.

Parameters
otherSource.
Returns
This map.

◆ operator==()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
bool StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator== ( const UnorderedMap< K, V, Hash, KeyEqual > & other) const

Compare entries by key and mapped value.

Order does not matter.

Parameters
otherMap to compare.
Returns
Whether both maps hold the same entries.

◆ operator[]()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
V & StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::operator[] ( const K & key)

Return the mapped value, inserting a value-initialized one when absent.

Parameters
keyKey.
Returns
Mapped value. Valid until the entry is erased or the map is rehashed.
Exceptions
AllocationErrorA node could not be allocated.

◆ rehash()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::rehash ( size_type buckets)

Replace the bucket array.

Entries are relinked, not copied.

Parameters
bucketsNew bucket count. Rounded up to a power of two.
Exceptions
AllocationErrorThe new bucket array could not be allocated.

◆ reserve()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::reserve ( size_type count)

Reserve room for count entries without exceeding the load factor.

Parameters
countEntry count to accommodate.
Exceptions
AllocationErrorThe bucket array could not be allocated.

◆ size()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
size_type StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::size ( ) const
inlinenoexcept

Return the entry count.

Returns
Entry count.

◆ swap()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::swap ( UnorderedMap< K, V, Hash, KeyEqual > & other)
noexcept

Exchange tables.

Does not allocate.

Parameters
otherMap to exchange with.

◆ try_emplace()

template<Type::SafeValue K, Type::SafeValue V, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class... Args>
insert_result StormByte::Safe::UnorderedMap< K, V, Hash, KeyEqual >::try_emplace ( const K & key,
Args &&... args )

Construct the mapped value in place when the key is absent.

Template Parameters
ArgsMapped constructor argument types.
Parameters
keyKey.
argsArguments forwarded to V.
Returns
Iterator to the entry and whether it was inserted.
Exceptions
AllocationErrorA node could not be allocated.

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