STD::UNORDERED_MAP(3)
๐ฆ STD::UNORDERED_MAP ๐
okay so bestie, you just cracked open the Library Functions Manual and landed on section 3 โ the one where we talk about functions and containers and all the C++ goodies. and the star of today's episode? std::unordered_map. no cap. ๐
the whole thing lives under the template signature
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >
so like, five template params, one icon. periodt. ๐
โจ NAME โจ
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > โ a standard container composed of unique keys (containing at most one of each key value) that associates values of another type with the keys. ๐
like, literally: keys stay unique, values tag along with them, and the container holds the whole situationship together. it's giving matchmaker energy fr fr. ๐ซถ
part 2 is loading, don't go anywhere ๐ธ
SYNOPSIS โจ
okay bestie, this is the whole vibe of std::unordered_map ๐. it's giving I have all the typedefs and functions you'll ever need โจ. let's get into it, no cap.
Public Types ๐ท๏ธ
these are the types you're gonna be working with, periodt ๐ .
Public typedefs โจ
typedef _Hashtable::key_type key_typeโ Public typedefs. ๐typedef _Hashtable::value_type value_typeโ Public typedefs. ๐typedef _Hashtable::mapped_type mapped_typeโ Public typedefs. ๐typedef _Hashtable::hasher hasherโ Public typedefs. ๐typedef _Hashtable::key_equal key_equalโ Public typedefs. ๐typedef _Hashtable::allocator_type allocator_typeโ Public typedefs. ๐
Iterator-related typedefs ๐ฆ
typedef _Hashtable::pointer pointerโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::const_pointer const_pointerโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::reference referenceโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::const_reference const_referenceโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::iterator iteratorโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::const_iterator const_iteratorโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::local_iterator local_iteratorโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::const_local_iterator const_local_iteratorโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::size_type size_typeโ Iterator-related typedefs. ๐ฆtypedef _Hashtable::difference_type difference_typeโ Iterator-related typedefs. ๐ฆ
Public Member Functions ๐ ๏ธ
okay so this is the whole function menu. it's long but we're gonna get through it together, fr fr ๐ช. every single overload is here, no skips.
unordered_map () = defaultโ Default constructor. ๐- ```cpp template<typename _InputIterator> unordered_map (_InputIterator __first, _InputIterator __last, const allocator_type &__a)
- ```cpp
template<typename _InputIterator> unordered_map (_InputIterator __first,
_InputIterator __last, size_type __n, const allocator_type &__a)
- ```cpp template<typename _InputIterator> unordered_map (_InputIterator __first, _InputIterator __last, size_type __n, const hasher &__hf, const allocator_type &__a)
- ```cpp
template<typename _InputIterator> unordered_map (_InputIterator __first,
_InputIterator __last, size_type __n=0, const hasher &__hf=hasher(),
const key_equal &__eql=key_equal(), const allocator_type
&__a=allocator_type())
Builds an unordered_map from a range. ๐
unordered_map (const allocator_type &__a)โ Creates an unordered_map with no elements. ๐ซถunordered_map (const unordered_map &)=defaultโ Copy constructor. ๐ฏ- ```cpp unordered_map (const unordered_map &__umap, const allocator_type &__a)
- ```cpp
unordered_map (initializer_list< value_type > __l, const allocator_type
&__a)
- ```cpp unordered_map (initializer_list< value_type > __l, size_type __n, const allocator_type &__a)
- ```cpp
unordered_map (initializer_list< value_type > __l, size_type __n, const
hasher &__hf, const allocator_type &__a)
- ```cpp unordered_map (initializer_list< value_type > __l, size_type __n=0, const hasher &__hf=hasher(), const key_equal &__eql=key_equal(), const allocator_type &__a=allocator_type())
Builds an unordered_map from an initializer_list. ๐
- ```cpp
unordered_map (size_type __n, const allocator_type &__a)
- ```cpp unordered_map (size_type __n, const hasher &__hf, const allocator_type &__a)
- ```cpp
unordered_map (size_type __n, const hasher &__hf=hasher(), const
key_equal &__eql=key_equal(), const allocator_type
&__a=allocator_type())
Default constructor creates no elements. ๐ญ
unordered_map (unordered_map &&)=defaultโ Move constructor. ๐- ```cpp unordered_map (unordered_map &&__umap, const allocator_type &__a) noexcept(noexcept(_Hashtable(std::move(__umap._M_h), __a)))
- **`iterator begin () noexcept`**
- **`local_iterator begin (size_type __n)`** โ Returns a read/write iterator pointing to the first bucket element. ๐ชฃ
- **`size_type bucket_count () const noexcept`** โ Returns the number of buckets of the unordered_map. ๐ข
- **`size_type bucket_size (size_type __n) const`**
- **`void clear () noexcept`**
- ```cpp
template<typename... _Args> std::pair< iterator, bool > emplace (_Args
&&... __args)
Attempts to build and insert a std::pair into the unordered_map. ๐
- ```cpp template<typename... _Args> iterator emplace_hint (const_iterator __pos, _Args &&... __args)
Attempts to build and insert a std::pair into the unordered_map. ๐
- **`bool empty () const noexcept`** โ Returns true if the unordered_map is empty. ๐ซ
- **`iterator end () noexcept`**
- **`local_iterator end (size_type __n)`** โ Returns a read/write iterator pointing to one past the last bucket elements. ๐
- ```cpp
iterator erase (const_iterator __first, const_iterator __last)
Erases a [__first,__last) range of elements from an unordered_map. โ๏ธ
allocator_type get_allocator () const noexceptโ Returns the allocator object used by the unordered_map. ๐งบhasher hash_function () constโ Returns the hash functor object with which the unordered_map was constructed. #๏ธโฃ- ```cpp template<typename _InputIterator> void insert (_InputIterator __first, _InputIterator __last)
A template function that attempts to insert a range of elements. ๐ฅ
- ```cpp
void insert (initializer_list< value_type > __l)
Attempts to insert a list of elements into the unordered_map. ๐
key_equal key_eq () constโ Returns the key comparison object with which the unordered_map was constructed. โ๏ธfloat load_factor () const noexceptโ Returns the average number of elements per bucket. โ๏ธsize_type max_bucket_count () const noexceptโ Returns the maximum number of buckets of the unordered_map. ๐ชฃfloat max_load_factor () const noexceptโ Returns a positive number that the unordered_map tries to keep the load factor less than or equal to. ๐void max_load_factor (float __z)โ Change the unordered_map maximum load factor. ๐งsize_type max_size () const noexceptโ Returns the maximum size of the unordered_map. ๐unordered_map & operator= (const unordered_map &)=defaultโ Copy assignment operator. ๐unordered_map & operator= (initializer_list< value_type > __l)โ Unordered_map list assignment operator. ๐unordered_map & operator= (unordered_map &&)=defaultโ Move assignment operator. ๐void rehash (size_type __n)โ May rehash the unordered_map. ๐void reserve (size_type __n)โ Prepare the unordered_map for a specified number of elements. ๐๏ธsize_type size () const noexceptโ Returns the size of the unordered_map. ๐- ```cpp void swap (unordered_map &__x) noexcept(noexcept(_M_h.swap(__x._M_h)))
Swaps data with another unordered_map. ๐
- **`const_iterator begin () const noexcept`**
- **`const_iterator cbegin () const noexcept`**
- **`const_iterator end () const noexcept`**
- **`const_iterator cend () const noexcept`**
- ```cpp
std::pair< iterator, bool > insert (const value_type &__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp std::pair< iterator, bool > insert (value_type &&__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp
template<typename _Pair> __enable_if_t< is_constructible<
value_type, _Pair && >::value, pair< iterator, bool > > insert
(_Pair &&__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp iterator insert (const_iterator __hint, const value_type &__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp
iterator insert (const_iterator __hint, value_type &&__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp template<typename _Pair> __enable_if_t< is_constructible< value_type, _Pair && >::value, iterator > insert (const_iterator __hint, _Pair &&__x)
Attempts to insert a std::pair into the unordered_map. ๐
- ```cpp
iterator erase (const_iterator __position)
Erases an element from an unordered_map. โ๏ธ
- ```cpp iterator erase (iterator __position)
Erases an element from an unordered_map. โ๏ธ
- ```cpp
size_type erase (const key_type &__x)
Erases elements according to the provided key. ๐
- ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> size_type erase (_Kt &&__x)
Erases elements according to the provided key. ๐
- ```cpp
iterator find (const key_type &__x)
Tries to locate an element in an unordered_map. ๐
- ```cpp const_iterator find (const key_type &__x) const
Tries to locate an element in an unordered_map. ๐
- ```cpp
size_type count (const key_type &__x) const
Finds the number of elements. ๐ข
- ```cpp bool contains (const key_type &__x) const
Finds whether an element with the given key exists. โ
- ```cpp
template<typename _Kt> auto contains (const _Kt &__x) const ->
decltype(_M_h._M_find_tr(__x), void(), true)
Finds whether an element with the given key exists. โ
- ```cpp std::pair< iterator, iterator > equal_range (const key_type &__x)
Finds a subsequence matching given key. ๐
- ```cpp
std::pair< const_iterator, const_iterator > equal_range (const
key_type &__x) const
Finds a subsequence matching given key. ๐
- ```cpp mapped_type & operator[] (const key_type &__k)
Subscript ( [] ) access to unordered_map data. ๐๏ธ
- ```cpp
mapped_type & operator[] (key_type &&__k)
Subscript ( [] ) access to unordered_map data. ๐๏ธ
- ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & operator[] (_Kt &&__k)
Subscript ( [] ) access to unordered_map data. ๐๏ธ
- ```cpp
mapped_type & at (const key_type &__k)
Access to unordered_map data. ๐
- ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & at (const _Kt &__k)
Access to unordered_map data. ๐
- ```cpp
const mapped_type & at (const key_type &__k) const
Access to unordered_map data. ๐
- ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> const mapped_type & at (const _Kt &__k) const
Access to unordered_map data. ๐
- ```cpp
size_type bucket (const key_type &__key) const
- ```cpp template<__heterogeneous_hash_key< unordered_map > _Kt> size_type bucket (const _Kt &__key) const
- ```cpp
const_local_iterator begin (size_type __n) const
Returns a read-only (constant) iterator pointing to the first bucket element. ๐ชฃ
- ```cpp const_local_iterator cbegin (size_type __n) const
Returns a read-only (constant) iterator pointing to the first
bucket element. ๐ชฃ
- ```cpp
const_local_iterator end (size_type __n) const
Returns a read-only (constant) iterator pointing to one past the last bucket elements. ๐
- ```cpp const_local_iterator cend (size_type __n) const
Returns a read-only (constant) iterator pointing to one past the
last bucket elements. ๐
> not me listing every single overload like my life depends on it ๐ but we did it bestie, we did it.
## Friends ๐ค
- ```cpp
template<typename _Key1, typename _Tp1, typename _Hash1, typename
_Pred1, typename _Alloc1> bool operator== (const unordered_map<
_Key1, _Tp1, _Hash1, _Pred1, _Alloc1 > &, const unordered_map<
_Key1, _Tp1, _Hash1, _Pred1, _Alloc1 > &)
โจ Detailed Description โจ
okay so here's the whole vibe of std::unordered_map. she is, and I quote, a class:
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>>
class std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >
"A standard container composed of unique keys (containing at most one of each key value) that associates values of another type with the keys. โ bestie that's just a dictionary and she ATE ๐
Since: C++11 ๐
Template Parameters ๐ธ
_Keyโ type of key objects._Tpโ type of mapped objects._Hashโ hashing function object type, defaults tohash<_Key>._Predโ predicate function object type, defaults toequal_to<_Key>._Allocโ allocator type, defaults tostd::allocator<std::pair<const _Key, _Tp>>.
Meets the requirements of a container, and unordered associative container โ yes queen, she's certified, she passed the vibe check โ
The resulting value type of the container is std::pair<const _Key, _Tp>. ๐ซถ
Base is _Hashtable, dispatched at compile time via template alias __umap_hashtable. lowkey iconic implementation detail, no cap.
๐ Member Typedef Documentation ๐
every single one of these is a member of that exact same class template from up top (you know the one โ template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>>), so just mentally copy-paste the header in front of each, mwah ๐
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::allocator_typeโ public typedefs ๐std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_iteratorโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_local_iteratorโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_pointerโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::const_referenceโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::difference_typeโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::hasherโ public typedefs ๐std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::iteratorโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::key_equalโ public typedefs ๐std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::key_typeโ public typedefs ๐std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::local_iteratorโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::mapped_typeโ public typedefs ๐std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::pointerโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::referenceโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::size_typeโ iterator-related typedefsstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::value_typeโ public typedefs ๐
sixteen of them. she's thorough and we love that for her ๐
๐ง Constructor & Destructor Documentation ๐ง
all of these live inside that same big template header, you know the drill by now bestie โจ
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map ()[default]โ Default constructor ๐ฑstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (size_type __n, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type())[inline],[explicit]โ Default constructor creates no elements.- Parameters
__nโ minimal initial number of buckets.__hfโ a hash functor.__eqlโ a key equality functor.__aโ an allocator object.
- Parameters
template<typename _InputIterator> std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (_InputIterator __first, _InputIterator __last, size_type __n = 0, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type())[inline]โ Builds an unordered_map from a range. ๐ฆ- Parameters
__firstโ an input iterator.__lastโ an input iterator.__nโ minimal initial number of buckets.__hfโ a hash functor.__eqlโ a key equality functor.__aโ an allocator object.
- Create an
unordered_mapconsisting of copies of the elements from[__first,__last). This is linear in N (where N isdistance(__first,__last)). so like, it does the thing, fast, we stan ๐ฅ
- Parameters
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (const unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > & )[default]โ Copy constructor. twin where have you been ๐ฏstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > && )[default]โ Move constructor. she's leaving but she's taking everything with her, periodt ๐จstd::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (const allocator_type & __a)[inline],[explicit]โ Creates an unordered_map with no elements.- Parameters
__aโ an allocator object.
- Parameters
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::unordered_map (initializer_list< value_type > __l, size_type __n = 0, const hasher & __hf = hasher(), const key_equal & __eql = key_equal(), const allocator_type & __a = allocator_type())[inline]โ Builds an unordered_map from an initializer_list. ๐- Parameters
__lโ an initializer_list.__nโ minimal initial number of buckets.__hfโ a hash functor.__eqlโ a key equality functor.__aโ an allocator object.
- Create an
unordered_mapconsisting of copies of the elements in the list. This is linear in N (where N is__l.size()). ๐งฎ
- Parameters
๐ Member Function Documentation ๐
the at girlies ๐
all three of these are members of the same template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> class, okurrr โจ
template<__heterogeneous_hash_key< unordered_map > _Kt> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const _Kt & __k)[inline]โ Access to unordered_map data. ๐- Parameters
__kโ the key for which data should be retrieved.
- Returns
- A reference to the data whose key is equal to
__k, if such a data is present in theunordered_map.
- A reference to the data whose key is equal to
- Exceptions
std::out_of_rangeif no such data is present. she will THROW, do not test her ๐ญ
- Parameters
template<__heterogeneous_hash_key< unordered_map > _Kt> const mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const _Kt & __k) const[inline]โ Access to unordered_map data. ๐- Parameters
__kโ the key for which data should be retrieved.
- Returns
- A reference to the data whose key is equal to
__k, if such a data is present in theunordered_map.
- A reference to the data whose key is equal to
- Exceptions
std::out_of_rangeif no such data is present. same energy, still throwing ๐
- Parameters
mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const key_type & __k)[inline]โ Access to unordered_map data. ๐- Parameters
__kโ the key for which data should be retrieved.
- Returns
- A reference to the data whose key is equal to
__k, if such a data is present in theunordered_map.
- A reference to the data whose key is equal to
- Parameters
Exceptions: std::out_of_range if no such data is present. ๐ that's the vibe for the overload above, and it's the vibe for this one too, bestie.
โจ at (the const girlie) โจ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::at (const key_type & __k) const [inline]
Access to unordered_map data. It's giving "hand me the thing" energy but make it read-only. ๐
Parameters
__kโ the key for which data should be retrieved.
Returns
A reference to the data whose key is equal to __k, if such a data is present in the unordered_map. ๐
Exceptions
std::out_of_rangeโ if no such data is present. No key, no data, we're throwing. ๐ญ
๐ธ begin (const) ๐ธ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the unordered_map. Look but don't touch, periodt. ๐
๐ฆ begin ๐ฆ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin () [inline], [noexcept]
Returns a read/write iterator that points to the first element in the unordered_map. Now you can actually edit things, main character energy fr fr. โจ
๐ง begin (bucket edition) ๐ง
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin (size_type __n) [inline]
Returns a read/write iterator pointing to the first bucket element. Yes bestie, you can poke around inside one single bucket. ๐ชฃ
Parameters
__nโ the bucket index.
Returns
A read/write local iterator.
๐ begin (bucket + const) ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::begin (size_type __n) const [inline]
Returns a read-only (constant) iterator pointing to the first bucket element.
Parameters
__nโ the bucket index.
Returns
A read-only local iterator.
๐ bucket_count ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::bucket_count () const [inline], [noexcept]
Returns the number of buckets of the unordered_map. That's it, that's the whole job. ๐
โญ cbegin โญ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cbegin () const [inline], [noexcept]
Returns a read-only (constant) iterator that points to the first element in the unordered_map. The "c" stands for const, iykyk. ๐
๐ cbegin (bucket) ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cbegin (size_type __n) const [inline]
Returns a read-only (constant) iterator pointing to the first bucket element.
Parameters
__nโ the bucket index.
Returns
A read-only local iterator.
๐ซ cend ๐ซ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cend () const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the unordered_map. Not the last element itself โ past it. Classic off-by-one's cooler sibling. ๐
๐ซถ cend (bucket) ๐ซถ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::cend (size_type __n) const [inline]
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
Parameters
__nโ the bucket index.
Returns
A read-only local iterator.
๐งน clear ๐งน
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::clear () [inline], [noexcept]
Erases all elements in an unordered_map. Fresh start, blank slate, cleanse era. โจ
Heads up bestie: this function only erases the elements, and if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. So if you thoughtclear()would clean up after yournewsโฆ no ma'am. ๐ญ
๐ contains (the template one) ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename _Kt> auto std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::contains (const _Kt & __x) const -> decltype(_M_h._M_find_tr(__x), void(), true) [inline]
Finds whether an element with the given key exists. The vibe check of the container world. ๐
Parameters
__xโ key of elements to be located.
Returns
True if there is any element with the specified key.
๐ contains (the key_type one) ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> bool std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::contains (const key_type & __x) const [inline]
Finds whether an element with the given key exists.
Parameters
__xโ key of elements to be located.
Returns
True if there is any element with the specified key.
๐งฎ count ๐งฎ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::count (const key_type & __x) const [inline]
Finds the number of elements.
Parameters
__xโ key to count.
Returns
Number of elements with specified key.
Real talk: this function only makes sense for unordered_multimap; for unordered_map the result will either be 0 (not present) or 1 (present). So it's not really counting, it's just โจconfirmingโจ. ๐
๐ emplace ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename... _Args> std::pair< iterator, bool > std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::emplace (_Args &&... __args) [inline]
Attempts to build and insert a std::pair into the unordered_map. Construction in place, no copies wasted, we love a resourceful queen. ๐
Parameters
__argsโ arguments used to generate a new pair instance (seestd::piecewise_contructfor passing arguments to each part of the pair constructor).
Returns
A pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a bool that is true if the pair was actually inserted.
This function attempts to build and insert a (key, value) pair into the unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map. No duplicates allowed, we run a strict door policy here. ๐ช
Insertion requires amortized constant time.
๐ฏ emplace_hint ๐ฏ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> template<typename... _Args> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::emplace_hint (const_iterator __pos, _Args &&... __args) [inline]
Attempts to build and insert a std::pair into the unordered_map. Same energy as emplace, but now with a hint. ๐ญ
Parameters
__posโ an iterator that serves as a hint as to where the pair should be inserted.__argsโ arguments used to generate a new pair instance (seestd::piecewise_contructfor passing arguments to each part of the pair constructor).
Returns
An iterator that points to the element with key of the std::pair built from __args (may or may not be that std::pair).
This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument emplace() does. Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency. It's a suggestion, not a command, bestie. ๐
See
https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints for more on hinting.
Insertion requires amortized constant time.
๐ซง empty ๐ซง
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> bool std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::empty () const [inline], [nodiscard], [noexcept]
Returns true if the unordered_map is empty. Yes she's [nodiscard] โ do not ignore her answer, that's rude. ๐ค
๐ end (const) ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end () const [inline], [noexcept]
Returns a read-only (constant) iterator that points one past the last element in the unordered_map.
๐ end ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end () [inline], [noexcept]
Returns a read/write iterator that points one past the last element in the unordered_map.
๐ชฃ end (bucket) ๐ชฃ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end (size_type __n) [inline]
Returns a read/write iterator pointing to one past the last bucket elements.
Parameters
__nโ the bucket index.
Returns
A read/write local iterator.
๐ชฃ end (bucket + const) ๐ชฃ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> const_local_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::end (size_type __n) const [inline]
Returns a read-only (constant) iterator pointing to one past the last bucket elements.
Parameters
__nโ the bucket index.
Returns
A read-only local iterator.
๐ equal_range ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename _Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const _Key, _Tp>>> std::pair< iterator, iterator > std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::equal_range (const key_type & __x) [inline]
Finds a subsequence matching given key. It's giving two-for-one deal, a whole pair of iterators. ๐
Parameters
__xโ key to be located.
Returns
Pair of iterators that possibly points to the subsequence matching given key.
This function probably only makes sense for unordered_multimap. ๐
๐ฆ equal_range โ the const girlie
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> std::pair< const_iterator, const_iterator >
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::equal_range
(const key_type & __x) const [inline]
Finds a subsequence matching given key. bestie it's giving "where are my people at" energy โจ
Parameters
__xโ the key you want located ๐
Returns
- a pair of iterators that possibly points to the subsequence matching the given key ๐ซถ
This function probably only makes sense for unordered_multimap. ๐ (yes, again. she said what she said.)
๐ erase โ the heterogeneous key one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> template<__heterogeneous_hash_key< unordered_map > _Kt>
size_type std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::erase
(_Kt && __x) [inline]
Erases elements according to the provided key. bye felicia ๐
Parameters
__xโ key of the element to be erased ๐ช
Returns
- the number of elements erased ๐ข
okay so real talk: this function erases all the elements located by the given key from an unordered_map. And for an unordered_map the result of this function can only be 0 (not present) or 1 (present). no in-between, no drama, just math ๐
โ ๏ธ Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. that's on you bestie, not on the container ๐ญ
๐ธ erase โ the const key_type one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::erase (const key_type & __x) [inline]
Erases elements according to the provided key.
Parameters
__xโ key of the element to be erased ๐ช
Returns
- the number of elements erased ๐ข
same deal, different overload. This function erases all the elements located by the given key from an unordered_map. For an unordered_map the result of this function can only be 0 (not present) or 1 (present). And again:
โ ๏ธ This function only erases the element โ if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. ๐ซ
๐ง erase โ the range one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::erase (const_iterator __first, const_iterator __last) [inline]
Erases a [__first,__last) range of elements from an unordered_map. a whole squad, gone ๐
Parameters
__firstโ iterator pointing to the start of the range to be erased ๐__lastโ iterator pointing to the end of the range to be erased ๐
Returns
- the iterator
__last๐ซถ
This function erases a sequence of elements from an unordered_map.
โ ๏ธ Note that this function only erases the elements, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. fr fr, it's your pointer, your problem ๐
๐ erase โ the const_iterator __position one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::erase (const_iterator __position) [inline]
Erases an element from an unordered_map. one singular element. targeted. iconic ๐ฏ
Parameters
__positionโ an iterator pointing to the element to be erased ๐
Returns
- an iterator pointing to the element immediately following
__positionprior to the element being erased. If no such element exists,end()is returned. ๐
This function erases an element, pointed to by the given iterator, from an unordered_map.
โ ๏ธ Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. no cap ๐
โญ erase โ the iterator __position one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::erase (iterator __position) [inline]
Erases an element from an unordered_map. the non-const twin, she's the same girl, different fit โจ
Parameters
__positionโ an iterator pointing to the element to be erased ๐
Returns
- an iterator pointing to the element immediately following
__positionprior to the element being erased. If no such element exists,end()is returned. ๐
This function erases an element, pointed to by the given iterator, from an unordered_map.
โ ๏ธ Note that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility. ๐
๐ find โ the non-const one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::find (const key_type & __x) [inline]
Tries to locate an element in an unordered_map. she's searching, she's looking, she's manifesting ๐ต๏ธโโ๏ธ
Parameters
__xโ key to be located ๐
Returns
- iterator pointing to the sought-after element, or
end()if not found ๐ญ
This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end (end()) iterator. the way that end() is always there for you ๐ซถ
๐ find โ the const one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> const_iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::find (const key_type & __x) const [inline]
Tries to locate an element in an unordered_map.
Parameters
__xโ key to be located ๐
Returns
- iterator pointing to the sought-after element, or
end()if not found ๐ญ
Same search, same energy, but this one hands you a const_iterator. This function takes a key and tries to locate the element with which the key matches. If successful the function returns an iterator pointing to the sought after element. If unsuccessful it returns the past-the-end (end()) iterator. slay โจ
๐ get_allocator
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> allocator_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::get_allocator () const [inline], [noexcept]
Returns the allocator object used by the unordered_map. she's giving you the keys to the allocator, no questions asked ๐๏ธ
๐ hash_function
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> hasher std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::hash_function () const [inline]
Returns the hash functor object with which the unordered_map was constructed. the whole vibe this container was built on, handed right back to you ๐ซถโจ
๐ insert โ the range one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> template<typename _InputIterator> void std::unordered_map<
_Key, _Tp, _Hash, _Pred, _Alloc >::insert (_InputIterator __first,
_InputIterator __last) [inline]
A template function that attempts to insert a range of elements. come in, the whole crew ๐
Parameters
__firstโ iterator pointing to the start of the range to be inserted ๐__lastโ iterator pointing to the end of the range ๐
Complexity similar to that of the range constructor.
๐ insert โ the _Pair && one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> template<typename _Pair> __enable_if_t< is_constructible<
value_type, _Pair && >::value, pair< iterator, bool > >
std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc >::insert (_Pair &&
__x) [inline]
Attempts to insert a std::pair into the unordered_map.
Parameters
__xโ pair to be inserted (seestd::make_pairfor easy creation of pairs) ๐ซถ
Returns
- a pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a
boolthat istrueif the pair was actually inserted ๐
This function attempts to insert a (key, value) pair into the unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map. no dupes allowed bestie ๐
โโ๏ธ
Insertion requires amortized constant time. fast fr fr โก
๐ insert โ the const value_type & one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> std::pair< iterator, bool > std::unordered_map< _Key, _Tp,
_Hash, _Pred, _Alloc >::insert (const value_type & __x) [inline]
Attempts to insert a std::pair into the unordered_map.
Parameters
__xโ pair to be inserted (seestd::make_pairfor easy creation of pairs) ๐ซถ
Returns
- a pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a
boolthat istrueif the pair was actually inserted ๐
This function attempts to insert a (key, value) pair into the unordered_map. An unordered_map relies on unique keys and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map.
Insertion requires amortized constant time. โก
โจ insert โ the const_iterator __hint + _Pair && one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> template<typename _Pair> __enable_if_t< is_constructible<
value_type, _Pair && >::value, iterator > std::unordered_map< _Key, _Tp,
_Hash, _Pred, _Alloc >::insert (const_iterator __hint, _Pair && __x)
[inline]
Attempts to insert a std::pair into the unordered_map.
Parameters
__hintโ an iterator that serves as a hint as to where the pair should be inserted ๐ซฐ__xโ pair to be inserted (seestd::make_pairfor easy creation of pairs) ๐ซถ
Returns
- an iterator that points to the element with key of
__x(may or may not be the pair passed in) ๐
This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. she's unbothered ๐
Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency. so likeโฆ don't stress the hint too much bestie ๐ญ
See
https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
for more on hinting. iykyk ๐
Insertion requires amortized constant time. โก
๐ฆ insert โ the const_iterator __hint + const value_type & one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::insert (const_iterator __hint, const value_type & __x)
[inline]
Attempts to insert a std::pair into the unordered_map.
๐ซฃ and that's where this part ends, bestie โ the rest of this overload's lore is coming up next. don't go anywhere ๐
Okay bestie, we were literally mid-sentence on the hinted insert โ here's the rest of that one, no cap ๐
__hintโ an iterator that serves as a hint as to where the pair should be inserted.__xโ the pair to be inserted (peepstd::make_pairif you want easy creation of pairs).
Returns โ an iterator that points to the element with key of __x (it may or may not be the pair passed in, so don't get attached ๐ซถ).
This function is not concerned about whether the insertion actually took place, so it does not return a boolean like the single-argument insert() does. And heads up: that first parameter is only a hint โ it can potentially improve the performance of the insertion process, but a bad hint would cause no gains in efficiency. So like, hint responsibly.
For more on hinting, go read https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints
Insertion requires amortized constant time. โจ
insert (const_iterator __hint, value_type && __x) โ the move-y hinted one ๐ฆ
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> iterator std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::insert (const_iterator __hint, value_type && __x) [inline]
Attempts to insert a std::pair into the unordered_map.
__hintโ an iterator that serves as a hint as to where the pair should be inserted.__xโ the pair to be inserted (seestd::make_pairfor easy creation of pairs).
Returns โ an iterator that points to the element with key of __x (may or may not be the pair passed in).
This function is not concerned about whether the insertion took place, and thus does not return a boolean like the single-argument insert() does. Note that the first parameter is only a hint and can potentially improve the performance of the insertion process. A bad hint would cause no gains in efficiency.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/associative.html#containers.associative.insert_hints for more on hinting.
Insertion requires amortized constant time.
insert (initializer_list< value_type > __l) โ the bulk drop ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::insert (initializer_list< value_type > __l) [inline]
Attempts to insert a list of elements into the unordered_map. It's giving "dump the whole squad in at once" energy ๐
__lโ astd::initializer_list<value_type>of elements to be inserted.
Complexity similar to that of the range constructor.
insert (value_type && __x) โ the single move-in ๐
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> std::pair< iterator, bool > std::unordered_map< _Key, _Tp,
_Hash, _Pred, _Alloc >::insert (value_type && __x) [inline]
Attempts to insert a std::pair into the unordered_map.
__xโ the pair to be inserted (seestd::make_pairfor easy creation of pairs).
Returns โ a pair, of which the first element is an iterator that points to the possibly inserted pair, and the second is a bool that is true if the pair was actually inserted. So yes, this one does tell you if it slayed or not. ๐
This function attempts to insert a (key, value) pair into the unordered_map. An unordered_map relies on unique keys, and thus a pair is only inserted if its first element (the key) is not already present in the unordered_map.
Insertion requires amortized constant time.
key_eq
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> key_equal std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::key_eq () const [inline]
Returns the key comparison object with which the unordered_map was constructed. That's it, that's the whole function. Short queen. ๐ง
load_factor
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> float std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::load_factor () const [inline], [noexcept]
Returns the average number of elements per bucket. Yes, it's a float. Yes, [noexcept]. We love a low-stress getter. ๐
max_bucket_count
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::max_bucket_count () const [inline], [noexcept]
Returns the maximum number of buckets of the unordered_map. The absolute ceiling, the final boss of bucket counts. ๐
max_load_factor (the getter)
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> float std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::max_load_factor () const [inline], [noexcept]
Returns a positive number that the unordered_map tries to keep the load factor less than or equal to. It's a goal, not a promise, iykyk. โญ
max_load_factor (the setter)
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::max_load_factor (float __z) [inline]
Change the unordered_map maximum load factor.
__zโ the new maximum load factor.
max_size
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::max_size () const [inline], [noexcept]
Returns the maximum size of the unordered_map. Hypothetically. In theory. Don't try to get there bestie, your RAM will simply pass away. ๐
operator= โ copy assignment
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
_Pred, _Alloc >::operator= (const unordered_map< _Key, _Tp, _Hash,
_Pred, _Alloc > & ) [default]
Copy assignment operator. Compiler-said-so, [default] and all. ๐
operator= โ list assignment
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
_Pred, _Alloc >::operator= (initializer_list< value_type > __l) [inline]
Unordered_map list assignment operator.
__lโ aninitializer_list.
This function fills an unordered_map with copies of the elements in the initializer list __l.
Note that the assignment completely changes the unordered_map, and that the resulting unordered_map's size is the same as the number of elements assigned. Full glow-up, total replacement. ๐
operator= โ move assignment
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> unordered_map & std::unordered_map< _Key, _Tp, _Hash,
_Pred, _Alloc >::operator= (unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc > && ) [default]
Move assignment operator. Also [default], also iconic. โจ
operator[] โ the heterogeneous key one
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> template<__heterogeneous_hash_key< unordered_map > _Kt>
mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::operator[] (_Kt && __k) [inline]
Subscript ( [] ) access to unordered_map data.
__kโ the key for which data should be retrieved.
Returns โ a reference to the data of the (key,data) pair.
Allows for easy lookup with the subscript ( [] ) operator. Returns data associated with the key specified in subscript. If the key does not exist, a pair with that key is created using default values, which is then returned. So like, sneaky โ it will make the thing. ๐ซถ
Lookup requires constant time.
operator[] โ const key_type &
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::operator[] (const key_type & __k) [inline]
Subscript ( [] ) access to unordered_map data.
__kโ the key for which data should be retrieved.
Returns โ a reference to the data of the (key,data) pair.
Allows for easy lookup with the subscript ( [] ) operator. Returns data associated with the key specified in subscript. If the key does not exist, a pair with that key is created using default values, which is then returned.
Lookup requires constant time.
operator[] โ key_type &&
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> mapped_type & std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::operator[] (key_type && __k) [inline]
Subscript ( [] ) access to unordered_map data.
__kโ the key for which data should be retrieved.
Returns โ a reference to the data of the (key,data) pair.
Allows for easy lookup with the subscript ( [] ) operator. Returns data associated with the key specified in subscript. If the key does not exist, a pair with that key is created using default values, which is then returned.
Lookup requires constant time. Three flavors of the same slay. ๐
rehash
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::rehash (size_type __n) [inline]
May rehash the unordered_map. Emphasis on may, bestie.
__nโ the new number of buckets.
Rehash will occur only if the new number of buckets respect the unordered_map maximum load factor. So sometimes it just looks at your request and politely declines. ๐ญ
reserve
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::reserve (size_type __n) [inline]
Prepare the unordered_map for a specified number of elements. Manifesting capacity. ๐ธ
__nโ number of elements required.
Same as rehash(ceil(n / max_load_factor())).
size
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> size_type std::unordered_map< _Key, _Tp, _Hash, _Pred,
_Alloc >::size () const [inline], [noexcept]
Returns the size of the unordered_map. The headcount. The roster. The [noexcept] little icon it is. ๐
swap
template<typename _Key, typename _Tp, typename _Hash = hash<_Key>, typename
_Pred = equal_to<_Key>, typename _Alloc = allocator<std::pair<const
_Key, _Tp>>> void std::unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc
>::swap (unordered_map< _Key, _Tp, _Hash, _Pred, _Alloc > & __x)
[inline], [noexcept]
Swaps data with another unordered_map.
__xโ an unordered_map of the same element and allocator types.
This exchanges the elements between two unordered_map in constant time. Note that the global std::swap() function is specialized such that std::swap(m1,m2) will feed to this function. Trade offer: you get my buckets, I get yours. ๐ค
๐ AUTHOR ๐
Generated automatically by Doxygen for libstdc++ from the source code.
And that's a wrap on the whole std::unordered_map saga, bestie โ every last flag, default, [noexcept] and hint, accounted for. ๐ This beauty lives in the libstdc++ manual set, page std::unord...d, _Alloc >(3), and it came to you courtesy of Doxygen auto-generating it straight from the source code. Go forth and hash responsibly. ๐โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 ยท GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 ยท GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms