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

Unique values stored in a Base-heap hash table. More...

#include <StormByte/safe/unordered_set.hxx>

Classes

class  iterator
 Forward cursor. More...
class  const_iterator
 Read-only forward cursor. 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
 Value and lookup type.
using value_type = K
 Stored value.
using hasher = Hash
 Value hash.
using key_equal = KeyEqual
 Value equality.
using size_type = Size
 Element count. Size, not std::size_t.
using difference_type = std::ptrdiff_t
 Iterator distance type.
using reference = const K&
 Read-only value reference.
using const_reference = const K&
 Read-only value reference.
using insert_result = Pair<iterator, bool>
 Iterator to the value and whether it was inserted.

Public Member Functions

 UnorderedSet () noexcept
 Construct an empty set.
 UnorderedSet (size_type buckets, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual())
 Construct an empty set with a bucket count and predicates.
 UnorderedSet (const UnorderedSet &other)
 Copy the values.
 UnorderedSet (UnorderedSet &&other) noexcept
 Take the table.
 ~UnorderedSet ()
 Destroy the values.
UnorderedSet & operator= (const UnorderedSet &other)
 Copy-assign the values.
UnorderedSet & operator= (UnorderedSet &&other) noexcept
 Move-assign the table.
UnorderedSet & operator= (std::initializer_list< K > values)
 Replace the contents with an initializer list.
template<class InputIt>
 UnorderedSet (InputIt first, InputIt last)
 Construct from an iterator range.
template<class InputIt>
 UnorderedSet (InputIt first, InputIt last, size_type buckets, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual())
 Construct from an iterator range, a bucket count and predicates.
 UnorderedSet (std::initializer_list< K > values)
 Construct from an initializer list.
 UnorderedSet (std::initializer_list< K > values, size_type buckets, const Hash &hash=Hash(), const KeyEqual &equal=KeyEqual())
 Construct from an initializer list, a bucket count and predicates.
STORMBYTE_FORCE_INLINE UnorderedSet (const std::unordered_set< K > &other)
 Copy a caller-owned STL set.
STORMBYTE_FORCE_INLINE UnorderedSet (std::unordered_set< K > &&other)
 Move values from a caller-owned STL set and leave it empty.
hasher hash_function () const
 Return the stored hash.
key_equal key_eq () const
 Return the stored equality predicate.
iterator begin () noexcept
 Return an iterator to the first occupied node.
const_iterator begin () const noexcept
 Return an iterator to the first occupied node.
const_iterator cbegin () const noexcept
 Return an iterator to the first occupied node.
iterator end () noexcept
 Return the past-the-end iterator.
const_iterator end () const noexcept
 Return the past-the-end iterator.
const_iterator cend () const noexcept
 Return the past-the-end iterator.
bool empty () const noexcept
 Test whether the set has no values.
size_type size () const noexcept
 Return the number of values.
size_type max_size () const noexcept
 Return the maximum number of values.
void clear () noexcept
 Destroy every value.
insert_result insert (const K &value)
 Insert a value if it is absent.
insert_result insert (K &&value)
 Insert a value if it is absent.
iterator insert (const_iterator hint, const K &value)
 Insert a value.
iterator insert (const_iterator hint, K &&value)
 Insert a value.
template<class InputIt>
void insert (InputIt first, InputIt last)
 Insert every value in [first, last).
void insert (std::initializer_list< K > values)
 Insert every value 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 a copy of range.
template<class... Args>
insert_result emplace (Args &&... args)
 Construct a value in a new node if it is absent.
template<class... Args>
iterator emplace_hint (const_iterator hint, Args &&... args)
 Construct a value.
insert_return_type insert (node_type &&handle)
 Insert an extracted node if its value is absent.
iterator insert (const_iterator hint, node_type &&handle)
 Insert an extracted node.
node_type extract (const_iterator position)
 Unlink the value at position and return that node.
node_type extract (const K &value)
 Unlink value and return that node.
template<class OtherHash, class OtherEqual>
void merge (UnorderedSet< K, OtherHash, OtherEqual > &source)
 Take unique values from source.
iterator erase (iterator position)
 Erase the value at an iterator.
iterator erase (const_iterator position)
 Erase the value at a read-only iterator.
iterator erase (const_iterator first, const_iterator last)
 Erase [first, last).
size_type erase (const K &value)
 Erase a value.
void swap (UnorderedSet &other) noexcept
 Exchange tables.
iterator find (const K &value)
 Find a value.
const_iterator find (const K &value) const
 Find a value.
size_type count (const K &value) const
 Count matching values.
bool contains (const K &value) const
 Test whether a value is present.
Pair< iterator, iterator > equal_range (const K &value)
 Return the range of values equal to value.
Pair< const_iterator, const_iterator > equal_range (const K &value) const
 Return the range of values equal to value.
size_type bucket_count () const noexcept
 Return the bucket count.
size_type bucket_size (size_type index) const
 Return the number of values in index.
size_type bucket (const K &value) const
 Return the bucket of value.
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 values without exceeding the load factor.
bool operator== (const UnorderedSet &other) const
 Compare values.
bool operator!= (const UnorderedSet &other) const
 Compare values.
STORMBYTE_FORCE_INLINE operator std::unordered_set< K > () const
 Copy the values into caller-owned STL storage.

Detailed Description

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

Unique values stored in a Base-heap hash table.

Template Parameters
KSafe value type. It must be hashable by Hash.
HashCross-module hash. A stateless hash does not allocate. A stateful one is stored in the set and must itself be Safe.
KeyEqualValue equality. A stateless predicate does not allocate. A stateful one is stored in the set and must itself be Safe.

The table is the same Base-heap table as UnorderedMap. Iterators yield the value, not a pair. Order is bucket order. Rehash invalidates every cursor. node_type owns a Base node. It is not std::unordered_set::node_type. There is no allocator. The default hash is Hash, not std::hash. A conversion to std::unordered_set copies the values and does not reuse this hasher.

Member Typedef Documentation

◆ const_reference

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

Read-only value reference.

◆ difference_type

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

Iterator distance type.

◆ hasher

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

Value hash.

◆ insert_result

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

Iterator to the value and whether it was inserted.

◆ key_equal

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

Value equality.

◆ key_type

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

Value and lookup type.

◆ reference

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::reference = const K&

Read-only value reference.

◆ size_type

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

Element count. Size, not std::size_t.

◆ value_type

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
using StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::value_type = K

Stored value.

Constructor & Destructor Documentation

◆ UnorderedSet() [1/10]

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

Construct an empty set.

◆ UnorderedSet() [2/10]

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

Construct an empty set with a bucket count and predicates.

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

◆ UnorderedSet() [3/10]

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

Copy the values.

Parameters
otherSource.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [4/10]

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

Take the table.

other is left empty.

Parameters
otherSource.

◆ ~UnorderedSet()

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

Destroy the values.

◆ UnorderedSet() [5/10]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class InputIt>
StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::UnorderedSet ( InputIt first,
InputIt last )

Construct from an iterator range.

Template Parameters
InputItInput iterator of values.
Parameters
firstStart.
lastEnd.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [6/10]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class InputIt>
StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::UnorderedSet ( InputIt first,
InputIt last,
size_type buckets,
const Hash & hash = Hash(),
const KeyEqual & equal = KeyEqual() )

Construct from an iterator range, a bucket count and predicates.

Template Parameters
InputItInput iterator of values.
Parameters
firstStart.
lastEnd.
bucketsInitial bucket count.
hashValue hash.
equalValue equality.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [7/10]

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

Construct from an initializer list.

Parameters
valuesValues. Duplicates are dropped.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [8/10]

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

Construct from an initializer list, a bucket count and predicates.

Parameters
valuesValues. Duplicates are dropped.
bucketsInitial bucket count.
hashValue hash.
equalValue equality.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [9/10]

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

Copy a caller-owned STL set.

Its hasher is not reused.

Parameters
otherSource.
Exceptions
AllocationErrorA node could not be allocated.

◆ UnorderedSet() [10/10]

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

Move values from a caller-owned STL set and leave it empty.

Its hasher is not reused.

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

Member Function Documentation

◆ begin() [1/2]

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

Return an iterator to the first occupied node.

Returns
First value, or end when empty.

◆ begin() [2/2]

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

Return an iterator to the first occupied node.

Returns
First value, or end when empty.

◆ bucket()

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

Return the bucket of value.

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

◆ bucket_count()

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

Return the bucket count.

Returns
Bucket count. Zero before the first allocation.

◆ bucket_size()

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

Return the number of values in index.

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

◆ cbegin()

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

Return an iterator to the first occupied node.

Returns
First value, or end when empty.

◆ cend()

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

Return the past-the-end iterator.

Returns
End iterator.

◆ clear()

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

Destroy every value.

The bucket array stays.

◆ contains()

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

Test whether a value is present.

Parameters
valueLookup value.
Returns
Whether the value is present.

◆ count()

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

Count matching values.

Parameters
valueLookup value.
Returns
Zero or one.

◆ emplace()

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

Construct a value in a new node if it is absent.

Template Parameters
ArgsValue constructor argument types.
Parameters
argsArguments forwarded to K.
Returns
Iterator to the value and whether it was inserted.
Exceptions
AllocationErrorThe node could not be allocated.

◆ emplace_hint()

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class... Args>
iterator StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::emplace_hint ( const_iterator hint,
Args &&... args )

Construct a value.

hint is ignored.

Template Parameters
ArgsValue constructor argument types.
Parameters
hintUnused.
argsArguments forwarded to K.
Returns
Iterator to the value.
Exceptions
AllocationErrorThe node could not be allocated.

◆ empty()

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

Test whether the set has no values.

Returns
Whether the set is empty.

◆ end() [1/2]

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

Return the past-the-end iterator.

Returns
End iterator.

◆ end() [2/2]

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

Return the past-the-end iterator.

Returns
End iterator.

◆ equal_range() [1/2]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
Pair< iterator, iterator > StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::equal_range ( const K & value)

Return the range of values equal to value.

Parameters
valueLookup value.
Returns
The value and the following cursor, or two ends when absent.

◆ equal_range() [2/2]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
Pair< const_iterator, const_iterator > StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::equal_range ( const K & value) const

Return the range of values equal to value.

Parameters
valueLookup value.
Returns
The value and the following cursor, or two ends when absent.

◆ erase() [1/4]

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

Erase a value.

Parameters
valueLookup value.
Returns
Number of erased values, zero or one.

◆ erase() [2/4]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::erase ( const_iterator first,
const_iterator last )

Erase [first, last).

Parameters
firstFirst value to erase.
lastEnd of the range.
Returns
Iterator following the last erased value.

◆ erase() [3/4]

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

Erase the value at a read-only iterator.

Parameters
positionValue to erase.
Returns
Iterator following the erased value.

◆ erase() [4/4]

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

Erase the value at an iterator.

Parameters
positionValue to erase.
Returns
Iterator following the erased value.

◆ extract() [1/2]

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

Unlink value and return that node.

Parameters
valueLookup value.
Returns
Owning handle. Empty when the value is absent.

◆ extract() [2/2]

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

Unlink the value at position and return that node.

Parameters
positionValue to extract.
Returns
Owning handle. Empty when position is end.

◆ find() [1/2]

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

Find a value.

Parameters
valueLookup value.
Returns
Iterator to the value, or end.

◆ find() [2/2]

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

Find a value.

Parameters
valueLookup value.
Returns
Iterator to the value, or end.

◆ hash_function()

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

Return the stored hash.

Returns
Value hash.

◆ insert() [1/8]

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

Insert a value if it is absent.

Parameters
valueValue to copy.
Returns
Iterator to the value and whether it was inserted.
Exceptions
AllocationErrorThe node could not be allocated.

◆ insert() [2/8]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::insert ( const_iterator hint,
const K & value )

Insert a value.

hint is ignored.

Parameters
hintUnused.
valueValue to copy.
Returns
Iterator to the value.
Exceptions
AllocationErrorThe node could not be allocated.

◆ insert() [3/8]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::insert ( const_iterator hint,
K && value )

Insert a value.

hint is ignored.

Parameters
hintUnused.
valueValue to move.
Returns
Iterator to the value.
Exceptions
AllocationErrorThe node could not be allocated.

◆ insert() [4/8]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
iterator StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::insert ( const_iterator hint,
node_type && handle )

Insert an extracted node.

hint is ignored.

Parameters
hintUnused.
handleNode from a set with this hash and equality. Emptied when inserted.
Returns
Iterator to the value, or end when handle was empty.
Exceptions
AllocationErrorThe bucket array could not grow.

◆ insert() [5/8]

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class InputIt>
void StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::insert ( InputIt first,
InputIt last )

Insert every value in [first, last).

Template Parameters
InputItInput iterator of values.
Parameters
firstStart.
lastEnd.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert() [6/8]

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

Insert a value if it is absent.

Parameters
valueValue to move.
Returns
Iterator to the value and whether it was inserted.
Exceptions
AllocationErrorThe node could not be allocated.

◆ insert() [7/8]

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

Insert an extracted node if its value is absent.

The same node is linked.

Parameters
handleNode from a set with this hash and equality. Emptied when inserted.
Returns
Position, whether it was inserted, and the rejected node.
Exceptions
AllocationErrorThe bucket array could not grow.

◆ insert() [8/8]

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

Insert every value of an initializer list.

Parameters
valuesValues.
Exceptions
AllocationErrorA node could not be allocated.

◆ insert_range()

template<Type::SafeValue K, 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::UnorderedSet< K, Hash, KeyEqual >::insert_range ( R && range)
inline

Insert a copy of range.

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

◆ key_eq()

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

Return the stored equality predicate.

Returns
Value equality.

◆ load_factor()

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

Return the current load factor.

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

◆ max_load_factor() [1/2]

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

Return the load factor that triggers a rehash.

Returns
Maximum load factor.

◆ max_load_factor() [2/2]

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

Set the load factor that triggers a rehash.

Parameters
factorMaximum load factor. Not checked.

◆ max_size()

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

Return the maximum number of values.

Returns
Implementation limit.

◆ merge()

template<Type::SafeValue K, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
template<class OtherHash, class OtherEqual>
void StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::merge ( UnorderedSet< K, OtherHash, OtherEqual > & source)

Take unique values from source.

Template Parameters
OtherHashSource hash.
OtherEqualSource equality.
Parameters
sourceSet to drain. The same hash and equality transfer the node. A different predicate copies the value. Values already present stay in source.
Exceptions
AllocationErrorA copied node could not be allocated.

◆ operator std::unordered_set< K >()

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

Copy the values into caller-owned STL storage.

The STL hasher is std::hash.

Returns
An std::unordered_set owned by the caller.

◆ operator!=()

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

Compare values.

Order does not matter.

Parameters
otherOther set.
Returns
Whether the sets differ.

◆ operator=() [1/3]

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

Copy-assign the values.

Parameters
otherSource.
Returns
This set.
Exceptions
AllocationErrorA node could not be allocated.

◆ operator=() [2/3]

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

Replace the contents with an initializer list.

Parameters
valuesValues. Duplicates are dropped.
Returns
This set.
Exceptions
AllocationErrorA node could not be allocated.

◆ operator=() [3/3]

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

Move-assign the table.

other is left empty.

Parameters
otherSource.
Returns
This set.

◆ operator==()

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

Compare values.

Order does not matter.

Parameters
otherOther set.
Returns
Whether both sets hold the same values.

◆ rehash()

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

Replace the bucket array.

Values 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, class Hash = Hash<K>, class KeyEqual = std::equal_to<K>>
void StormByte::Safe::UnorderedSet< K, Hash, KeyEqual >::reserve ( size_type count)

Reserve room for count values without exceeding the load factor.

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

◆ size()

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

Return the number of values.

Returns
Value count.

◆ swap()

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

Exchange tables.

Parameters
otherOther set.

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