<unordered_set>
[added with
TR1]
Include the STL
standard header <unordered_set> to define the
container
template classes unordered_set and
unordered_multiset, and their supporting
templates.
namespace std {
namespace tr1 {
// DECLARATIONS
template<class Key, class Hash, class Pred, class Alloc>
class unordered_set;
template<class Key, class Hash, class Pred, class Alloc>
class unordered_multiset;
// TEMPLATE FUNCTIONS
template<class Key, class Hash, class Pred, class Alloc>
void swap(
unordered_set<Key, Hash, Pred, Alloc>& left,
unordered_set<Key, Hash, Pred, Alloc>& right);
template<class Key, class Hash, class Pred, class Alloc>
void swap(
unordered_multiset<Key, Hash, Pred, Alloc>& left,
unordered_multiset<Key, Hash, Pred, Alloc>& right);
} // namespace tr1
} // namespace std
allocator_type
· begin
· bucket
· bucket_count
· bucket_size
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· count
· difference_type
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hasher
· hash_function
· insert
· iterator
· key_eq
· key_equal
· key_type
· load_factor
· local_iterator
· max_bucket_count
· max_load_factor
· max_size
· pointer
· reference
· rehash
· size
· size_type
· swap
· unordered_multiset
· value_type
template<class Key,
class Hash = std::tr1::hash<Key>,
class Pred = std::equal_to<Key>,
class Alloc = std::allocator<Key> >
class unordered_multiset {
public:
typedef Key key_type;
typedef Key value_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef Alloc::pointer pointer;
typedef Alloc::const_pointer const_pointer;
typedef Alloc::reference reference;
typedef Alloc::const_reference const_reference;
typedef T0 iterator;
typedef T1 const_iterator;
typedef T2 size_type;
typedef T3 difference_type;
typedef T4 local_iterator;
typedef T5 const_local_iterator;
unordered_multiset(
const unordered_multiset& right);
explicit unordered_multiset(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_multiset(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
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;
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;
Hash hash_function() const;
Pred key_eq() 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(iterator where, const value_type& val);
template<class InIt>
void insert(InIt first, InIt last);
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
size_type erase(const Key& keyval);
void clear();
void swap(unordered_multiset& right);
const_iterator find(const Key& keyval) const;
size_type count(const std::pair<iterator, iterator>
equal_range(const Key& keyval);
std::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 const Key.
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 serves as both 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 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_set,
an object of template class unordered_multiset 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.
Note that the stored allocator object is not copied when the container
object is assigned.
typedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc.
iterator 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).
size_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval.
size_type bucket_count() const;
The member function returns the current number of buckets.
size_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket.
void clear();
The member function calls
erase(
begin(),
end()).
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.
typedef T5 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 T5.
typedef Alloc::const_pointer const_pointer;
The type describes an object that can serve as a constant pointer
to an element of the controlled sequence.
typedef Alloc::const_reference const_reference;
The type describes an object that can serve as a constant reference
to an element of the controlled sequence.
size_type count(const Key& keyval) const;
The member function returns the number of elements in the range delimited by
equal_range(keyval).
typedef T3 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. It is described here as a
synonym for the implementation-defined type T3.
bool empty() const;
The member function returns true for an empty controlled sequence.
iterator 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.
std::pair<iterator, iterator>
equal_range(const Key& keyval);
std::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().
iterator erase(iterator where);
iterator erase(iterator first, 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.
const_iterator find(const Key& keyval) const;
The member function returns
equal_range(keyval).first.
Alloc get_allocator() const;
The member function returns the stored
allocator object.
Hash hash_function() const;
The member function returns the stored hash function object.
typedef Hash hasher;
The type is a synonym for the template parameter Hash.
iterator insert(const value_type& val);
iterator insert(iterator where, const value_type& val);
template<class InIt>
void insert(InIt first, InIt last);
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).
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.
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.
Pred key_eq() const;
The member function returns the stored comparison function object.
typedef Pred key_equal;
The type is a synonym for the template parameter Pred.
typedef Key key_type;
The type is a synonym for the template parameter Key.
float load_factor() const;
The member function returns
(float)size() /
(float)bucket_count(),
the average number of elements per bucket.
typedef T4 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 T4.
size_type max_bucket_count() const;
The member function returns the maximum number of buckets currently permitted.
float 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.
size_type max_size() const;
The member function returns the length of the longest sequence that
the object can control.
typedef Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an
element of the controlled sequence.
typedef Alloc::reference reference;
The type describes an object that can serve as a reference to an
element of the controlled sequence.
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.
size_type size() const;
The member function returns the length of the controlled sequence.
typedef T2 size_type;
The unsigned integer type describes an object that can represent the
length of any controlled sequence. It is described here as a
synonym for the implementation-defined type T2.
void swap(unordered_multiset& 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_multiset(
const unordered_multiset& right);
explicit unordered_multiset(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_multiset(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
The first constructor specifies
a copy of the sequence controlled by right.
The second constructor specifies an empty controlled sequence.
The third constructor inserts the sequence of element values
[first, last).
All constructors also initialize several stored values.
For the copy constructor, the values are obtained from right.
Otherwise:
- the minimum number of buckets is the argument
nbuckets, if present;
otherwise it is a default value described here as the implementation-defined
value N0.
- the hash function object is the argument
hfn, if present;
otherwise it is Hash().
- the comparison function object is the argument
comp, if present;
otherwise it is Pred().
- the allocator object is the argument
al, if present;
otherwise, it is Alloc().
typedef Key value_type;
The type describes an element of the controlled sequence.
allocator_type
· begin
· bucket
· bucket_count
· bucket_size
· clear
· const_iterator
· const_local_iterator
· const_pointer
· const_reference
· count
· difference_type
· empty
· end
· equal_range
· erase
· find
· get_allocator
· hasher
· hash_function
· insert
· iterator
· key_eq
· key_equal
· key_type
· load_factor
· local_iterator
· max_bucket_count
· max_load_factor
· max_size
· pointer
· reference
· rehash
· size
· size_type
· swap
· unordered_set
· value_type
template<class Key,
class Hash = std::tr1::hash<Key>,
class Pred = std::equal_to<Key>,
class Alloc = std::allocator<Key> >
class unordered_set {
public:
typedef Key key_type;
typedef Key value_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef Alloc::pointer pointer;
typedef Alloc::const_pointer const_pointer;
typedef Alloc::reference reference;
typedef Alloc::const_reference const_reference;
typedef T0 iterator;
typedef T1 const_iterator;
typedef T2 size_type;
typedef T3 difference_type;
typedef T4 local_iterator;
typedef T5 const_local_iterator;
unordered_set(
const unordered_set& right);
explicit unordered_set(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_set(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
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;
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;
Hash hash_function() const;
Pred key_eq() 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(iterator where, const value_type& val);
template<class InIt>
void insert(InIt first, InIt last);
iterator erase(iterator where);
iterator erase(iterator first, iterator last);
size_type erase(const Key& keyval);
void clear();
void swap(unordered_set& right);
const_iterator find(const Key& keyval) const;
size_type count(const Key& keyval) const;
std::pair<iterator, iterator>
equal_range(const Key& keyval);
std::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 const Key.
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 serves as both 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 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_multiset,
an object of template class unordered_set 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.
Note that the stored allocator object is not copied when the container
object is assigned.
typedef Alloc allocator_type;
The type is a synonym for the template parameter Alloc.
iterator 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).
size_type bucket(const Key& keyval) const;
The member function returns the bucket number currently corresponding
to the key value keyval.
size_type bucket_count() const;
The member function returns the current number of buckets.
size_type bucket_size(size_type nbucket) const;
The member functions returns the size of bucket number nbucket.
void clear();
The member function calls
erase(
begin(),
end()).
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.
typedef T5 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 T5.
typedef Alloc::const_pointer const_pointer;
The type describes an object that can serve as a constant pointer
to an element of the controlled sequence.
typedef Alloc::const_reference const_reference;
The type describes an object that can serve as a constant reference
to an element of the controlled sequence.
size_type count(const Key& keyval) const;
The member function returns the number of elements in the range delimited by
equal_range(keyval).
typedef T3 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. It is described here as a
synonym for the implementation-defined type T3.
bool empty() const;
The member function returns true for an empty controlled sequence.
iterator 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.
std::pair<iterator, iterator>
equal_range(const Key& keyval);
std::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().
iterator erase(iterator where);
iterator erase(iterator first, 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.
const_iterator find(const Key& keyval) const;
The member function returns
equal_range(keyval).first.
Alloc get_allocator() const;
The member function returns the stored
allocator object.
Hash hash_function() const;
The member function returns the stored hash function object.
typedef Hash hasher;
The type is a synonym for the template parameter Hash.
iterator insert(const value_type& val);
iterator insert(iterator where, const value_type& val);
template<class InIt>
void insert(InIt first, InIt last);
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).
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.
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.
Pred key_eq() const;
The member function returns the stored comparison function object.
typedef Pred key_equal;
The type is a synonym for the template parameter Pred.
typedef Key key_type;
The type is a synonym for the template parameter Key.
float load_factor() const;
The member function returns
(float)size() /
(float)bucket_count(),
the average number of elements per bucket.
typedef T4 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 T4.
size_type max_bucket_count() const;
The member function returns the maximum number of buckets currently permitted.
float 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.
size_type max_size() const;
The member function returns the length of the longest sequence that
the object can control.
typedef Alloc::pointer pointer;
The type describes an object that can serve as a pointer to an
element of the controlled sequence.
typedef Alloc::reference reference;
The type describes an object that can serve as a reference to an
element of the controlled sequence.
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.
size_type size() const;
The member function returns the length of the controlled sequence.
typedef T2 size_type;
The unsigned integer type describes an object that can represent the
length of any controlled sequence. It is described here as a
synonym for the implementation-defined type T2.
void swap(unordered_set& 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_set(
const unordered_set& right);
explicit unordered_set(
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
template<class InIt>
unordered_set(
InIt first, InIt last,
size_type nbuckets = N0,
const Hash& hfn = Hash(),
const Pred& comp = Pred(),
const Alloc& al = Alloc());
The first constructor specifies
a copy of the sequence controlled by right.
The second constructor specifies an empty controlled sequence.
The third constructor inserts the sequence of element values
[first, last).
All constructors also initialize several stored values.
For the copy constructor, the values are obtained from right.
Otherwise:
- the minimum number of buckets is the argument
nbuckets, if present;
otherwise it is a default value described here as the implementation-defined
value N0.
- the hash function object is the argument
hfn, if present;
otherwise it is Hash().
- the comparison function object is the argument
comp, if present;
otherwise it is Pred().
- the allocator object is the argument
al, if present;
otherwise, it is Alloc().
typedef Key value_type;
The type describes an element of the controlled sequence.
template<class Key, class Hash, class Pred, class Alloc>
void swap(
unordered_multiset <Key, Hash, Pred, Alloc>& left,
unordered_multiset <Key, Hash, Pred, Alloc>& right);
template<class Key, class Hash, class Pred, class Alloc>
void swap(
unordered_set <Key, Hash, Pred, Alloc>& left,
unordered_set <Key, Hash, Pred, Alloc>& right);
The template function executes
left.swap(right).
See also the
Table of Contents and the
Index.
Copyright © 1992-2006
by P.J. Plauger. All rights reserved.