<hash_map>Include the STL
standard header <hash_map> to define the
container
template classes hash_map and
hash_multimap, and their supporting
templates.
namespace std {
template<class Key, class Pr>
class hash_compare;
template<class Key, class Ty, class Tr, class Alloc>
class hash_map;
template<class Key, class Ty, class Tr, class Alloc>
class hash_multimap;
// TEMPLATE FUNCTIONS
template<class Key, class Ty, class Tr, class Alloc>
bool operator==(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator==(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator!=(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator!=(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator>(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator>(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<=(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<=(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator>=(
const hash_map<Key, Ty, Tr, Alloc>& left,
const hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator>=(
const hash_multimap<Key, Ty, Tr, Alloc>& left,
const hash_multimap<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
void swap(
hash_map<Key, Ty, Tr, Alloc>& left,
hash_map<Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
void swap(
hash_multimap<Key, Ty, Tr, Alloc>& left,
hash_multimap<Key, Ty, Tr, Alloc>& right);
} // namespace std
hash_comparetemplate<class Key,
class Pr = less<Key> >
class hash_compare {
Pr comp;
public:
const size_t bucket_size = 4;
const size_t min_buckets = 8;
hash_compare();
hash_compare(Pr pred);
size_t operator()(const Key& Key) const;
bool operator()(const Key& keyval1,
const Key& keyval2) const;
};
The template class describes an object that can be used by
any of the containers
hash_map,
hash_multimap,
hash_set, or
hash_multiset as a
hash traits object
to order the sequence it controls.
Each of these stores hash traits object of type Tr
(a template parameter). You can derive a class from a specialization of
hash_compare, to selectively override certain functions
and objects. Or you can supply your own version of this class,
provided you meet certain minimum requirements.
Specifically, for an object hash_comp of type
hash_compare<Key, Pr>,
the following behavior is required by the above containers:
keyval of type Key,
the call hash_comp(keyval) serves as a
hash function,
which yields a distribution of values of type size_t.
The function supplied by hash_compare simply
returns keyval.keyval1 of
type Key that precedes keyval2 in the sequence
and has the same hash value (value returned by the hash function),
hash_comp(keyval2, keyval1) is false. The function must impose a
strict weak ordering
on values of type Key.
The function supplied by hash_compare returns
comp(keyval1, keyval2) where comp is a stored
object of type Tr that you can specify when you construct
the object hash_comp. For the default Pr parameter type
less<Key>,
sort keys never decrease in value.bucket_size
specifies the mean number of elements per ``bucket'' (hash-table
entry) that the container should endeavor not to exceed. It must
be greater than zero. The value supplied by
hash_compare is 4.min_buckets
specifies the minimum number of buckets to maintain in the hash table.
It must be a power of two and greater than zero. The value supplied by
hash_compare is 8.hash_mapallocator_type
· at
· begin
· bucket
· bucket_count
· bucket_size
· cbegin
· cend
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· const_reverse_iterator
· count
· crbegin
· crend
· difference_type
· emplace
· emplace_hint
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hash_map
· insert
· iterator
· key_comp
· key_compare
· key_type
· load_factor
· local_iterator
· lower_bound
· mapped_type
· max_bucket_count
· max_load_factor
· max_size
· operator=
· operator[]
· pointer
· rbegin
· reference
· rehash
· rend
· reverse_iterator
· size
· size_type
· swap
· upper_bound
· value_comp
· value_compare
· value_type
template<class Key, class Ty,
class Tr = hash_compare<Key, less<Key> >,
class Alloc = allocator<pair<const Key, Ty> > >
class hash_map {
public:
typedef Key key_type;
typedef Ty mapped_type;
typedef Tr key_compare;
typedef Alloc allocator_type;
typedef pair<const Key, Ty> value_type;
class value_compare;
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;
typedef reverse_iterator<const_iterator>
const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
hash_map();
explicit hash_map(const Tr& traits);
hash_map(const Tr& traits, const Alloc& al);
hash_map(const hash_map& right);
template<class InIt>
hash_map(InIt first, InIt last);
template<class InIt>
hash_map(InIt first, InIt last,
const Tr& traits);
template<class InIt>
hash_map(InIt first, InIt last,
const Tr& traits, const Alloc& al);
hash_map(initializer_list<Ty> init) [added with C++11]
hash_map(initializer_list<Ty> init,
const Pr& pred); [added with C++11]
hash_map(initializer_list<Ty> init,
const Pr& pred, const Alloc& al); [added with C++11]
hash_map(hash_map&& right); [added with C++11]
hash_map& operator=(const hash_map& right);
hash_map& operator=(initializer_list<Ty> init) [added with C++11]
hash_map& operator=(hash_map&& right); [added with C++11]
iterator begin();
const_iterator begin() const;
local_iterator begin(size_type nbucket);
const_local_iterator begin(size_type nbucket) const;
iterator end();
const_iterator end() const;
local_iterator end(size_type nbucket);
const_local_iterator end(size_type nbucket) const;
const_iterator cbegin() const; [added with C++11]
const_iterator cend() const; [added with C++11]
const_reverse_iterator crbegin() const; [added with C++11]
const_reverse_iterator crend() const; [added with C++11]
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
size_type size() const;
size_type max_size() const;
bool empty() const;
size_type bucket_count() const;
size_type max_bucket_count() const;
size_type bucket(const Key& keyval) const;
size_type bucket_size(size_type nbucket) const;
key_compare key_comp() const;
value_compare value_comp() const;
Alloc get_allocator() const;
float load_factor() const;
float max_load_factor() const;
void max_load_factor(float factor);
void rehash(size_type nbuckets);
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();
void swap(hash_map& right);
iterator find(const Key& keyval);
const_iterator find(const Key& keyval) const;
size_type count(const Key& keyval) const;
iterator lower_bound(const Key& keyval);
const_iterator lower_bound(const Key& keyval) const;
iterator upper_bound(const Key& keyval);
const_iterator upper_bound(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
ordered by the
hash traits object
Tr, which includes two functions:
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, and removing an element invalidates only those iterators which point at the removed element.
The object orders the sequence it controls by calling a stored
hash traits object of type Tr.
You access this stored object by calling the member function
key_comp().
Such a traits object must behave the same as an object of class
hash_compare<Key, Pr>.
Specifically, for all values keyval of type Key,
the call key_comp()(keyval) yields a distribution
of values of type size_t.
Moreover, class Tr imposes a
strict weak ordering
on sort keys of type Key.
For any element X that precedes
Y in the sequence and has the same hash value,
key_comp()(Y.first,
X.first) is false. (For the default function object
less<Key>,
sort keys never decrease in value.)
Unlike template class hash_multimap,
an object of template class hash_map does not ensure that
key_comp()(X.first, Y.first) is true.
(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 class Alloc. Such an allocator object must have
the same external interface as an object of template class
allocator.
Note that the stored allocator object is not copied when the container
object is assigned.
hash_map::allocator_typetypedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc.
hash_map::atconst 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.
hash_map::beginiterator begin();
const_iterator begin() const;
local_iterator begin(size_type nbucket);
const_local_iterator begin(size_type nbucket) const;
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).
hash_map::bucketsize_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval.
hash_map::bucket_countsize_type bucket_count() const;
The member function returns the current number of buckets.
hash_map::bucket_sizesize_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket.
hash_map::cbeginconst_iterator cbegin() const; [added with C++11]
The member functions return a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
hash_map::cendconst_reference cend() const; [added with C++11]
The member functions return a bidirectional iterator that points just beyond the end of the sequence.
hash_map::clearvoid clear();
The member function calls
erase(
begin(),
end()).
hash_map::const_iteratortypedef T1 const_iterator;
The type describes an object that can serve as a constant
bidirectional iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T1.
hash_map::const_local_iteratortypedef 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.
hash_map::const_pointertypedef 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.
hash_map::const_referencetypedef 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.
hash_map::const_reverse_iteratortypedef reverse_iterator<const_iterator>
const_reverse_iterator;
The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.
hash_map::countsize_type count(const Key& keyval) const;
The member function returns the number of elements in the range
[lower_bound(keyval),
upper_bound(keyval)).
hash_map::crbeginconst_reverse_iterator crbegin() const; [added with C++11]
The member functions return a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
hash_map::crendconst_reverse_iterator crend() const; [added with C++11]
The member functions return a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence)). Hence, it designates the end of the reverse sequence.
hash_map::difference_typetypedef 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.
hash_map::emplacetemplate<class... Valty>
pair<iterator, bool> emplace(Valty&&... val); [added with C++11]
The member function returns
insert(forward<pair<key, mapped_type> >(
pair<key, mapped_type>(val...)).
hash_map::emplace_hinttemplate<class... Valty>
iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]
The member function returns
insert(where, forward<pair<key, mapped_type> >(
pair<key, mapped_type>(val...)).
hash_map::emptybool empty() const;
The member function returns true for an empty controlled sequence.
hash_map::enditerator end();
const_iterator end() const;
local_iterator end(size_type nbucket);
const_local_iterator end(size_type nbucket) const;
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.
hash_map::equal_rangepair<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 ==
lower_bound(keyval)
and X.second ==
upper_bound(keyval).
hash_map::eraseiterator 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 with sort keys in the range
[lower_bound(keyval),
upper_bound(keyval)).
It returns the number of elements it removes.
The member functions never throw an exception.
hash_map::finditerator find(const Key& keyval); const_iterator find(const Key& keyval) const;
The member function returns
lower_bound(keyval).
hash_map::get_allocatorAlloc get_allocator() const;
The member function returns the stored allocator object.
hash_map::hash_maphash_map();
explicit hash_map(const Tr& traits);
hash_map(const Tr& traits, const Alloc& al);
hash_map(const hash_map& right);
template<class InIt>
hash_map(InIt first, InIt last);
template<class InIt>
hash_map(InIt first, InIt last,
const Tr& traits);
template<class InIt>
hash_map(InIt first, InIt last,
const Tr& traits, const Alloc& al);
hash_map(initializer_list<Ty> init) [added with C++11]
hash_map(initializer_list<Ty> init,
const Pr& pred); [added with C++11]
hash_map(initializer_list<Ty> init,
const Pr& pred, const Alloc& al); [added with C++11]
hash_map(hash_map&& right); [added with C++11]
All constructors store an
allocator object and
initialize the controlled sequence. The allocator object is the argument
al, if present. For the copy constructor, it is
right.get_allocator().
Otherwise, it is Alloc().
All constructors also store a
hash traits object that can later
be returned by calling
key_comp().
The hash traits object is the argument traits, if present.
For the copy constructor, it is
right.key_comp()).
Otherwise, it is Tr().
The first three constructors specify an
empty initial controlled sequence. The fourth constructor specifies
a copy of the sequence controlled by right.
The next three constructors specify the sequence of element values
[first, last).
The next three constructors specify the initial controlled sequence
with an object of class
initializer_list<Ty>.
The last constructor is the same as the fourth, but with an rvalue reference.
hash_map::insertpair<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.
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.
hash_map::iteratortypedef T0 iterator;
The type describes an object that can serve as a bidirectional
iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T0.
hash_map::key_compkey_compare key_comp() const;
The member function returns the stored hash traits object that determines the order of elements in the controlled sequence. In particular, the stored object defines the member function:
bool operator()(const Key& left, const Key& right);
which returns true if left strictly
precedes right in the sort order.
hash_map::key_comparetypedef Tr key_compare;
The type describes a traits object that behaves much like an object of class
hash_compare<Key, Pr>.
In particular, it can compare two
sort keys to determine the relative order of two
elements in the controlled sequence.
hash_map::key_typetypedef Key key_type;
The type describes the sort key object stored in each element of the controlled sequence.
hash_map::load_factorfloat load_factor() const;
The member function returns
(float)size() /
(float)bucket_count(),
the average number of elements per bucket.
hash_map::local_iteratortypedef 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.
hash_map::lower_bounditerator lower_bound(const Key& keyval); const_iterator lower_bound(const Key& keyval) const;
The member function returns an iterator that designates the
earliest element X in the controlled sequence for which
key_comp()(X.
first, keyval) is
false.
end().
hash_map::mapped_typetypedef Ty mapped_type;
The type is a synonym for the template parameter Ty.
hash_map::max_bucket_countsize_type max_bucket_count() const;
The member function returns the maximum number of buckets currently permitted.
hash_map::max_load_factorfloat max_load_factor() const; 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.
hash_map::max_sizesize_type max_size() const;
The member function returns the length of the longest sequence that the object can control.
hash_map::operator=hash_map& operator=(const hash_map& right); hash_map& operator=(initializer_list<Ty> init) [added with C++11] hash_map& operator=(hash_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.
hash_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.
hash_map::pointertypedef typename Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an element of the controlled sequence.
hash_map::rbeginconst_reverse_iterator rbegin() const; reverse_iterator rbegin();
The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
hash_map::referencetypedef typename Alloc::reference reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
hash_map::rehashvoid rehash(size_type nbuckets);
The member function alters the number of buckets to be at least nbuckets
and rebuilds the hash table as needed.
hash_map::rendconst_reverse_iterator rend() const; reverse_iterator rend();
The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.
hash_map::reverse_iteratortypedef reverse_iterator<iterator> reverse_iterator;
The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.
hash_map::sizesize_type size() const;
The member function returns the length of the controlled sequence.
hash_map::size_typetypedef typename Alloc::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
hash_map::swapvoid swap(hash_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.
hash_map::upper_bounditerator upper_bound(const Key& keyval); const_iterator upper_bound(const Key& keyval) const;
The member function returns an iterator
just beyond the iterator that designates the
latest element X in the controlled sequence
for which X.first has
equivalent ordering
to keyval.
If no such element exists, the function returns
end().
hash_map::value_compvalue_compare value_comp() const;
The member function returns a function object that determines the order of elements in the controlled sequence.
hash_map::value_compareclass value_compare
: public binary_function<value_type, value_type,
bool> {
public:
bool operator()(const value_type& left,
const value_type& right) const
{return (comp(left.first, right.first)); }
protected:
value_compare(key_compare pr)
: comp(pr) {}
key_compare comp;
};
The type describes a function object that can compare the
sort keys in two elements to determine their relative order
in the controlled sequence. The function object stores an object
comp
of type key_type.
The member function operator() uses this
object to compare the sort-key components of two element.
hash_map::value_typetypedef pair<const Key, Ty> value_type;
The type describes an element of the controlled sequence.
hash_multimapallocator_type
· begin
· bucket
· bucket_count
· bucket_size
· cbegin
· cend
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· const_reverse_iterator
· count
· crbegin
· crend
· difference_type
· emplace
· emplace_hint
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hash_multimap
· insert
· iterator
· key_comp
· key_compare
· key_type
· load_factor
· local_iterator
· lower_bound
· mapped_type
· max_bucket_count
· max_load_factor
· max_size
· operator=
· pointer
· rbegin
· reference
· rehash
· rend
· reverse_iterator
· size
· size_type
· swap
· upper_bound
· value_comp
· value_compare
· value_type
template<class Key, class Ty,
class Tr = hash_compare<Key, less<Key> >,
class Alloc = allocator<pair<const Key, Ty> > >
class hash_multimap {
public:
typedef Key key_type;
typedef Ty mapped_type;
typedef Tr key_compare;
typedef Alloc allocator_type;
typedef pair<const Key, Ty> value_type;
class value_compare;
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 difference_type difference_type;
typedef T0 iterator;
typedef T1 const_iterator;
typedef T2 local_iterator;
typedef T3 const_local_iterator;
typedef reverse_iterator<const_iterator>
const_reverse_iterator;
typedef reverse_iterator<iterator> reverse_iterator;
hash_multimap();
explicit hash_multimap(const Tr& traits);
hash_multimap(const Tr& traits, const Alloc& al);
hash_multimap(const hash_multimap& right);
template<class InIt>
hash_multimap(InIt first, InIt last);
template<class InIt>
hash_multimap(InIt first, InIt last,
const Tr& traits);
template<class InIt>
hash_multimap(InIt first, InIt last,
const Tr& traits, const Alloc& al);
hash_multimap(initializer_list<Ty> init) [added with C++11]
hash_multimap(initializer_list<Ty> init,
const Pr& pred); [added with C++11]
hash_multimap(initializer_list<Ty> init,
const Pr& pred, const Alloc& al); [added with C++11]
hash_multimap(hash_multimap&& right); [added with C++11]
hash_multimap& operator=(const hash_multimap& right);
hash_multimap& operator=(initializer_list<Ty> init) [added with C++11]
hash_multimap& operator=(hash_multimap&& right); [added with C++11]
iterator begin();
const_iterator begin() const;
local_iterator begin(size_type nbucket);
const_local_iterator begin(size_type nbucket) const;
iterator end();
const_iterator end() const;
local_iterator end(size_type nbucket);
const_local_iterator end(size_type nbucket) const;
const_iterator cbegin() const; [added with C++11]
const_iterator cend() const; [added with C++11]
const_reverse_iterator crbegin() const; [added with C++11]
const_reverse_iterator crend() const; [added with C++11]
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
size_type size() const;
size_type max_size() const;
bool empty() const;
size_type bucket_count() const;
size_type max_bucket_count() const;
size_type bucket(const Key& keyval) const;
size_type bucket_size(size_type nbucket) const;
key_compare key_comp() const;
value_compare value_comp() const;
Alloc get_allocator() const;
float load_factor() const;
float max_load_factor() const;
void max_load_factor(float factor);
void rehash(size_type nbuckets);
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();
void swap(hash_multimap& right);
iterator find(const Key& keyval);
const_iterator find(const Key& keyval) const;
size_type count(const Key& keyval) const;
iterator lower_bound(const Key& keyval);
const_iterator lower_bound(const Key& keyval) const;
iterator upper_bound(const Key& keyval);
const_iterator upper_bound(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
ordered by the
hash traits object
Tr, which includes two functions:
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, and removing an element invalidates only those iterators which point at the removed element.
The object orders the sequence it controls by calling a stored
hash traits object of type Tr.
You access this stored object by calling the member function
key_comp().
Such a traits object must behave the same as an object of class
hash_compare<Key, Pr>.
Specifically, for all values keyval of type Key,
the call key_comp()(keyval) yields a distribution
of values of type size_t.
Moreover, class Tr imposes a
strict weak ordering
on sort keys of type Key.
For any element X that precedes
Y in the sequence and has the same hash value,
key_comp()(Y.first,
X.first) is false. (For the default function object
less<Key>,
sort keys never decrease in value.)
Unlike template class hash_map,
an object of template class hash_multimap does not ensure that
key_comp()(X.first, Y.first) is true.
(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 class Alloc. Such an allocator object must have
the same external interface as an object of template class
allocator.
Note that the stored allocator object is not copied when the container
object is assigned.
Inserting and erasing elements, and rehashing, preserves the order of elements with equivalent ordering.
hash_multimap::allocator_typetypedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc.
hash_multimap::beginiterator begin();
const_iterator begin() const;
local_iterator begin(size_type nbucket);
const_local_iterator begin(size_type nbucket) const;
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).
hash_multimap::bucketsize_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval.
hash_multimap::bucket_countsize_type bucket_count() const;
The member function returns the current number of buckets.
hash_multimap::bucket_sizesize_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket.
hash_multimap::cbeginconst_iterator cbegin() const; [added with C++11]
The member functions return a bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
hash_multimap::cendconst_reference cend() const; [added with C++11]
The member functions return a bidirectional iterator that points just beyond the end of the sequence.
hash_multimap::clearvoid clear();
The member function calls
erase(
begin(),
end()).
hash_multimap::const_iteratortypedef T1 const_iterator;
The type describes an object that can serve as a constant
bidirectional iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T1.
hash_multimap::const_local_iteratortypedef 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.
hash_multimap::const_pointertypedef 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.
hash_multimap::const_referencetypedef 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.
hash_multimap::const_reverse_iteratortypedef reverse_iterator<const_iterator>
const_reverse_iterator;
The type describes an object that can serve as a constant reverse bidirectional iterator for the controlled sequence.
hash_multimap::countsize_type count(const Key& keyval) const;
The member function returns the number of elements in the range
[lower_bound(keyval),
upper_bound(keyval)).
hash_multimap::crbeginconst_reverse_iterator crbegin() const; [added with C++11]
The member functions return a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
hash_multimap::crendconst_reverse_iterator crend() const; [added with C++11]
The member functions return a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence)). Hence, it designates the end of the reverse sequence.
hash_multimap::difference_typetypedef 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.
hash_multimap::emplacetemplate<class... Valty>
pair<iterator, bool> emplace(Valty&&... val); [added with C++11]
The member function returns
insert(forward<pair<key, mapped_type> >(
pair<key, mapped_type>(val...)).
hash_multimap::emplace_hinttemplate<class... Valty>
iterator emplace_hint(const_iterator where, Valty&&... val); [added with C++11]
The member function returns
insert(where, forward<pair<key, mapped_type> >(
pair<key, mapped_type>(val...)).
hash_multimap::emptybool empty() const;
The member function returns true for an empty controlled sequence.
hash_multimap::enditerator end();
const_iterator end() const;
local_iterator end(size_type nbucket);
const_local_iterator end(size_type nbucket) const;
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.
hash_multimap::equal_rangepair<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 ==
lower_bound(keyval)
and X.second ==
upper_bound(keyval).
hash_multimap::eraseiterator 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 with sort keys in the range
[lower_bound(keyval),
upper_bound(keyval)).
It returns the number of elements it removes.
The member functions never throw an exception.
hash_multimap::finditerator find(const Key& keyval); const_iterator find(const Key& keyval) const;
The member function returns
lower_bound(keyval).
hash_multimap::get_allocatorAlloc get_allocator() const;
The member function returns the stored allocator object.
hash_multimap::hash_multimaphash_multimap();
explicit hash_multimap(const Tr& traits);
hash_multimap(const Tr& traits, const Alloc& al);
hash_multimap(const hash_multimap& right);
template<class InIt>
hash_multimap(InIt first, InIt last);
template<class InIt>
hash_multimap(InIt first, InIt last,
const Tr& traits);
template<class InIt>
hash_multimap(InIt first, InIt last,
const Tr& traits, const Alloc& al);
hash_multimap(initializer_list<Ty> init) [added with C++11]
hash_multimap(initializer_list<Ty> init,
const Pr& pred); [added with C++11]
hash_multimap(initializer_list<Ty> init,
const Pr& pred, const Alloc& al); [added with C++11]
hash_multimap(hash_multimap&& right); [added with C++11]
All constructors store an
allocator object and
initialize the controlled sequence. The allocator object is the argument
al, if present. For the copy constructor, it is
right.get_allocator().
Otherwise, it is Alloc().
All constructors also store a
hash traits object that can later
be returned by calling
key_comp().
The hash traits object is the argument traits, if present.
For the copy constructor, it is
right.key_comp()).
Otherwise, it is Tr().
The first three constructors specify an
empty initial controlled sequence. The fourth constructor specifies
a copy of the sequence controlled by right.
The next three constructors specify the sequence of element values
[first, last).
The next three constructors specify the initial controlled sequence
with an object of class
initializer_list<Ty>.
The last constructor is the same as the fourth, but with an rvalue reference.
hash_multimap::insertiterator 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.
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.
hash_multimap::iteratortypedef T0 iterator;
The type describes an object that can serve as a bidirectional
iterator for the controlled sequence.
It is described here as a
synonym for the implementation-defined type T0.
hash_multimap::key_compkey_compare key_comp() const;
The member function returns the stored hash traits object that determines the order of elements in the controlled sequence. In particular, the stored object defines the member function:
bool operator()(const Key& left, const Key& right);
which returns true if left strictly
precedes right in the sort order.
hash_multimap::key_comparetypedef Tr key_compare;
The type describes a traits object that behaves much like an object of class
hash_compare<Key, Pr>.
In particular, it can compare two
sort keys to determine the relative order of two
elements in the controlled sequence.
hash_multimap::key_typetypedef Key key_type;
The type describes the sort key object stored in each element of the controlled sequence.
hash_multimap::load_factorfloat load_factor() const;
The member function returns
(float)size() /
(float)bucket_count(),
the average number of elements per bucket.
hash_multimap::local_iteratortypedef 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.
hash_multimap::lower_bounditerator lower_bound(const Key& keyval); const_iterator lower_bound(const Key& keyval) const;
The member function returns an iterator that designates the
earliest element X in the controlled sequence for which
key_comp()(X.
first, keyval) is
false.
end().
hash_multimap::mapped_typetypedef Ty mapped_type;
The type is a synonym for the template parameter Ty.
hash_multimap::max_bucket_countsize_type max_bucket_count() const;
The member function returns the maximum number of buckets currently permitted.
hash_multimap::max_load_factorfloat max_load_factor() const; 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.
hash_multimap::max_sizesize_type max_size() const;
The member function returns the length of the longest sequence that the object can control.
hash_multimap::operator=hash_multimap& operator=(const hash_multimap& right); hash_multimap& operator=(initializer_list<Ty> init) [added with C++11] hash_multimap& operator=(hash_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.
hash_multimap::pointertypedef typename Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an element of the controlled sequence.
hash_multimap::rbeginconst_reverse_iterator rbegin() const; reverse_iterator rbegin();
The member function returns a reverse bidirectional iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
hash_multimap::referencetypedef typename Alloc::reference reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
hash_multimap::rehashvoid rehash(size_type nbuckets);
The member function alters the number of buckets to be at least nbuckets
and rebuilds the hash table as needed.
hash_multimap::rendconst_reverse_iterator rend() const; reverse_iterator rend();
The member function returns a reverse bidirectional iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence.
hash_multimap::reverse_iteratortypedef reverse_iterator<iterator> reverse_iterator;
The type describes an object that can serve as a reverse bidirectional iterator for the controlled sequence.
hash_multimap::sizesize_type size() const;
The member function returns the length of the controlled sequence.
hash_multimap::size_typetypedef typename Alloc::size_type size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence.
hash_multimap::swapvoid swap(hash_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.
hash_multimap::upper_bounditerator upper_bound(const Key& keyval); const_iterator upper_bound(const Key& keyval) const;
The member function returns an iterator
just beyond the iterator that designates the
latest element X in the controlled sequence
for which X.first has
equivalent ordering
to keyval.
If no such element exists, the function returns
end().
hash_multimap::value_compvalue_compare value_comp() const;
The member function returns a function object that determines the order of elements in the controlled sequence.
hash_multimap::value_compareclass value_compare
: public binary_function<value_type, value_type,
bool> {
public:
bool operator()(const value_type& left,
const value_type& right) const
{return (comp(left.first, right.first)); }
protected:
value_compare(key_compare pr)
: comp(pr) {}
key_compare comp;
};
The type describes a function object that can compare the
sort keys in two elements to determine their relative order
in the controlled sequence. The function object stores an object
comp
of type key_type.
The member function operator() uses this
object to compare the sort-key components of two element.
hash_multimap::value_typetypedef pair<const Key, Ty> value_type;
The type describes an element of the controlled sequence.
operator!=template<class Key, class Ty, class Tr, class Alloc>
bool operator!=(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator!=(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The template function returns !(left == right).
operator==template<class Key, class Ty, class Tr, class Alloc>
bool operator==(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator==(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The first template function overloads operator==
to compare two objects of template class
hash_map.
The second template function overloads operator==
to compare two objects of template class
hash_multimap.
Both functions return
left.size() == right.size() &&
equal(left.
begin(), left.
end(), right.begin()).
operator<template<class Key, class Ty, class Tr, class Alloc>
bool operator<(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The first template function overloads operator<
to compare two objects of template class
hash_map.
The second template function overloads operator<
to compare two objects of template class
hash_multimap.
Both functions return
lexicographical_compare(left.
begin(), left.
end(), right.begin(), right.end(),
left.value_comp()).
operator<=template<class Key, class Ty, class Tr, class Alloc>
bool operator<=(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator<=(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The template function returns !(right < left).
operator>template<class Key, class Ty, class Tr, class Alloc>
bool operator>(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator>(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The template function returns right < left.
operator>=template<class Key, class Ty, class Tr, class Alloc>
bool operator>=(
const hash_map <Key, Ty, Tr, Alloc>& left,
const hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
bool operator!=(
const hash_multimap <Key, Ty, Tr, Alloc>& left,
const hash_multimap <Key, Ty, Tr, Alloc>& right);
The template function returns !(left < right).
swaptemplate<class Key, class Ty, class Tr, class Alloc>
void swap(
hash_map <Key, Ty, Tr, Alloc>& left,
hash_map <Key, Ty, Tr, Alloc>& right);
template<class Key, class Ty, class Tr, class Alloc>
void swap(
hash_multimap <Key, Ty, Tr, Alloc>& left,
hash_multimap <Key, Ty, Tr, Alloc>& right);
The template function executes
left.swap(right).
See also the Table of Contents and the Index.
Copyright © 1992-2013 by P.J. Plauger. All rights reserved.