namespace boost { namespace bimaps { template < class KeyType, class HashFunctor = hash< KeyType >, class EqualKey = std::equal_to< KeyType > > struct unordered_set_of; template < class HashFunctor = hash< _relation >, class EqualKey = std::equal_to< _relation > > struct unordered_set_of_relation; } // namespace bimap } // namespace boost
namespace boost { namespace bimaps { template < class KeyType, class HashFunctor = hash< KeyType >, class EqualKey = std::equal_to< KeyType > > struct unordered_multiset_of; template < class HashFunctor = hash< _relation >, class EqualKey = std::equal_to< _relation > > struct unordered_multiset_of_relation; } // namespace bimap } // namespace boost
These collection types specifiers allow for set views without and with
allowance of duplicate elements, respectively. The syntax of set_of and multiset_of
coincide, thus we describe them in a grouped manner.
An unordered_[multi]set_of set view is a tr1::unordered[multi]set signature
compatible interface to the underlying heap of elements contained in a
bimap.
The interface and semantics of unordered_[multi]set_of
views are modeled according to the proposal for unordered associative containers
given in the C++
Standard Library Technical Report, also known as TR1. An unordered_[multi]set_of view is particularized according
to a given Hash function
object which returns hash values for the keys and a binary predicate Pred acting as an equivalence relation
on values of Key.
There are two variants: unordered_set_of, which do not allow duplicate elements (with respect to its associated comparison predicate) and unordered_multiset_of, which accept those duplicates. The interface of these two variants is the same to a great extent, so they are documented together with their differences explicitly noted when they exist.
If you look the bimap by a side, you will use a map view and if you looked it as a whole you will be using a set view.
Except where noted, unordered_[multi]set_of
views (both unique and non-unique) are models of Unordered Associative
Container. Validity of iterators and references to elements is
preserved in all cases. Occasionally, the exception safety guarantees provided
are actually stronger than required by the extension draft. We only provide
descriptions of those types and operations that are either not present
in the concepts modeled or do not exactly conform to the requirements for
unordered associative containers.
namespace boost { namespace bimap { namespace views { template< -implementation defined parameter list- > class -implementation defined view name- { public: // types typedef -unspecified- key_type; typedef -unspecified- value_type; typedef -unspecified- key_compare; typedef -unspecified- value_compare; typedef -unspecified- hasher; typedef -unspecified- key_equal; typedef -unspecified- allocator_type; typedef -unspecified- reference; typedef -unspecified- const_reference; typedef -unspecified- iterator; typedef -unspecified- const_iterator; typedef -unspecified- size_type; typedef -unspecified- difference_type; typedef -unspecified- pointer; typedef -unspecified- const_pointer; typedef -unspecified- local_iterator; typedef -unspecified- const_local_iterator; typedef -unspecified- info_type; // construct/destroy/copy: this_type & operator=(const this_type & x); allocator_type get_allocator() const; // size and capacity bool empty() const; size_type size() const; size_type max_size() const; // iterators iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; // modifiers std::pair< iterator, bool > insert(const value_type & x); iterator insert(iterator position, const value_type & x); template< class InputIterator > void insert(InputIterator first, InputIterator last); iterator erase(iterator position); template< class CompatibleKey > size_type erase(const CompatibleKey & x); iterator erase(iterator first, iterator last); bool replace(iterator position, const value_type & x); // Only in map views // { template< class CompatibleKey > bool replace_key(iterator position, const CompatibleKey & x); template< class CompatibleData > bool replace_data(iterator position, const CompatibleData & x); template< class KeyModifier > bool modify_key(iterator position, KeyModifier mod); template< class DataModifier > bool modify_data(iterator position, DataModifier mod); // } void clear(); // observers key_from_value key_extractor() const; hasher hash_function() const; key_equal key_eq() const; // lookup template< class CompatibleKey > iterator find(const CompatibleKey & x); template< class CompatibleKey > const_iterator find(const CompatibleKey & x) const; template< class CompatibleKey > size_type count(const CompatibleKey & x) const; template< class CompatibleKey > std::pair<iterator,iterator> equal_range(const CompatibleKey & x); template< class CompatibleKey > std::pair<const_iterator,const_iterator> equal_range(const CompatibleKey & x) const; // bucket interface size_type bucket_count() const; size_type max_bucket_count() const; size_type bucket_size(size_type n) const; size_type bucket(const key_type & k) const; local_iterator begin(size_type n); const_local_iterator begin(size_type n) const; local_iterator end(size_type n); const_local_iterator end(size_type n) const; // hash policy float load_factor() const; float max_load_factor() const; void max_load_factor(float z); void rehash(size_type n); // Only in maps views // { typedef -unspecified- data_type; // Only in for `unordered_set_of` collection type // { template<class CompatibleKey> const data_type & at(const CompatibleKey & k) const; // Only if the other collection type is mutable // { template<class CompatibleKey> data_type & operator[](const CompatibleKey & k); template<class CompatibleKey> data_type & at(const CompatibleKey & k); // } // Only if info_hook is used // { template< class CompatibleKey > info_type & info_at(const CompatibleKey & k); template< class CompatibleKey > const info_type & info_at(const CompatibleKey & k) const; // } // } }; } // namespace views } // namespace bimap } // namespace boost
In the case of a bimap< unordered_{multi}set_of<Left>, ... >
In the set view:
typedef signature-compatible with relation< Left, ... > key_type; typedef signature-compatible with relation< const Left, ... > value_type;
In the left map view:
typedef Left key_type; typedef ... data_type; typedef signature-compatible with std::pair< const Left, ... > value_type;
In the right map view:
typedef ... key_type; typedef Left data_type; typedef signature-compatible with std::pair< ... ,const Left > value_type;
Here and in the descriptions of operations of unordered_[multi]set_of
views, we adopt the scheme outlined in the complexity
signature section. The complexity signature of unordered_[multi]set_of
view is:
-
copying:
c(n) = n * log(n), -
insertion: average case
i(n) = 1(constant), worst casei(n) = n, -
hinted insertion: average case
h(n) = 1(constant), worst caseh(n) = n, -
deletion: average case
d(n) = 1(constant), worst cased(n) = n, -
replacement:
-
if the new element key is equivalent to the original,
r(n) = 1(constant), -
otherwise, average case
r(n) = 1(constant), worst caser(n) = n,
-
if the new element key is equivalent to the original,
-
modifying: average case
m(n) = 1(constant), worst casem(n) = n.
unordered_[multi]set_of views are instantiated internally
to bimap specified by
means of the collection type specifiers and the bimap
itself. Instantiations are dependent on the following types:
-
Valuefrombimap, -
Allocatorfrombimap, -
Hashfrom the collection type specifier, -
Predfrom the collection type specifier.
Hash is a Unary
Function taking a single argument of type key_type
and returning a value of type std::size_t
in the range [0, std::numeric_limits<std::size_t>::max()). Pred is a Binary
Predicate inducing an equivalence relation on elements of key_type. It is required that the
Hash object return the
same value for keys equivalent under Pred.
iterator const_iterator local_iterator const_local_iterator
These types are models of Forward Iterator.
As explained in the concepts section, views do not have public constructors
or destructors. Assignment, on the other hand, is provided. Upon construction,
max_load_factor()
is 1.0.
this_type & operator=(const this_type & x);
-
Effects:
a = b; where a and b are thebimapobjects to which*thisand x belong, respectively. -
Returns:
*this.
std::pair<iterator,bool> insert(const value_type & x);
-
Effects: Inserts
xinto thebimapto which the view belongs if- the view is non-unique OR no other element with equivalent key exists,
-
AND insertion is allowed by all other views of the
bimap.
-
Returns: The return value is a pair
p.p.secondistrueif and only if insertion took place. On successful insertion,p.firstpoints to the element inserted; otherwise,p.firstpoints to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed. - Complexity: O(I(n)).
- Exception safety: Strong.
iterator insert(iterator position, const value_type & x);
-
Requires:
positionis a valid iterator of the view. -
Effects:
positionis used as a hint to improve the efficiency of the operation. Insertsxinto thebimapto which the view belongs if- the view is non-unique OR no other element with equivalent key exists,
-
AND insertion is allowed by all other views of the
bimap.
- Returns: On successful insertion, an iterator to the newly inserted element. Otherwise, an iterator to an element that caused the insertion to be banned. Note that more than one element can be causing insertion not to be allowed.
- Complexity: O(H(n)).
- Exception safety: Strong.
template< class InputIterator> void insert(InputIterator first, InputIterator last);
-
Requires:
InputIteratoris a model of Input Iterator over elements of typevalue_type.firstandlastare not iterators into any views of thebimapto which this view belongs.lastis reachable from first. -
Effects:
iterator hint = end();while(first != last) hint = insert(hint, *first++); -
Complexity:
O(m*H(n+m)), where m is the number of elements in
[first, last). - Exception safety: Basic.
iterator erase(iterator position);
-
Requires:
positionis a valid dereferenceableiteratorof the view. -
Effects: Deletes the element pointed
to by
position. -
Returns: An
iteratorpointing to the element immediately following the one that was deleted, orend()if no such element exists. - Complexity: O(D(n)).
- Exception safety: nothrow.
template< class CompatibleKey > size_type erase(const CompatibleKey & x);
-
Effects: Deletes the elements with
key equivalent to
x. - Returns: Number of elements deleted.
- Complexity: Average case, O(1 + m*D(n)), worst case O(n + m*D(n)), where m is the number of elements deleted.
- Exception safety: Basic.
iterator erase(iterator first, iterator last);
-
Requires:
[first,last)is a valid range of the view. -
Effects: Deletes the elements in
[first,last). -
Returns:
last. -
Complexity:
O(m*D(n)), where m is the number of elements in
[first,last). - Exception safety: nothrow.
bool replace(iterator position, const value_type & x);
-
Requires:
positionis a valid dereferenceableiteratorof the view. -
Effects: Assigns the value
xto the element pointed to bypositioninto thebimapto which the view belongs if, for the valuex-
the view is non-unique OR no other element with equivalent key
exists (except possibly
*position), -
AND replacing is allowed by all other views of the
bimap.
-
the view is non-unique OR no other element with equivalent key
exists (except possibly
- Postconditions: Validity of position is preserved in all cases.
-
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation the
bimapto which the view belongs remains in its original state.
template< class CompatibleKey > bool replace_key(iterator position, const CompatibleKey & x);
-
Requires:
positionis a valid dereferenceable iterator of the set view.CompatibleKeycan be assigned tokey_type. -
Effects: Assigns the value
xtoe.first, whereeis the element pointed to bypositioninto thebimapto which the set view belongs if,-
the map view is non-unique OR no other element with equivalent
key exists (except possibly
*position), -
AND replacing is allowed by all other views of the
bimap.
-
the map view is non-unique OR no other element with equivalent
key exists (except possibly
- Postconditions: Validity of position is preserved in all cases.
-
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation, the
bimapto which the set view belongs remains in its original state.
template< class CompatibleData > bool replace_data(iterator position, const CompatibleData & x);
-
Requires:
positionis a valid dereferenceable iterator of the set view.CompatibleKeycan be assigned todata_type. -
Effects: Assigns the value
xtoe.second, whereeis the element pointed to bypositioninto thebimapto which the set view belongs if,-
the map view is non-unique OR no other element with equivalent
key exists (except possibly
*position), -
AND replacing is allowed by all other views of the
bimap.
-
the map view is non-unique OR no other element with equivalent
key exists (except possibly
- Postconditions: Validity of position is preserved in all cases.
-
Returns:
trueif the replacement took place,falseotherwise. - Complexity: O(R(n)).
-
Exception safety: Strong. If an exception
is thrown by some user-provided operation, the
bimapto which the set view belongs remains in its original state.
template< class KeyModifier > bool modify_key(iterator position, KeyModifier mod);
-
Requires:
KeyModifieris a model of Unary Function accepting arguments of type:key_type&;positionis a valid dereferenceable iterator of the view. -
Effects: Calls
mod(e.first)where e is the element pointed to by position and rearranges*positioninto all the views of thebimap. If the rearrangement fails, the element is erased. Rearrangement is successful if- the map view is non-unique OR no other element with equivalent key exists,
-
AND rearrangement is allowed by all other views of the
bimap.
-
Postconditions: Validity of
positionis preserved if the operation succeeds. -
Returns:
trueif the operation succeeded,falseotherwise. - Complexity: O(M(n)).
- Exception safety: Basic. If an exception is thrown by some user-provided operation (except possibly mod), then the element pointed to by position is erased.
- Note: Only provided for map views.
template< class DataModifier > bool modify_data(iterator position, DataModifier mod);
-
Requires:
DataModifieris a model of Unary Function accepting arguments of type:data_type&;positionis a valid dereferenceable iterator of the view. -
Effects: Calls
mod(e.second)where e is the element pointed to by position and rearranges*positioninto all the views of thebimap. If the rearrangement fails, the element is erased. Rearrangement is successful if- the oppositte map view is non-unique OR no other element with equivalent key in that view exists,
-
AND rearrangement is allowed by all other views of the
bimap.
-
Postconditions: Validity of
positionis preserved if the operation succeeds. -
Returns:
trueif the operation succeeded,falseotherwise. - Complexity: O(M(n)).
- Exception safety: Basic. If an exception is thrown by some user-provided operation (except possibly mod), then the element pointed to by position is erased.
- Note: Only provided for map views.
unordered_[multi]set_of views provide the full lookup
functionality required by unordered associative containers, namely find, count,
and equal_range. Additionally,
these member functions are templatized to allow for non-standard arguments,
so extending the types of search operations allowed. The kind of arguments
permissible when invoking the lookup member functions is defined by the
following concept.
A type CompatibleKey
is said to be a compatible key of (Hash, Pred) if (CompatibleKey,
Hash,
Pred)
is a compatible extension of (Hash, Pred).
This implies that Hash
and Pred accept arguments
of type CompatibleKey,
which usually means they have several overloads of their corresponding
operator()
member functions.
template< class CompatibleKey > iterator find(const CompatibleKey & x); template< class CompatibleKey > const_iterator find(const CompatibleKey & x) const;
-
Effects: Returns a pointer to an element
whose key is equivalent to
x, orend()if such an element does not exist. - Complexity: Average case O(1) (constant), worst case O(n).
template< class CompatibleKey > size_type count(const CompatibleKey & x) const;
-
Effects: Returns the number of elements
with key equivalent to
x. - Complexity: Average case O(count(x)), worst case O(n).
template< class CompatibleKey > std::pair<iterator,iterator> equal_range(const CompatibleKey & x); template< class CompatibleKey > std::pair<const_iterator,const_iterator> equal_range(const CompatibleKey & x) const;
-
Effects: Returns a range containing
all elements with keys equivalent to
x(and only those). - Complexity: Average case O(count(x)), worst case O(n).
template< class CompatibleKey > const data_type & at(const CompatibleKey & k) const;
-
Requires:
CompatibleKeyis a compatible key ofkey_compare. -
Effects: Returns the
data_typereference that is associated withk, or throwsstd::out_of_rangeif such key does not exist. - Complexity: Average case O(1) (constant), worst case O(n).
-
Note: Only provided when
unordered_set_ofis used.
The symmetry of bimap imposes some constraints on operator[] and the non constant version of at()
that are not found in std::maps.
Tey are only provided if the other collection type is mutable (list_of, vector_of
and unconstrained_set_of).
template< class CompatibleKey > data_type & operator[](const CompatibleKey & k);
-
Requires:
CompatibleKeyis a compatible key ofkey_compare. -
Effects:
return insert(value_type(k,data_type()))->second; - Complexity: If the insertion is performed O(I(n)), else: Average case O(1) (constant), worst case O(n).
-
Note: Only provided when
unordered_set_ofis used and the other collection type is mutable.
template< class CompatibleKey > data_type & at(const CompatibleKey & k);
-
Requires:
CompatibleKeyis a compatible key ofkey_compare. -
Effects: Returns the
data_typereference that is associated withk, or throwsstd::out_of_rangeif such key does not exist. - Complexity: Average case O(1) (constant), worst case O(n).
-
Note: Only provided when
unordered_set_ofis used and the other collection type is mutable.
template< class CompatibleKey > info_type & info_at(const CompatibleKey & k); template< class CompatibleKey > const info_type & info_at(const CompatibleKey & k) const;
-
Requires:
CompatibleKeyis a compatible key ofkey_compare. -
Effects: Returns the
info_typereference that is associated withk, or throwsstd::out_of_rangeif such key does not exist. - Complexity: Average case O(1) (constant), worst case O(n).
-
Note: Only provided when
unordered_set_ofandinfo_hookare used
void rehash(size_type n);
-
Effects: Increases if necessary the
number of internal buckets so that
size()/bucket_count()does not exceed the maximum load factor, andbucket_count()>=n. - Postconditions: Validity of iterators and references to the elements contained is preserved.
- Complexity: Average case O(size()), worst case O(size(n)2).
- Exception safety: Strong.
Views cannot be serialized on their own, but only as part of the bimap into which they are embedded.
In describing the additional preconditions and guarantees associated
to unordered_[multi]set_of views with respect to serialization
of their embedding containers, we use the concepts defined in the bimap serialization section.
- Requires: No additional requirements to those imposed by the container.
-
Requires: Additionally to the general
requirements,
key_eq()must be serialization-compatible withm.get<i>().key_eq(), where i is the position of theunordered_[multi]set_ofview in the container. -
Postconditions: On successful loading,
the range
[begin(), end())contains restored copies of every element in[m.get<i>().begin(), m.get<i>().end()), though not necessarily in the same order.
-
Requires:
itis a validiteratorof the view. The associatedbimaphas been previously saved.
-
Postconditions: On successful loading,
if
itwas dereferenceable then*it' is the restored copy of*it, otherwiseit'== end(). -
Note: It is allowed that
itbe aconst_iteratorand the restoredit' aniterator, or viceversa.
-
Requires:
itis a valid local iterator of the view. The associatedbimaphas been previously saved.
-
Postconditions: On successful loading,
if
itwas dereferenceable then*it' is the restored copy of*it; ifitwasm.get<i>().end(n)for some n, thenit'== m'.get<i>().end(n)(wherebis the originalbimap,b' its restored copy andiis the ordinal of the index.) -
Note: It is allowed that
itbe aconst_local_iteratorand the restoredit' alocal_iterator, or viceversa.
