<unordered_map>
[added with C++11]
Include the STL
standard header <unordered_map>
to define the
container
template classes unordered_map
and
unordered_multimap
, and their supporting
templates.
namespace std { // DECLARATIONS template<class Key, class Ty, class Hash, class Pred, class Alloc> class unordered_map; template<class Key, class Ty, class Hash, class Pred, class Alloc> class unordered_multimap; // TEMPLATE FUNCTIONS template<class Key, class Ty, class Hash, class Pred, class Alloc> void swap( unordered_map<Key, Ty, Hash, Pred, Alloc>& left, unordered_map<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> void swap( unordered_multimap<Key, Ty, Hash, Pred, Alloc>& left, unordered_multimap<Key, Ty, Hash, Pred, Alloc>& right); // TEMPLATE OPERATORS template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator==( [added with C++11] const unordered_map<Key, Ty, Hash, Pred, Alloc>& left, const unordered_map<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator==( [added with C++11] const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& left, const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator!=( [added with C++11] const unordered_map<Key, Ty, Hash, Pred, Alloc>& left, const unordered_map<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator!=( [added with C++11] const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& left, const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& right); namespace tr1 { using std::unordered_map; using std::unordered_multimap; [added with C++11] } // namespace tr1 } // namespace std
operator==
template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator==( [added with C++11] const unordered_map<Key, Ty, Hash, Pred, Alloc>& left, const unordered_map<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator==( [added with C++11] const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& left, const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& right);
The first template function overloads operator==
to compare two objects of template class
unordered_map
.
The function returns true only if
left.size() ==
right.size()
and,
for each element X
in left
,
right.find(X->first)
exists and compares equal to X
using operator==
.
The second template function overloads operator==
to compare two objects of template class
unordered_multimap
.
The function returns true only if
left.size() ==
right.size()
and,
for each element X
in
left.equal_range(X.first)
,
right.equal_range(X.first)
is a permutation,
using is_permutation
.
operator!=
template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator!=( [added with C++11] const unordered_map<Key, Ty, Hash, Pred, Alloc>& left, const unordered_map<Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> bool operator!=( [added with C++11] const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& left, const unordered_multimap<Key, Ty, Hash, Pred, Alloc>& right);
The template functions both return !(left == right)
.
swap
template<class Key, class Ty, class Hash, class Pred, class Alloc> void swap( unordered_multimap <Key, Ty, Hash, Pred, Alloc>& left, unordered_multimap <Key, Ty, Hash, Pred, Alloc>& right); template<class Key, class Ty, class Hash, class Pred, class Alloc> void swap( unordered_map <Key, Ty, Hash, Pred, Alloc>& left, unordered_map <Key, Ty, Hash, Pred, Alloc>& right);
The template function executes
left.swap(right)
.
unordered_map
allocator_type
· at
· begin
· bucket
· bucket_count
· bucket_size
· cbegin
· cend
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· count
· difference_type
· emplace
· emplace_hint
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hasher
· hash_function
· insert
· iterator
· key_eq
· key_equal
· key_type
· load_factor
· local_iterator
· mapped_type
· max_bucket_count
· max_load_factor
· max_size
· operator=
· operator[]
· pointer
· reference
· rehash
· reserve
· size
· size_type
· swap
· unordered_map
· value_type
template<class Key, class Ty, class Hash = hash<Key>, class Pred = equal_to<Key>, class Alloc = allocator<Key> > class unordered_map { public: typedef Key key_type; typedef Ty mapped_type; typedef pair<const Key, Ty> value_type; typedef Hash hasher; typedef Pred key_equal; typedef Alloc allocator_type; typedef typename Alloc::pointer pointer; typedef typename Alloc::const_pointer const_pointer; typedef typename Alloc::reference reference; typedef typename Alloc::const_reference const_reference; typedef typename Alloc::size_type size_type; typedef typename Alloc::difference_type difference_type; typedef T0 iterator; typedef T1 const_iterator; typedef T2 local_iterator; typedef T3 const_local_iterator; explicit unordered_map( size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); explicit unordered_map(const Alloc& al); [added with C++11] unordered_map(const unordered_map& right); unordered_map(const unordered_map& right, const Alloc& al); [added with C++11] unordered_map(unordered_map&& right); [added with C++11] unordered_map(unordered_map&& right, const Alloc& al); [added with C++11] template<class InIt> unordered_map( InIt first, InIt last, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); unordered_map( initializer_list<Ty> init, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); [added with C++11] unordered_map& operator=(const unordered_map& right); unordered_map& operator=(initializer_list<Ty> init) [added with C++11] unordered_map& operator=(unordered_map&& right); [added with C++11] iterator begin() noexcept; const_iterator begin() const noexcept; local_iterator begin(size_type nbucket) noexcept; const_local_iterator begin(size_type nbucket) const noexcept; const_iterator cbegin() const noexcept; [added with C++11] const_local_iterator cbegin(size_type nbucket) const noexcept; [added with C++11] iterator end() noexcept; const_iterator end() const noexcept; local_iterator end(size_type nbucket) noexcept; const_local_iterator end(size_type nbucket) const noexcept; const_iterator cend() const noexcept; [added with C++11] const_local_iterator cend(size_type nbucket) const noexcept [added with C++11]; size_type size() const noexcept; size_type max_size() const noexcept; bool empty() const noexcept; size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; size_type bucket(const Key& keyval) const; size_type bucket_size(size_type nbucket) const; Hash hash_function() const; Pred key_eq() const; Alloc get_allocator() const noexcept; float load_factor() const noexcept; float max_load_factor() const noexcept; void max_load_factor(float factor); void rehash(size_type nbuckets); void reserve(size_type nelements); [added with C++11] mapped_type& operator[](const Key& keyval); mapped_type& operator[](Key&& keyval); [added with C++11] mapped_type& at(const Key& keyval); [added with C++11] const mapped_type& at(const Key& keyval); const [added with C++11] pair<iterator, bool> insert(const value_type& val); iterator insert(const_iterator where, const value_type& val); template<class InIt> void insert(InIt first, InIt last); void insert(initializer_list<Ty> init) [added with C++11] template<class Valty> pair<iterator, bool> insert(Valty&& val); [added with C++11] template<class Valty> iterator insert(const_iterator where, Valty&& val); [added with C++11] template<class... Valty> pair<iterator, bool> emplace(Valty&&... val); [added with C++11] template<class... Valty> iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11] iterator erase(const_iterator where); iterator erase(const_iterator first, const_iterator last); size_type erase(const Key& keyval); void clear() noexcept; void swap(unordered_map& right); const_iterator find(const Key& keyval) const; size_type count(const Key& keyval) const; pair<iterator, iterator> equal_range(const Key& keyval); pair<const_iterator, const_iterator> equal_range(const Key& keyval) const; };
The template class describes an object that controls a
varying-length sequence of elements of type
pair<const Key, Ty>
.
The sequence is weakly
ordered by a hash function,
which partitions the sequence into an ordered set of subsequences called
buckets. Within each bucket a comparison function determines
whether any pair of elements has
equivalent ordering.
Each element stores two objects, a sort key and a value.
The sequence is represented in a way that permits lookup, insertion,
and removal of an arbitrary element with a number of operations that can be
independent of the number of elements in the sequence (constant time),
at least when all buckets are of roughly equal length.
In the worst case, when all of the elements are in one bucket,
the number of operations is proportional to the number of elements
in the sequence (linear time). Moreover, inserting an element
invalidates no iterators unless rehashing occurs, and removing an element
invalidates only those iterators which point at the removed element.
The object orders the sequence it controls by calling two stored objects,
a comparison function object of type
key_equal
and a hash function object of type
hasher.
You access the first stored object by calling the member function
key_eq()
;
and you access the second stored object by calling the member function
hash_function()
.
Specifically, for all values X
and Y
of type Key
,
the call key_eq()(X, Y)
returns true only if
the two argument values have equivalent ordering;
the call hash_function()(keyval)
yields a distribution
of values of type size_t
.
Unlike template class unordered_multimap
,
an object of template class unordered_map
ensures that
key_eq()(X, Y)
is always false for any two elements of the controlled sequence.
(Keys are unique.)
The object also stores a maximum load factor, which specifies the
maximum desired average number of elements per bucket. If inserting an element
causes load_factor()
to exceed the maximum load factor, the container increases the number of
buckets and rebuilds the hash table as needed.
The actual order of elements in the controlled sequence depends on the hash function, the comparison function, the order of insertion, the maximum load factor, and the current number of buckets. You cannot in general predict the order of elements in the controlled sequence. You can always be assured, however, that any subset of elements that have equivalent ordering are adjacent in the controlled sequence.
The object allocates and frees storage for the sequence it controls
through a stored allocator object
of type allocator_type.
Such an allocator object must have
the same external interface as an object of template class
allocator
.
unordered_map::allocator_type
typedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc
.
unordered_map::at
const mapped_type& at(const Key& keyval) const; [added with C++11] mapped_type& at(const Key& keyval); [added with C++11]
The member function effectively determines the iterator where
as the return value of
find(keyval)
.
If that iterator does not designate an element whose sort key has
equivalent ordering
to keyval
, the function throws an object of class
out_of_range
. Otherwise, it returns a reference to
(*where).second
.
unordered_map::begin
iterator begin() noexcept; const_iterator begin() const noexcept; local_iterator begin(size_type nbucket) noexcept; const_local_iterator begin(size_type nbucket) const noexcept;
The first two member functions return a forward iterator that points at
the first element of the sequence (or just beyond the end of an empty
sequence). The last two member functions return a forward iterator that points at
the first element of bucket nbucket
(or just beyond the end of an empty
bucket).
unordered_map::bucket
size_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval
.
unordered_map::bucket_count
size_type bucket_count() const noexcept;
The member function returns the current number of buckets.
unordered_map::bucket_size
size_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket
.
unordered_map::cbegin
const_iterator cbegin() const noexcept; [added with C++11] const_local_iterator cbegin(size_type nbucket) const noexcept; [added with C++11]
The first member function returns a forward iterator that points at
the first element of the sequence (or just beyond the end of an empty
sequence). The second member function returns a forward iterator that points at
the first element of bucket nbucket
(or just beyond the end of an empty
bucket).
unordered_map::cend
const_reference cend() const noexcept; [added with C++11] const_local_iterator cend(size_type nbucket) const noexcept; [added with C++11]
The first member function returns a forward iterator that points
just beyond the end of the sequence.
The second member function returns a forward iterator that points
just beyond the end of bucket nbucket
.
unordered_map::clear
void clear() noexcept;
The member function calls
erase(
begin(),
end())
.
unordered_map::const_iterator
typedef T1 const_iterator;
The type describes an object that can serve as a constant
forward iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T1
.
unordered_map::const_local_iterator
typedef T3 const_local_iterator;
The type describes an object that can serve as a constant
forward iterator for a bucket.
It is described here as a
synonym for the implementation-defined type T3
.
unordered_map::const_pointer
typedef typename Alloc::const_pointer const_pointer;
The type describes an object that can serve as a constant pointer to an element of the controlled sequence.
unordered_map::const_reference
typedef typename Alloc::const_reference const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
unordered_map::count
size_type count(const Key& keyval) const;
The member function returns the number of elements in the range delimited by
equal_range(keyval)
.
unordered_map::difference_type
typedef typename Alloc::difference_type difference_type;
The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.
unordered_map::emplace
template<class... Valty> pair<iterator, bool> emplace(Valty&&... val); [added with C++11]
The member function effectively returns
insert(value_type(forward<Valty>(val)...))
,
except that the element value is constructed in place.
unordered_map::emplace_hint
template<class... Valty> iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]
The member function effectively returns
insert(where, value_type(forward<Valty>(val)...))
,
except that the element value is constructed in place.
unordered_map::empty
bool empty() const noexcept;
The member function returns true for an empty controlled sequence.
unordered_map::end
iterator end() noexcept; const_iterator end() const noexcept; local_iterator end(size_type nbucket) noexcept; const_local_iterator end(size_type nbucket) const noexcept;
The first two member functions return a forward iterator that points
just beyond the end of the sequence.
The last two member functions return a forward iterator that points
just beyond the end of bucket nbucket
.
unordered_map::equal_range
pair<iterator, iterator> equal_range(const Key& keyval); pair<const_iterator, const_iterator> equal_range(const Key& keyval) const;
The member function returns a pair of iterators X
such that [X.first,
X.second)
delimits just those elements of the controlled sequence that have
equivalent ordering with keyval
. If no such elements exist,
both iterators are end()
.
unordered_map::erase
iterator erase(const_iterator where); iterator erase(const_iterator first, const_iterator last); size_type erase(const Key& keyval);
The first member function removes the element of the controlled
sequence pointed to by where
.
The second member function removes the elements
in the range [first, last)
.
Both return an iterator that designates the first element remaining
beyond any elements removed, or
end()
if no such element exists.
The third member removes the elements in the range delimited by
equal_range(keyval)
.
It returns the number of elements it removes.
The member functions never throw an exception.
unordered_map::find
const_iterator find(const Key& keyval) const;
The member function returns
equal_range(keyval).first
.
unordered_map::get_allocator
Alloc get_allocator() const noexcept;
The member function returns the stored allocator object.
unordered_map::hash_function
Hash hash_function() const;
The member function returns the stored hash function object.
unordered_map::hasher
typedef Hash hasher;
The type is a synonym for the template parameter Hash
.
unordered_map::insert
pair<iterator, bool> insert(const value_type& val); iterator insert(const_iterator where, const value_type& val); template<class InIt> void insert(InIt first, InIt last); void insert(initializer_list<Ty> init) [added with C++11] template<class Valty> pair<iterator, bool> insert(Valty&& val); [added with C++11] template<class Valty> iterator insert(const_iterator where, Valty&& val); [added with C++11]
The first member function determines whether an element X
exists in the sequence whose key has
equivalent ordering
to that of val
. If not, it creates such
an element X
and initializes it with val
.
The function then determines the iterator where
that
designates X
. If an insertion occurred, the function
returns pair(where, true)
.
Otherwise, it returns pair(where, false)
.
The second member function returns insert(val).first
,
using where
as a starting place within the controlled
sequence to search for the insertion point. (Insertion can
possibly occur somewhat faster, if the
insertion point immediately precedes or follows where
.)
The third member function
inserts the sequence of element values,
for each where
in the range [first, last)
,
by calling insert(*where)
.
The fourth member function inserts the sequence
specified by an object of class
initializer_list<Ty>
.
The last two member functions behave the same as the first two but with an rvalue reference.
Unless is_convertible<Valty, value_type>
holds true,
the last two member functions
do not participate in overload resolution.
If an exception is thrown during the insertion of a single element, the container is left unaltered and the exception is rethrown. If an exception is thrown during the insertion of multiple elements, the container is left in a stable but unspecified state and the exception is rethrown.
unordered_map::iterator
typedef T0 iterator;
The type describes an object that can serve as a forward
iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T0
.
unordered_map::key_eq
Pred key_eq() const;
The member function returns the stored comparison function object.
unordered_map::key_equal
typedef Pred key_equal;
The type is a synonym for the template parameter Pred
.
unordered_map::key_type
typedef Key key_type;
The type is a synonym for the template parameter Key
.
unordered_map::load_factor
float load_factor() const noexcept;
The member function returns
(float)size() /
(float)bucket_count()
,
the average number of elements per bucket.
unordered_map::local_iterator
typedef T2 local_iterator;
The type describes an object that can serve as a
forward iterator for a bucket.
It is described here as a
synonym for the implementation-defined type T2
.
unordered_map::mapped_typer
typedef Ty mapped_type;
The type is a synonym for the template parameter Ty
.
unordered_map::max_bucket_count
size_type max_bucket_count() const noexcept;
The member function returns the maximum number of buckets currently permitted.
unordered_map::max_load_factor
float max_load_factor() const noexcept; void max_load_factor(float factor);
The first member function returns the stored maximum load factor.
The second member function replaces the stored maximum load factor with factor
.
unordered_map::max_size
size_type max_size() const noexcept;
The member function returns the length of the longest sequence that the object can control.
unordered_map::operator=
unordered_map& operator=(const unordered_map& right); unordered_map& operator=(initializer_list<Ty> init) [added with C++11] unordered_map& operator=(unordered_map&& right); [added with C++11]
The first member operator replaces the controlled sequence
with a copy of the sequence controlled by right
.
The second member operator replaces the controlled sequence
from an object of class
initializer_list<Ty>
.
The third member operator is the same as the first, but with an rvalue reference.
unordered_map::operator[]
mapped_type& operator[](const Key& keyval); mapped_type& operator[](Key&& keyval); [added with C++11]
The first member function determines the iterator where
as the return value of
insert(
value_type(keyval, Ty())
.
(It inserts an element with the specified key if no such element
exists.) It then returns a reference to
(*where).second
.
The second member operator is the same as the first, but with an rvalue reference.
unordered_map::pointer
typedef typename Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an element of the controlled sequence.
unordered_map::reference
typedef typename Alloc::reference reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
unordered_map::rehash
void rehash(size_type nbuckets);
The member function alters the number of buckets to be at least nbuckets
and rebuilds the hash table as needed.
unordered_map::reserve
void reserve(size_type nelements); [added with C++11]
The member function returns
rehash(ceil(nelements /
max_load_factor()))
.
unordered_map::size
size_type size() const noexcept;
The member function returns the length of the controlled sequence.
unordered_map::size_type
typedef typename Alloc::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
unordered_map::swap
void swap(unordered_map& right);
The member function swaps the controlled sequences between
*this
and right
. If
get_allocator()
== right.get_allocator()
, it does so in constant time,
it throws an exception only as a result of copying the stored
traits object of type Tr
, and it invalidates no references, pointers,
or iterators that designate elements in the two controlled sequences.
Otherwise, it performs a number of element assignments and constructor calls
proportional to the number of elements in the two controlled sequences.
unordered_map::unordered_map
explicit map( size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); explicit map(const Alloc& al); [added with C++11] map(const unordered_map& right); map(const unordered_map& right, const Alloc& al); [added with C++11] map(unordered_map&& right); [added with C++11] map(unordered_map&& right, const Alloc& al); [added with C++11] template<class InIt> map( InIt first, InIt last, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); map( initializer_list<Ty> init, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); [added with C++11]
All constructors initialize several stored values.
For the copy constructor, the values are obtained from right
.
Otherwise:
nbuckets
, if present;
otherwise it is a default value described here as the implementation-defined
value N0
.hfn
, if present;
otherwise it is Hash()
.comp
, if present;
otherwise it is Pred()
.al
, if present;
For the copy constructor, it is
right.get_allocator()
.
Otherwise, it is Alloc()
.The first two constructors specify an empty initial controlled sequence.
The next four constructors specify
a copy of the sequence controlled by right
.
The last two of these constructors are the same as the first two, but with an
rvalue reference.
The next constructor specifies the sequence of element values
[first, last)
.
The last constructor specifies the initial controlled sequence
with an object of class
initializer_list<Ty>
.
unordered_map::value_type
typedef pair<const Key, Ty> value_type;
The type describes an element of the controlled sequence.
unordered_multimap
allocator_type
· begin
· bucket
· bucket_count
· bucket_size
· cbegin
· cend
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· count
· difference_type
· emplace
· emplace_hint
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hasher
· hash_function
· insert
· iterator
· key_eq
· key_equal
· key_type
· load_factor
· local_iterator
· mapped_type
· max_bucket_count
· max_load_factor
· max_size
· operator=
· pointer
· reference
· rehash
· reserve
· size
· size_type
· swap
· unordered_multimap
· value_type
template<class Key, class Ty, class Hash = hash<Key>, class Pred = equal_to<Key>, class Alloc = allocator<Key> > class unordered_multimap { public: typedef Key key_type; typedef Ty mapped_type; typedef pair<const Key, Ty> value_type; typedef Hash hasher; typedef Pred key_equal; typedef Alloc allocator_type; typedef typename Alloc::pointer pointer; typedef typename Alloc::const_pointer const_pointer; typedef typename Alloc::reference reference; typedef typename Alloc::const_reference const_reference; typedef typename Alloc::size_type size_type; typedef typename Alloc::difference_type difference_type; typedef T0 iterator; typedef T1 const_iterator; typedef T2 local_iterator; typedef T3 const_local_iterator; explicit unordered_multimap( size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); explicit unordered_multimap(const Alloc& al); unordered_multimap(const unordered_multimap& right); unordered_multimap(const unordered_multimap& right, const Alloc& al); [added with C++11] unordered_multimap(unordered_multimap&& right); [added with C++11] unordered_multimap(unordered_multimap&& right, const Alloc& al); [added with C++11] unordered_multimap( initializer_list<Ty> init, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); [added with C++11] template<class InIt> unordered_multimap( InIt first, InIt last, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); unordered_multimap& operator=(const unordered_multimap& right); unordered_multimap& operator=(initializer_list<Ty> init) [added with C++11] unordered_multimap& operator=(unordered_multimap&& right); [added with C++11] iterator begin() noexcept; const_iterator begin() const noexcept; local_iterator begin(size_type nbucket) noexcept; const_local_iterator begin(size_type nbucket) const noexcept; const_iterator cbegin() const noexcept; [added with C++11] const_local_iterator cbegin(size_type nbucket) const noexcept; [added with C++11] iterator end() noexcept; const_iterator end() const noexcept; local_iterator end(size_type nbucket) noexcept; const_local_iterator end(size_type nbucket) const noexcept; const_iterator cend() const noexcept; [added with C++11] const_local_iterator cend(size_type nbucket) const noexcept; [added with C++11] iterator begin() noexcept; const_iterator begin() const noexcept; local_iterator begin(size_type nbucket); const_local_iterator begin(size_type nbucket) const; const_iterator cbegin() const noexcept; [added with C++11] const_iterator cend() const noexcept; [added with C++11] iterator end() noexcept; const_iterator end() const noexcept; local_iterator end(size_type nbucket) noexcept; const_local_iterator end(size_type nbucket) const noexcept; size_type size() const noexcept; size_type max_size() const noexcept; bool empty() const noexcept; size_type bucket_count() const noexcept; size_type max_bucket_count() const noexcept; size_type bucket(const Key& keyval) const; size_type bucket_size(size_type nbucket) const; Hash hash_function() const; Pred key_eq() const; Alloc get_allocator() const noexcept; float load_factor() const noexcept; float max_load_factor() const noexcept; void max_load_factor(float factor); void rehash(size_type nbuckets); void reserve(size_type nelements); [added with C++11] iterator insert(const value_type& val); iterator insert(const_iterator where, const value_type& val); template<class InIt> void insert(InIt first, InIt last); void insert(initializer_list<Ty> init) [added with C++11] template<class Valty> pair<iterator, bool> insert(Valty&& val); [added with C++11] template<class Valty> iterator insert(const_iterator where, Valty&& val); [added with C++11] template<class... Valty> pair<iterator, bool> emplace(Valty&&... val); [added with C++11] template<class... Valty> iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11] iterator erase(const_iterator where); iterator erase(const_iterator first, const_iterator last); size_type erase(const Key& keyval); void clear() noexcept; void swap(unordered_multimap& right); const_iterator find(const Key& keyval) const; size_type count(const Key& keyval) const; pair<iterator, iterator> equal_range(const Key& keyval); pair<const_iterator, const_iterator> equal_range(const Key& keyval) const; };
The template class describes an object that controls a
varying-length sequence of elements of type
pair<const Key, Ty>
.
The sequence is weakly
ordered by a hash function,
which partitions the sequence into an ordered set of subsequences called
buckets. Within each bucket a comparison function determines
whether any pair of elements has
equivalent ordering.
Each element stores two objects, a sort key and a value.
The sequence is represented in a way that permits lookup, insertion,
and removal of an arbitrary element with a number of operations that can be
independent of the number of elements in the sequence (constant time),
at least when all buckets are of roughly equal length.
In the worst case, when all of the elements are in one bucket,
the number of operations is proportional to the number of elements
in the sequence (linear time). Moreover, inserting an element
invalidates no iterators unless rehashing occurs, and removing an element
invalidates only those iterators which point at the removed element.
The object orders the sequence it controls by calling two stored objects,
a comparison function object of type
key_equal
and a hash function object of type
hasher.
You access the first stored object by calling the member function
key_eq()
;
and you access the second stored object by calling the member function
hash_function()
.
Specifically, for all values X
and Y
of type Key
,
the call key_eq()(X, Y)
returns true only if
the two argument values have equivalent ordering;
the call hash_function()(keyval)
yields a distribution
of values of type size_t
.
Unlike template class unordered_map
,
an object of template class unordered_multimap
does not ensure that
key_eq()(X, Y)
is always false for any two elements of the controlled sequence.
(Keys need not be unique.)
The object also stores a maximum load factor, which specifies the
maximum desired average number of elements per bucket. If inserting an element
causes load_factor()
to exceed the maximum load factor, the container increases the number of
buckets and rebuilds the hash table as needed.
The actual order of elements in the controlled sequence depends on the hash function, the comparison function, the order of insertion, the maximum load factor, and the current number of buckets. You cannot in general predict the order of elements in the controlled sequence. You can always be assured, however, that any subset of elements that have equivalent ordering are adjacent in the controlled sequence.
The object allocates and frees storage for the sequence it controls
through a stored allocator object
of type allocator_type.
Such an allocator object must have
the same external interface as an object of template class
allocator
.
Inserting and erasing elements, and rehashing, preserves the order of elements with equivalent ordering.
unordered_multimap::allocator_type
typedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc
.
unordered_multimap::begin
iterator begin() noexcept; const_iterator begin() const noexcept; local_iterator begin(size_type nbucket) noexcept; const_local_iterator begin(size_type nbucket) const noexcept;
The first two member functions return a forward iterator that points at
the first element of the sequence (or just beyond the end of an empty
sequence). The last two member functions return a forward iterator that points at
the first element of bucket nbucket
(or just beyond the end of an empty
bucket).
unordered_multimap::bucket
size_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval
.
unordered_multimap::bucket_count
size_type bucket_count() const noexcept;
The member function returns the current number of buckets.
unordered_multimap::bucket_size
size_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket
.
unordered_multimap::cbegin
const_iterator cbegin() const noexcept; [added with C++11] const_local_iterator cbegin(size_type nbucket) const noexcept; [added with C++11]
The first member function returns a forward iterator that points at
the first element of the sequence (or just beyond the end of an empty
sequence). The second member function returns a forward iterator that points at
the first element of bucket nbucket
(or just beyond the end of an empty
bucket).
unordered_multimap::cend
const_reference cend() const noexcept; [added with C++11] const_local_iterator cend(size_type nbucket) const noexcept; [added with C++11]
The first member function returns a forward iterator that points
just beyond the end of the sequence.
The second member function returns a forward iterator that points
just beyond the end of bucket nbucket
.
unordered_multimap::clear
void clear() noexcept;
The member function calls
erase(
begin(),
end())
.
unordered_multimap::const_iterator
typedef T1 const_iterator;
The type describes an object that can serve as a constant
forward iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T1
.
unordered_multimap::const_local_iterator
typedef T3 const_local_iterator;
The type describes an object that can serve as a constant
forward iterator for a bucket.
It is described here as a
synonym for the implementation-defined type T3
.
unordered_multimap::const_pointer
typedef typename Alloc::const_pointer const_pointer;
The type describes an object that can serve as a constant pointer to an element of the controlled sequence.
unordered_multimap::const_reference
typedef typename Alloc::const_reference const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
unordered_multimap::count
size_type count(const Key& keyval) const;
The member function returns the number of elements in the range delimited by
equal_range(keyval)
.
unordered_multimap::difference_type
typedef typename Alloc::difference_type difference_type;
The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence.
unordered_multimap::emplace
template<class... Valty> pair<iterator, bool> emplace(Valty&&... val); [added with C++11]
The member function effectively returns
insert(value_type(forward<Valty>(val)...))
,
except that the element value is constructed in place.
unordered_multimap::emplace_hint
template<class... Valty> iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]
The member function effectively returns
insert(where, value_type(forward<Valty>(val)...))
,
except that the element value is constructed in place.
unordered_multimap::empty
bool empty() const noexcept;
The member function returns true for an empty controlled sequence.
unordered_multimap::end
iterator end() noexcept; const_iterator end() const noexcept; local_iterator end(size_type nbucket) noexcept; const_local_iterator end(size_type nbucket) const noexcept;
The first two member functions return a forward iterator that points
just beyond the end of the sequence.
The last two member functions return a forward iterator that points
just beyond the end of bucket nbucket
.
unordered_multimap::equal_range
pair<iterator, iterator> equal_range(const Key& keyval); pair<const_iterator, const_iterator> equal_range(const Key& keyval) const;
The member function returns a pair of iterators X
such that [X.first,
X.second)
delimits just those elements of the controlled sequence that have
equivalent ordering with keyval
. If no such elements exist,
both iterators are end()
.
unordered_multimap::erase
iterator erase(const_iterator where); iterator erase(const_iterator first, const_iterator last); size_type erase(const Key& keyval);
The first member function removes the element of the controlled
sequence pointed to by where
.
The second member function removes the elements
in the range [first, last)
.
Both return an iterator that designates the first element remaining
beyond any elements removed, or
end()
if no such element exists.
The third member removes the elements in the range delimited by
equal_range(keyval)
.
It returns the number of elements it removes.
The member functions never throw an exception.
unordered_multimap::find
const_iterator find(const Key& keyval) const;
The member function returns
equal_range(keyval).first
.
unordered_multimap::get_allocator
Alloc get_allocator() const noexcept;
The member function returns the stored allocator object.
unordered_multimap::hash_function
Hash hash_function() const;
The member function returns the stored hash function object.
unordered_multimap::hasher
typedef Hash hasher;
The type is a synonym for the template parameter Hash
.
unordered_multimap::insert
iterator insert(const value_type& val); iterator insert(const_iterator where, const value_type& val); template<class InIt> void insert(InIt first, InIt last); void insert(initializer_list<Ty> init) [added with C++11] template<class Valty> pair<iterator, bool> insert(Valty&& val); [added with C++11] template<class Valty> iterator insert(const_iterator where, Valty&& val); [added with C++11]
The first member function inserts the element val
in the controlled sequence, then returns
the iterator that designates the inserted element.
The second member function returns insert(val)
,
using where
as a starting place within the controlled
sequence to search for the insertion point. (Insertion can
possibly occur somewhat faster, if the
insertion point immediately precedes or follows where
.)
The third member function
inserts the sequence of element values,
for each where
in the range [first, last)
,
by calling insert(*where)
.
The fourth member function inserts the sequence
specified by an object of class
initializer_list<Ty>
.
The last two member functions behave the same as the first two but with an rvalue reference.
Unless is_convertible<Valty, value_type>
holds true,
the last two member functions
do not participate in overload resolution.
If an exception is thrown during the insertion of a single element, the container is left unaltered and the exception is rethrown. If an exception is thrown during the insertion of multiple elements, the container is left in a stable but unspecified state and the exception is rethrown.
unordered_multimap::iterator
typedef T0 iterator;
The type describes an object that can serve as a forward
iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T0
.
unordered_multimap::key_eq
Pred key_eq() const;
The member function returns the stored comparison function object.
unordered_multimap::key_equal
typedef Pred key_equal;
The type is a synonym for the template parameter Pred
.
unordered_multimap::key_type
typedef Key key_type;
The type is a synonym for the template parameter Key
.
unordered_multimap::load_factor
float load_factor() const noexcept;
The member function returns
(float)size() /
(float)bucket_count()
,
the average number of elements per bucket.
unordered_multimap::local_iterator
typedef T2 local_iterator;
The type describes an object that can serve as a
forward iterator for a bucket.
It is described here as a
synonym for the implementation-defined type T2
.
unordered_multimap::mapped_type
typedef Ty mapped_type;
The type is a synonym for the template parameter Ty
.
unordered_multimap::max_bucket_count
size_type max_bucket_count() const noexcept;
The member function returns the maximum number of buckets currently permitted.
unordered_multimap::max_load_factor
float max_load_factor() const noexcept; void max_load_factor(float factor);
The first member function returns the stored maximum load factor.
The second member function replaces the stored maximum load factor with factor
.
unordered_multimap::max_size
size_type max_size() const noexcept;
The member function returns the length of the longest sequence that the object can control.
unordered_multimap::operator=
unordered_multimap& operator=(const unordered_multimap& right); unordered_multimap& operator=(initializer_list<Ty> init) [added with C++11] unordered_multimap& operator=(unordered_multimap&& right); [added with C++11]
The first member operator replaces the controlled sequence
with a copy of the sequence controlled by right
.
The second member operator replaces the controlled sequence
from an object of class
initializer_list<Ty>
.
The third member operator is the same as the first, but with an rvalue reference.
unordered_multimap::pointer
typedef typename Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an element of the controlled sequence.
unordered_multimap::reference
typedef typename Alloc::reference reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
unordered_multimap::rehash
void rehash(size_type nbuckets);
The member function alters the number of buckets to be at least nbuckets
and rebuilds the hash table as needed.
unordered_multimap::reserve
void reserve(size_type nelements); [added with C++11]
The member function returns
rehash(ceil(nelements /
max_load_factor()))
.
unordered_multimap::size
size_type size() const noexcept;
The member function returns the length of the controlled sequence.
unordered_multimap::size_type
typedef typename Alloc::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
unordered_multimap::swap
void swap(unordered_multimap& right);
The member function swaps the controlled sequences between
*this
and right
. If
get_allocator()
== right.get_allocator()
, it does so in constant time,
it throws an exception only as a result of copying the stored
traits object of type Tr
, and it invalidates no references, pointers,
or iterators that designate elements in the two controlled sequences.
Otherwise, it performs a number of element assignments and constructor calls
proportional to the number of elements in the two controlled sequences.
unordered_multimap::unordered_multimap
explicit unordered_multimap( size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); explicit unordered_multimap(const Alloc& al); unordered_multimap(const unordered_multimap& right); unordered_multimap(const unordered_multimap& right, const Alloc& al); [added with C++11] unordered_multimap(unordered_multimap&& right); [added with C++11] unordered_multimap(unordered_multimap&& right, const Alloc& al); [added with C++11] template<class InIt> unordered_multimap( InIt first, InIt last, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); unordered_multimap( initializer_list<Ty> init, size_type nbuckets = N0, const Hash& hfn = Hash(), const Pred& comp = Pred(), const Alloc& al = Alloc()); [added with C++11]
All constructors initialize several stored values.
For the copy constructor, the values are obtained from right
.
Otherwise:
nbuckets
, if present;
otherwise it is a default value described here as the implementation-defined
value N0
.hfn
, if present;
otherwise it is Hash()
.comp
, if present;
otherwise it is Pred()
.al
, if present;
For the copy constructor, it is
right.get_allocator()
.
Otherwise, it is Alloc()
.The first two constructors specify an empty initial controlled sequence.
The next four constructors specify
a copy of the sequence controlled by right
.
The last two of these constructors are the same as the first two, but with an
rvalue reference.
The next constructor specifies the sequence of element values
[first, last)
.
The last constructor specifies the initial controlled sequence
with an object of class
initializer_list<Ty>
.
unordered_multimap::value_type
typedef pair<const Key, Ty> value_type;
The type describes an element of the controlled sequence.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by P.J. Plauger. All rights reserved.