Introduction
It is an associative container that store unique elements in no particular order, and which allow for fast retrieval of individual elements based on their value.
Definition
Below is definition of std::unordered_set
template < class Key, class Hash = hash<Key>, class Pred = equal_to<Key>, class Alloc = allocator<Key> > class unordered_set;
Parameters
- Key − It defines the type of element.
- Hash − It is a unary function object.
- Pred − It is a binary predicate that takes two arguments of the same type as the elements and returns a bool.
- Alloc − It defines the type of allowcater.
Member types
Following member types can be used as parameters or return type by member functions.
Member Type | Definition | Notes |
---|---|---|
key_type | It is the first template parameter (Key) | |
value_type | It is the first template parameter (Key) | The same as key_type |
hasher | It is the second template parameter (Hash) | defaults to: hash<key_type> |
key_equal | It is the third template parameter (Pred) | defaults to: equal_to<key_type> |
allocator_type | It is the fourth template parameter (Alloc) | defaults to: allocator<value_type> |
reference | Alloc::reference | |
const_reference | Alloc::const_reference | |
pointer | Alloc::pointer | for the default allocator: value_type* |
const_pointer | Alloc::const_pointer | for the default allocator: const value_type* |
iterator | a forward iterator to const value_type | * convertible to const_iterator |
const_iterator | a forward iterator to const value_type | * |
local_iterator | a forward iterator to const value_type | * convertible to const_local_iterator |
const_local_iterator | a forward iterator to const value_type | * |
size_type | an unsigned integral type | usually the same as size_t |
difference_type | a signed integral type | usually the same as ptrdiff_t |
Member functions
Below is list of member functions
Sr.No. | Method & Description |
---|---|
It is used to assign the content. |
Capacity
Sr.No. | Capacity & Description |
---|---|
1 |
It is used to test whether container is empty. |
2 |
It returns container size. |
3 |
It returns maximum size. |
Iterators
Sr.No. | Iterators & Description |
---|---|
1 |
It returns iterator to beginning. |
2 |
It returns iterator to end. |
3 |
It returns const_iterator to beginning. |
4 |
It return const_iterator to end. |
Element lookup
Sr.No. | Element lookup & Description |
---|---|
1 |
It is used to get iterator to element. |
2 |
It is used to count elements with a specific key. |
3 |
It is used to get range of elements with a specific key. |
Modifiers
Sr.No. | Modifiers & Description |
---|---|
1 |
It is used to construct and insert element. |
2 |
It is used to construct and insert element with hint. |
3 |
It is used to insert elements. |
4 |
It is used to erase elements. |
5 |
It is used to clear content. |
6 |
It is used to swap content. |
Buckets
Sr.No. | Buckets & Description |
---|---|
1 |
It returns number of buckets. |
2 |
It returns maximum number of buckets. |
3 |
It returns bucket size. |
4 |
It locates element”s bucket. |
Hash policy
Sr.No. | Hash policy & Description |
---|---|
1 |
It returns load factor. |
2 |
It is used to get or set maximum load factor. |
3 |
It is used to set number of buckets. |
4 |
It gives a request to capacity chage of backets |
Observers
Sr.No. | Observers & Description |
---|---|
1 |
It is used to get hash function. |
2 |
It is used to get key equivalence predicate. |
3 |
It is used to get allocator. |
Non-member overloaded functions
Sr.No. | Non-member function overloads & Description |
---|---|
1 |
operator== Tests whether two maps are equal or not. |
2 |
operator!= Tests whether two maps are equal or not. |
3 |
It exchanges contents of two unordered_set containers. |