#include <bn_unordered_set.h>
iunordered_set class
Base class of bn::
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::
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_class unordered_set
to<Key>> 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_ |
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_ |
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_
Parameters | |
---|---|
key | Key to search for. |
Returns | true if the specified key is contained in this iunordered_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_
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_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_
Parameters | |
---|---|
key | Key to search for. |
Returns | 1 if the specified key is contained in this iunordered_ |
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_
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_ |
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>
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_
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_
Parameters | |
---|---|
other | iunordered_ |
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_
Parameters | |
---|---|
a | First iunordered_ |
b | Second iunordered_ |
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_ |
b | Second iunordered_ |
Returns | true if the first iunordered_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_ |
b | Second iunordered_ |
Returns | true if the first iunordered_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_ |
b | Second iunordered_ |
Returns | true if the first iunordered_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_ |
b | Second iunordered_ |
Returns | true if the first iunordered_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_ |
b | Second iunordered_ |
Returns | true if the first iunordered_false . |