template<typename Key, typename KeyHash = hash<Key>, typename KeyEqual = equal_to<Key>>
bn::iunordered_set class

Base class of bn::unordered_set.

Template parameters
Key Element type.
KeyHash Functor used to calculate the hash of a given key.
KeyEqual Functor used for all key comparisons.

Can be used as a reference type for all bn::unordered_set containers containing a specific type.

Unlike std::unordered_set, it doesn't offer pointer stability when moving or erasing elements.

Derived classes

template<typename Key, int MaxSize, typename KeyHash = hash<Key>, typename KeyEqual = equal_to<Key>>
class unordered_set
std::unordered_set like container with a fixed size buffer.

Public types

class const_iterator
Const iterator.
class iterator
Non const iterator.
using key_type = Key
Key type alias.
using value_type = Key
Value type alias.
using size_type = int
Size type alias.
using difference_type = int
Difference type alias.
using hash_type = unsigned
Hash type alias.
using hasher = KeyHash
Hash functor alias.
using key_equal = KeyEqual
Equality functor alias.
using reference = value_type&
Reference alias.
using const_reference = const value_type&
Const reference alias.
using pointer = value_type*
Pointer alias.
using const_pointer = const value_type*
Const pointer alias.
using reverse_iterator = bn::reverse_iterator<iterator>
Reverse iterator alias.
using const_reverse_iterator = bn::reverse_iterator<const_iterator>
Const reverse iterator alias.

Constructors, destructors, conversion operators

~iunordered_set() defaulted noexcept
Destructor.
~iunordered_set() noexcept
Destructor.

Public functions

auto operator=(const iunordered_set& other) -> iunordered_set&
Copy assignment operator.
auto operator=(iunordered_set&& other) -> iunordered_set& noexcept
Move assignment operator.
auto size() const -> size_type
Returns the current size.
auto max_size() const -> size_type
Returns the maximum possible size.
auto available() const -> size_type
Returns the remaining capacity.
auto empty() const -> bool
Indicates if it doesn't contain any element.
auto full() const -> bool
Indicates if it can't contain any more elements.
auto begin() const -> const_iterator
Returns a const iterator to the beginning of the iunordered_set.
auto begin() -> iterator
Returns an iterator to the beginning of the iunordered_set.
auto end() const -> const_iterator
Returns a const iterator to the end of the iunordered_set.
auto end() -> iterator
Returns an iterator to the end of the iunordered_set.
auto cbegin() const -> const_iterator
Returns a const iterator to the beginning of the iunordered_set.
auto cend() const -> const_iterator
Returns a const iterator to the end of the iunordered_set.
auto rbegin() const -> const_reverse_iterator
Returns a const reverse iterator to the end of the iunordered_set.
auto rbegin() -> reverse_iterator
Returns a reverse iterator to the end of the iunordered_set.
auto rend() const -> const_reverse_iterator
Returns a const reverse iterator to the beginning of the iunordered_set.
auto rend() -> reverse_iterator
Returns a reverse iterator to the beginning of the iunordered_set.
auto crbegin() const -> const_reverse_iterator
Returns a const reverse iterator to the end of the iunordered_set.
auto crend() const -> const_reverse_iterator
Returns a const reverse iterator to the beginning of the iunordered_set.
auto contains(const key_type& key) const -> bool
Indicates if the specified key is contained in this iunordered_set.
auto contains_hash(hash_type key_hash, const key_type& key) const -> bool
Indicates if the specified key is contained in this iunordered_set.
auto count(const key_type& key) const -> size_type
Counts the number of keys stored in this iunordered_set are equal to the given one.
auto count_hash(hash_type key_hash, const key_type& key) const -> size_type
Counts the number of keys stored in this iunordered_set are equal to the given one.
auto find(const key_type& key) const -> const_iterator
Searches for a given key.
auto find(const key_type& key) -> iterator
Searches for a given key.
auto find_hash(hash_type key_hash, const key_type& key) const -> const_iterator
Searches for a given key.
auto find_hash(hash_type key_hash, const key_type& key) -> iterator
Searches for a given key.
auto insert(const value_type& value) -> iterator
Inserts a copy of the given value.
auto insert(value_type&& value) -> iterator
Inserts a moved value.
auto insert_hash(hash_type value_hash, const value_type& value) -> iterator
Inserts a copy of the given value.
auto insert_hash(hash_type value_hash, value_type&& value) -> iterator
Inserts a moved value.
auto erase(const const_iterator& position) -> iterator
Erases an element.
auto erase(const key_type& key) -> bool
Erases an element.
auto erase_hash(hash_type key_hash, const key_type& key) -> bool
Erases an element.
template<class Pred>
auto erase_if(const Pred& pred) -> size_type
Erases all elements that satisfy the specified predicate.
void merge(iunordered_set&& other)
Moves all elements of the given iunordered_set into this one, leaving the first one empty.
void clear()
Removes all elements.
void clear()
Removes all elements.
void swap(iunordered_set& other)
Exchanges the contents of this iunordered_set with those of the other one.

Friends

void swap(iunordered_set& a, iunordered_set& b)
Exchanges the contents of a iunordered_set with those of another one.
auto operator==(const iunordered_set& a, const iunordered_set& b) -> bool
Equal operator.
auto operator<(const iunordered_set& a, const iunordered_set& b) -> bool
Less than operator.
auto operator>(const iunordered_set& a, const iunordered_set& b) -> bool
Greater than operator.
auto operator<=(const iunordered_set& a, const iunordered_set& b) -> bool
Less than or equal operator.
auto operator>=(const iunordered_set& a, const iunordered_set& b) -> bool
Greater than or equal operator.

Function documentation

template<typename Key, typename KeyHash, typename KeyEqual>
iunordered_set& bn::iunordered_set<Key, KeyHash, KeyEqual>::operator=(const iunordered_set& other)

Copy assignment operator.

Parameters
other iunordered_set to copy.
Returns Reference to this.

template<typename Key, typename KeyHash, typename KeyEqual>
iunordered_set& bn::iunordered_set<Key, KeyHash, KeyEqual>::operator=(iunordered_set&& other) noexcept

Move assignment operator.

Parameters
other iunordered_set to move.
Returns Reference to this.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
bool bn::iunordered_set<Key, KeyHash, KeyEqual>::contains(const key_type& key) const

Indicates if the specified key is contained in this iunordered_set.

Parameters
key Key to search for.
Returns true if the specified key is contained in this iunordered_set, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
bool bn::iunordered_set<Key, KeyHash, KeyEqual>::contains_hash(hash_type key_hash, const key_type& key) const

Indicates if the specified key is contained in this iunordered_set.

Parameters
key_hash Hash of the given key to search for.
key Key to search for.
Returns true if the specified key is contained in this iunordered_set, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
size_type bn::iunordered_set<Key, KeyHash, KeyEqual>::count(const key_type& key) const

Counts the number of keys stored in this iunordered_set are equal to the given one.

Parameters
key Key to search for.
Returns 1 if the specified key is contained in this iunordered_set, otherwise 0.

template<typename Key, typename KeyHash, typename KeyEqual>
size_type bn::iunordered_set<Key, KeyHash, KeyEqual>::count_hash(hash_type key_hash, const key_type& key) const

Counts the number of keys stored in this iunordered_set are equal to the given one.

Parameters
key_hash Hash of the given key to search for.
key Key to search for.
Returns 1 if the specified key is contained in this iunordered_set, otherwise 0.

template<typename Key, typename KeyHash, typename KeyEqual>
const_iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::find(const key_type& key) const

Searches for a given key.

Parameters
key Key to search for.
Returns Const iterator to the key if it exists, otherwise end().

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::find(const key_type& key)

Searches for a given key.

Parameters
key Key to search for.
Returns Iterator to the key if it exists, otherwise end().

template<typename Key, typename KeyHash, typename KeyEqual>
const_iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::find_hash(hash_type key_hash, const key_type& key) const

Searches for a given key.

Parameters
key_hash Hash of the given key to search for.
key Key to search for.
Returns Const iterator to the key if it exists, otherwise end().

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::find_hash(hash_type key_hash, const key_type& key)

Searches for a given key.

Parameters
key_hash Hash of the given key to search for.
key Key to search for.
Returns Iterator to the key if it exists, otherwise end().

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::insert(const value_type& value)

Inserts a copy of the given value.

Parameters
value Value to insert.
Returns Iterator pointing to the inserted value.

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::insert(value_type&& value)

Inserts a moved value.

Parameters
value Value to insert.
Returns Iterator pointing to the inserted value.

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::insert_hash(hash_type value_hash, const value_type& value)

Inserts a copy of the given value.

Parameters
value_hash Hash of the value to insert.
value Value to insert.
Returns Iterator pointing to the inserted value.

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::insert_hash(hash_type value_hash, value_type&& value)

Inserts a moved value.

Parameters
value_hash Hash of the value to insert.
value Value to insert.
Returns Iterator pointing to the inserted value.

template<typename Key, typename KeyHash, typename KeyEqual>
iterator bn::iunordered_set<Key, KeyHash, KeyEqual>::erase(const const_iterator& position)

Erases an element.

Parameters
position Iterator to the element to erase.
Returns Iterator following the erased element.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
bool bn::iunordered_set<Key, KeyHash, KeyEqual>::erase(const key_type& key)

Erases an element.

Parameters
key Key to erase.
Returns true if the elements was erased, otherwise false.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
bool bn::iunordered_set<Key, KeyHash, KeyEqual>::erase_hash(hash_type key_hash, const key_type& key)

Erases an element.

Parameters
key_hash Hash of the key to erase.
key Key to erase.
Returns true if the elements was erased, otherwise false.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual> template<class Pred>
size_type bn::iunordered_set<Key, KeyHash, KeyEqual>::erase_if(const Pred& pred)

Erases all elements that satisfy the specified predicate.

Parameters
pred Unary predicate which returns ​true if the element should be erased.
Returns Number of erased elements.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
void bn::iunordered_set<Key, KeyHash, KeyEqual>::merge(iunordered_set&& other)

Moves all elements of the given iunordered_set into this one, leaving the first one empty.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
void bn::iunordered_set<Key, KeyHash, KeyEqual>::swap(iunordered_set& other)

Exchanges the contents of this iunordered_set with those of the other one.

Parameters
other iunordered_set to exchange the contents with.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
void swap(iunordered_set& a, iunordered_set& b)

Exchanges the contents of a iunordered_set with those of another one.

Parameters
a First iunordered_set to exchange the contents with.
b Second iunordered_set to exchange the contents with.

Unlike std::unordered_set, it doesn't offer pointer stability.

template<typename Key, typename KeyHash, typename KeyEqual>
bool operator==(const iunordered_set& a, const iunordered_set& b)

Equal operator.

Parameters
a First iunordered_set to compare.
b Second iunordered_set to compare.
Returns true if the first iunordered_set is equal to the second one, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
bool operator<(const iunordered_set& a, const iunordered_set& b)

Less than operator.

Parameters
a First iunordered_set to compare.
b Second iunordered_set to compare.
Returns true if the first iunordered_set is lexicographically less than the second one, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
bool operator>(const iunordered_set& a, const iunordered_set& b)

Greater than operator.

Parameters
a First iunordered_set to compare.
b Second iunordered_set to compare.
Returns true if the first iunordered_set is lexicographically greater than the second one, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
bool operator<=(const iunordered_set& a, const iunordered_set& b)

Less than or equal operator.

Parameters
a First iunordered_set to compare.
b Second iunordered_set to compare.
Returns true if the first iunordered_set is lexicographically less than or equal to the second one, otherwise false.

template<typename Key, typename KeyHash, typename KeyEqual>
bool operator>=(const iunordered_set& a, const iunordered_set& b)

Greater than or equal operator.

Parameters
a First iunordered_set to compare.
b Second iunordered_set to compare.
Returns true if the first iunordered_set is lexicographically greater than or equal to the second one, otherwise false.