Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Olaf Krzikalla 2004-2006. Chris@101: // (C) Copyright Ion Gaztanaga 2006-2014 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/intrusive for documentation. Chris@16: // Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: #ifndef BOOST_INTRUSIVE_UNORDERED_SET_HPP Chris@16: #define BOOST_INTRUSIVE_UNORDERED_SET_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@16: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace intrusive { Chris@16: Chris@16: //! The class template unordered_set is an intrusive container, that mimics most of Chris@16: //! the interface of std::tr1::unordered_set as described in the C++ TR1. Chris@16: //! Chris@16: //! unordered_set is a semi-intrusive container: each object to be stored in the Chris@16: //! container must contain a proper hook, but the container also needs Chris@16: //! additional auxiliary memory to work: unordered_set needs a pointer to an array Chris@16: //! of type `bucket_type` to be passed in the constructor. This bucket array must Chris@16: //! have at least the same lifetime as the container. This makes the use of Chris@16: //! unordered_set more complicated than purely intrusive containers. Chris@16: //! `bucket_type` is default-constructible, copyable and assignable Chris@16: //! Chris@16: //! The template parameter \c T is the type to be managed by the container. Chris@16: //! The user can specify additional options and if no options are provided Chris@16: //! default options are used. Chris@16: //! Chris@16: //! The container supports the following options: Chris@16: //! \c base_hook<>/member_hook<>/value_traits<>, Chris@16: //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> Chris@16: //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>. Chris@16: //! Chris@16: //! unordered_set only provides forward iterators but it provides 4 iterator types: Chris@16: //! iterator and const_iterator to navigate through the whole container and Chris@16: //! local_iterator and const_local_iterator to navigate through the values Chris@16: //! stored in a single bucket. Local iterators are faster and smaller. Chris@16: //! Chris@16: //! It's not recommended to use non constant-time size unordered_sets because several Chris@16: //! key functions, like "empty()", become non-constant time functions. Non Chris@16: //! constant-time size unordered_sets are mainly provided to support auto-unlink hooks. Chris@16: //! Chris@16: //! unordered_set, unlike std::unordered_set, does not make automatic rehashings nor Chris@16: //! offers functions related to a load factor. Rehashing can be explicitly requested Chris@16: //! and the user must provide a new bucket array that will be used from that moment. Chris@16: //! Chris@16: //! Since no automatic rehashing is done, iterators are never invalidated when Chris@16: //! inserting or erasing elements. Iterators are only invalidated when rehasing. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class unordered_set_impl Chris@16: : public hashtable_impl Chris@16: { Chris@16: /// @cond Chris@16: private: Chris@16: typedef hashtable_impl table_type; Chris@16: Chris@16: //! This class is Chris@16: //! movable Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set_impl) Chris@16: Chris@16: typedef table_type implementation_defined; Chris@16: /// @endcond Chris@16: Chris@16: public: Chris@16: typedef typename implementation_defined::value_type value_type; Chris@16: typedef typename implementation_defined::value_traits value_traits; Chris@16: typedef typename implementation_defined::bucket_traits bucket_traits; Chris@16: typedef typename implementation_defined::pointer pointer; Chris@16: typedef typename implementation_defined::const_pointer const_pointer; Chris@16: typedef typename implementation_defined::reference reference; Chris@16: typedef typename implementation_defined::const_reference const_reference; Chris@16: typedef typename implementation_defined::difference_type difference_type; Chris@16: typedef typename implementation_defined::size_type size_type; Chris@16: typedef typename implementation_defined::key_type key_type; Chris@16: typedef typename implementation_defined::key_equal key_equal; Chris@16: typedef typename implementation_defined::hasher hasher; Chris@16: typedef typename implementation_defined::bucket_type bucket_type; Chris@16: typedef typename implementation_defined::bucket_ptr bucket_ptr; Chris@16: typedef typename implementation_defined::iterator iterator; Chris@16: typedef typename implementation_defined::const_iterator const_iterator; Chris@16: typedef typename implementation_defined::insert_commit_data insert_commit_data; Chris@16: typedef typename implementation_defined::local_iterator local_iterator; Chris@16: typedef typename implementation_defined::const_local_iterator const_local_iterator; Chris@16: typedef typename implementation_defined::node_traits node_traits; Chris@16: typedef typename implementation_defined::node node; Chris@16: typedef typename implementation_defined::node_ptr node_ptr; Chris@16: typedef typename implementation_defined::const_node_ptr const_node_ptr; Chris@16: typedef typename implementation_defined::node_algorithms node_algorithms; Chris@16: Chris@16: public: Chris@16: Chris@16: //! Requires: buckets must not be being used by any other resource. Chris@16: //! Chris@16: //! Effects: Constructs an empty unordered_set_impl, storing a reference Chris@16: //! to the bucket array and copies of the hasher and equal functors. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If value_traits::node_traits::node Chris@16: //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) Chris@16: //! or the copy constructor or invocation of Hash or Equal throws. Chris@16: //! Chris@16: //! Notes: buckets array must be disposed only after Chris@16: //! *this is disposed. Chris@16: explicit unordered_set_impl( const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : table_type(b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: //! Requires: buckets must not be being used by any other resource Chris@16: //! and Dereferencing iterator must yield an lvalue of type value_type. Chris@16: //! Chris@16: //! Effects: Constructs an empty unordered_set and inserts elements from Chris@16: //! [b, e). Chris@16: //! Chris@101: //! Complexity: If N is distance(b, e): Average case is O(N) Chris@16: //! (with a good hash function and with buckets_len >= N),worst case O(N2). Chris@16: //! Chris@16: //! Throws: If value_traits::node_traits::node Chris@16: //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) Chris@16: //! or the copy constructor or invocation of hasher or key_equal throws. Chris@16: //! Chris@16: //! Notes: buckets array must be disposed only after Chris@16: //! *this is disposed. Chris@16: template Chris@16: unordered_set_impl( Iterator b Chris@16: , Iterator e Chris@16: , const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : table_type(b_traits, hash_func, equal_func, v_traits) Chris@16: { table_type::insert_unique(b, e); } Chris@16: Chris@16: //! Effects: to-do Chris@16: //! Chris@16: unordered_set_impl(BOOST_RV_REF(unordered_set_impl) x) Chris@101: : table_type(BOOST_MOVE_BASE(table_type, x)) Chris@16: {} Chris@16: Chris@16: //! Effects: to-do Chris@16: //! Chris@16: unordered_set_impl& operator=(BOOST_RV_REF(unordered_set_impl) x) Chris@101: { return static_cast(table_type::operator=(BOOST_MOVE_BASE(table_type, x))); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: //! Effects: Detaches all elements from this. The objects in the unordered_set Chris@16: //! are not deleted (i.e. no destructors are called). Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements in the unordered_set, if Chris@16: //! it's a safe-mode or auto-unlink value. Otherwise constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~unordered_set_impl() Chris@16: {} Chris@16: Chris@16: //! Effects: Returns an iterator pointing to the beginning of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: iterator begin() Chris@16: { return table_type::begin(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the beginning Chris@16: //! of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator begin() const Chris@16: { return table_type::begin(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the beginning Chris@16: //! of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator cbegin() const Chris@16: { return table_type::cbegin(); } Chris@16: Chris@16: //! Effects: Returns an iterator pointing to the end of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: iterator end() Chris@16: { return table_type::end(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the end of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator end() const Chris@16: { return table_type::end(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the end of the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator cend() const Chris@16: { return table_type::cend(); } Chris@16: Chris@16: //! Effects: Returns the hasher object used by the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If hasher copy-constructor throws. Chris@16: hasher hash_function() const Chris@16: { return table_type::hash_function(); } Chris@16: Chris@16: //! Effects: Returns the key_equal object used by the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If key_equal copy-constructor throws. Chris@16: key_equal key_eq() const Chris@16: { return table_type::key_eq(); } Chris@16: Chris@16: //! Effects: Returns true if the container is empty. Chris@16: //! Chris@16: //! Complexity: if constant-time size and cache_last options are disabled, Chris@16: //! average constant time (worst case, with empty() == true: O(this->bucket_count()). Chris@16: //! Otherwise constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: bool empty() const Chris@16: { return table_type::empty(); } Chris@16: Chris@16: //! Effects: Returns the number of elements stored in the unordered_set. Chris@16: //! Chris@16: //! Complexity: Linear to elements contained in *this if Chris@16: //! constant-time size option is disabled. Constant-time otherwise. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type size() const Chris@16: { return table_type::size(); } Chris@16: Chris@16: //! Requires: the hasher and the equality function unqualified swap Chris@16: //! call should not throw. Chris@16: //! Chris@16: //! Effects: Swaps the contents of two unordered_sets. Chris@16: //! Swaps also the contained bucket array and equality and hasher functors. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the swap() call for the comparison or hash functors Chris@16: //! found using ADL throw. Basic guarantee. Chris@16: void swap(unordered_set_impl& other) Chris@16: { table_type::swap(other.table_); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Cloner should yield to nodes that compare equal and produce the same Chris@16: //! hash than the original node. Chris@16: //! Chris@16: //! Effects: Erases all the elements from *this Chris@16: //! calling Disposer::operator()(pointer), clones all the Chris@16: //! elements from src calling Cloner::operator()(const_reference ) Chris@16: //! and inserts them on *this. The hash function and the equality Chris@16: //! predicate are copied from the source. Chris@16: //! Chris@16: //! If store_hash option is true, this method does not use the hash function. Chris@16: //! Chris@16: //! If any operation throws, all cloned elements are unlinked and disposed Chris@16: //! calling Disposer::operator()(pointer). Chris@16: //! Chris@16: //! Complexity: Linear to erased plus inserted elements. Chris@16: //! Chris@16: //! Throws: If cloner or hasher throw or hash or equality predicate copying Chris@16: //! throws. Basic guarantee. Chris@16: template Chris@16: void clone_from(const unordered_set_impl &src, Cloner cloner, Disposer disposer) Chris@16: { table_type::clone_from(src.table_, cloner, disposer); } Chris@16: Chris@16: #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Requires: value must be an lvalue Chris@16: //! Chris@16: //! Effects: Tries to inserts value into the unordered_set. Chris@16: //! Chris@16: //! Returns: If the value Chris@16: //! is not already present inserts it and returns a pair containing the Chris@16: //! iterator to the new value and true. If there is an equivalent value Chris@16: //! returns a pair containing an iterator to the already present value Chris@16: //! and false. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: Does not affect the validity of iterators and references. Chris@16: //! No copy-constructors are called. Chris@16: std::pair insert(reference value) Chris@16: { return table_type::insert_unique(value); } Chris@16: Chris@16: //! Requires: Dereferencing iterator must yield an lvalue Chris@16: //! of type value_type. Chris@16: //! Chris@16: //! Effects: Equivalent to this->insert(t) for each element in [b, e). Chris@16: //! Chris@101: //! Complexity: Average case O(N), where N is distance(b, e). Chris@16: //! Worst case O(N*this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Does not affect the validity of iterators and references. Chris@16: //! No copy-constructors are called. Chris@16: template Chris@16: void insert(Iterator b, Iterator e) Chris@16: { table_type::insert_unique(b, e); } Chris@16: Chris@16: //! Requires: "hasher" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hasher" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Checks if a value can be inserted in the unordered_set, using Chris@16: //! a user provided key instead of the value itself. Chris@16: //! Chris@16: //! Returns: If there is an equivalent value Chris@16: //! returns a pair containing an iterator to the already present value Chris@16: //! and false. If the value can be inserted returns true in the returned Chris@16: //! pair boolean and fills "commit_data" that is meant to be used with Chris@16: //! the "insert_commit" function. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hasher or key_value_equal throw. Strong guarantee. Chris@16: //! Chris@16: //! Notes: This function is used to improve performance when constructing Chris@16: //! a value_type is expensive: if there is an equivalent value Chris@16: //! the constructed object must be discarded. Many times, the part of the Chris@16: //! node that is used to impose the hash or the equality is much cheaper to Chris@16: //! construct than the value_type and this function offers the possibility to Chris@16: //! use that the part to check if the insertion will be successful. Chris@16: //! Chris@16: //! If the check is successful, the user can construct the value_type and use Chris@16: //! "insert_commit" to insert the object in constant-time. Chris@16: //! Chris@16: //! "commit_data" remains valid for a subsequent "insert_commit" only if no more Chris@16: //! objects are inserted or erased from the unordered_set. Chris@16: //! Chris@16: //! After a successful rehashing insert_commit_data remains valid. Chris@16: template Chris@16: std::pair insert_check Chris@16: (const KeyType &key, KeyHasher hasher, KeyValueEqual key_value_equal, insert_commit_data &commit_data) Chris@16: { return table_type::insert_unique_check(key, hasher, key_value_equal, commit_data); } Chris@16: Chris@16: //! Requires: value must be an lvalue of type value_type. commit_data Chris@16: //! must have been obtained from a previous call to "insert_check". Chris@16: //! No objects should have been inserted or erased from the unordered_set between Chris@16: //! the "insert_check" that filled "commit_data" and the call to "insert_commit". Chris@16: //! Chris@16: //! Effects: Inserts the value in the unordered_set using the information obtained Chris@16: //! from the "commit_data" that a previous "insert_check" filled. Chris@16: //! Chris@16: //! Returns: An iterator to the newly inserted object. Chris@16: //! Chris@16: //! Complexity: Constant time. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Notes: This function has only sense if a "insert_check" has been Chris@16: //! previously executed to fill "commit_data". No value should be inserted or Chris@16: //! erased between the "insert_check" and "insert_commit" calls. Chris@16: //! Chris@16: //! After a successful rehashing insert_commit_data remains valid. Chris@16: iterator insert_commit(reference value, const insert_commit_data &commit_data) Chris@16: { return table_type::insert_unique_commit(value, commit_data); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Effects: Erases the element pointed to by i. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased element. No destructors are called. Chris@16: void erase(const_iterator i) Chris@16: { table_type::erase(i); } Chris@16: Chris@16: //! Effects: Erases the range pointed to by b end e. Chris@16: //! Chris@101: //! Complexity: Average case O(distance(b, e)), Chris@16: //! worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: void erase(const_iterator b, const_iterator e) Chris@16: { table_type::erase(b, e); } Chris@16: Chris@16: //! Effects: Erases all the elements with the given value. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: size_type erase(const_reference value) Chris@16: { return table_type::erase(value); } Chris@16: Chris@16: //! Requires: "hasher" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hasher" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Erases all the elements that have the same hash and Chris@16: //! compare equal with the given key. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::erase(key, hash_func, equal_func); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases the element pointed to by i. Chris@16: //! Disposer::operator()(pointer) is called for the removed element. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: void erase_and_dispose(const_iterator i, Disposer disposer Chris@16: /// @cond Chris@16: , typename detail::enable_if_c::value >::type * = 0 Chris@16: /// @endcond Chris@16: ) Chris@16: { table_type::erase_and_dispose(i, disposer); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases the range pointed to by b end e. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@101: //! Complexity: Average case O(distance(b, e)), Chris@16: //! worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) Chris@16: { table_type::erase_and_dispose(b, e, disposer); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all the elements with the given value. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: size_type erase_and_dispose(const_reference value, Disposer disposer) Chris@16: { return table_type::erase_and_dispose(value, disposer); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all the elements with the given key. Chris@16: //! according to the comparison functor "equal_func". Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer) Chris@16: { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); } Chris@16: Chris@16: //! Effects: Erases all of the elements. Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements on the container. Chris@16: //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: void clear() Chris@16: { return table_type::clear(); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all of the elements. Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements on the container. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: void clear_and_dispose(Disposer disposer) Chris@16: { return table_type::clear_and_dispose(disposer); } Chris@16: Chris@16: //! Effects: Returns the number of contained elements with the given value Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: size_type count(const_reference value) const Chris@16: { return table_type::find(value) != end(); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "equal_func" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "equal_func" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns the number of contained elements with the given key Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Chris@16: template Chris@16: size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::find(key, hash_func, equal_func) != end(); } Chris@16: Chris@16: //! Effects: Finds an iterator to the first element is equal to Chris@16: //! "value" or end() if that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: iterator find(const_reference value) Chris@16: { return table_type::find(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "equal_func" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "equal_func" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Finds an iterator to the first element whose key is Chris@16: //! "key" according to the given hasher and equality functor or end() if Chris@16: //! that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::find(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Finds a const_iterator to the first element whose key is Chris@16: //! "key" or end() if that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: const_iterator find(const_reference value) const Chris@16: { return table_type::find(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "equal_func" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "equal_func" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Finds an iterator to the first element whose key is Chris@16: //! "key" according to the given hasher and equality functor or end() if Chris@16: //! that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::find(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Returns a range containing all elements with values equivalent Chris@16: //! to value. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: std::pair equal_range(const_reference value) Chris@16: { return table_type::equal_range(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "equal_func" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "equal_func" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns a range containing all elements with equivalent Chris@16: //! keys. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(key, hash_func, hash_func)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or the equal_func throw. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: std::pair equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::equal_range(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Returns a range containing all elements with values equivalent Chris@16: //! to value. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: std::pair Chris@16: equal_range(const_reference value) const Chris@16: { return table_type::equal_range(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "equal_func" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "equal_func" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns a range containing all elements with equivalent Chris@16: //! keys. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(key, hash_func, equal_func)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the hash_func or equal_func throw. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: std::pair Chris@16: equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::equal_range(key, hash_func, equal_func); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid iterator belonging to the unordered_set Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the internal hash function throws. Chris@16: iterator iterator_to(reference value) Chris@16: { return table_type::iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_iterator belonging to the Chris@16: //! unordered_set that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the internal hash function throws. Chris@16: const_iterator iterator_to(const_reference value) const Chris@16: { return table_type::iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid local_iterator belonging to the unordered_set Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: This static function is available only if the value traits Chris@16: //! is stateless. Chris@16: static local_iterator s_local_iterator_to(reference value) Chris@16: { return table_type::s_local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_local_iterator belonging to Chris@16: //! the unordered_set that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: This static function is available only if the value traits Chris@16: //! is stateless. Chris@16: static const_local_iterator s_local_iterator_to(const_reference value) Chris@16: { return table_type::s_local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid local_iterator belonging to the unordered_set Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: local_iterator local_iterator_to(reference value) Chris@16: { return table_type::local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_local_iterator belonging to Chris@16: //! the unordered_set that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_local_iterator local_iterator_to(const_reference value) const Chris@16: { return table_type::local_iterator_to(value); } Chris@16: Chris@16: //! Effects: Returns the number of buckets passed in the constructor Chris@16: //! or the last rehash function. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type bucket_count() const Chris@16: { return table_type::bucket_count(); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns the number of elements in the nth bucket. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type bucket_size(size_type n) const Chris@16: { return table_type::bucket_size(n); } Chris@16: Chris@16: //! Effects: Returns the index of the bucket in which elements Chris@16: //! with keys equivalent to k would be found, if any such element existed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the hash functor throws. Chris@16: //! Chris@16: //! Note: the return value is in the range [0, this->bucket_count()). Chris@16: size_type bucket(const value_type& k) const Chris@16: { return table_type::bucket(k); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! Effects: Returns the index of the bucket in which elements Chris@16: //! with keys equivalent to k would be found, if any such element existed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If hash_func throws. Chris@16: //! Chris@16: //! Note: the return value is in the range [0, this->bucket_count()). Chris@16: template Chris@16: size_type bucket(const KeyType& k, KeyHasher hash_func) const Chris@16: { return table_type::bucket(k, hash_func); } Chris@16: Chris@16: //! Effects: Returns the bucket array pointer passed in the constructor Chris@16: //! or the last rehash function. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: bucket_ptr bucket_pointer() const Chris@16: { return table_type::bucket_pointer(); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: local_iterator begin(size_type n) Chris@16: { return table_type::begin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator begin(size_type n) const Chris@16: { return table_type::begin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator cbegin(size_type n) const Chris@16: { return table_type::cbegin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: local_iterator end(size_type n) Chris@16: { return table_type::end(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator end(size_type n) const Chris@16: { return table_type::end(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator cend(size_type n) const Chris@16: { return table_type::cend(n); } Chris@16: Chris@16: //! Requires: new_buckets must be a pointer to a new bucket array Chris@16: //! or the same as the old bucket array. new_size is the length of the Chris@16: //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer() Chris@16: //! n can be bigger or smaller than this->bucket_count(). Chris@16: //! Chris@16: //! Effects: Updates the internal reference with the new bucket erases Chris@16: //! the values from the old bucket and inserts then in the new one. Chris@16: //! Chris@16: //! If store_hash option is true, this method does not use the hash function. Chris@16: //! Chris@16: //! Complexity: Average case linear in this->size(), worst case quadratic. Chris@16: //! Chris@16: //! Throws: If the hasher functor throws. Basic guarantee. Chris@16: void rehash(const bucket_traits &new_bucket_traits) Chris@16: { table_type::rehash(new_bucket_traits); } Chris@16: Chris@16: //! Requires: Chris@16: //! Chris@16: //! Effects: Chris@16: //! Chris@16: //! Complexity: Chris@16: //! Chris@16: //! Throws: Chris@16: //! Chris@16: //! Note: this method is only available if incremental option is activated. Chris@16: bool incremental_rehash(bool grow = true) Chris@16: { return table_type::incremental_rehash(grow); } Chris@16: Chris@16: //! Note: this method is only available if incremental option is activated. Chris@16: bool incremental_rehash(const bucket_traits &new_bucket_traits) Chris@16: { return table_type::incremental_rehash(new_bucket_traits); } Chris@16: Chris@16: //! Requires: Chris@16: //! Chris@16: //! Effects: Chris@16: //! Chris@16: //! Complexity: Chris@16: //! Chris@16: //! Throws: Chris@16: size_type split_count() const Chris@16: { return table_type::split_count(); } Chris@16: Chris@16: //! Effects: Returns the nearest new bucket count optimized for Chris@16: //! the container that is bigger than n. This suggestion can be used Chris@16: //! to create bucket arrays with a size that will usually improve Chris@16: //! container's performance. If such value does not exist, the Chris@16: //! higher possible value is returned. Chris@16: //! Chris@16: //! Complexity: Amortized constant time. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: static size_type suggested_upper_bucket_count(size_type n) Chris@16: { return table_type::suggested_upper_bucket_count(n); } Chris@16: Chris@16: //! Effects: Returns the nearest new bucket count optimized for Chris@16: //! the container that is smaller than n. This suggestion can be used Chris@16: //! to create bucket arrays with a size that will usually improve Chris@16: //! container's performance. If such value does not exist, the Chris@16: //! lower possible value is returned. Chris@16: //! Chris@16: //! Complexity: Amortized constant time. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: static size_type suggested_lower_bucket_count(size_type n) Chris@16: { return table_type::suggested_lower_bucket_count(n); } Chris@16: Chris@16: #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: }; Chris@16: Chris@16: //! Helper metafunction to define an \c unordered_set that yields to the same type when the Chris@16: //! same options (either explicitly or implicitly) are used. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: struct make_unordered_set Chris@16: { Chris@16: /// @cond Chris@16: typedef typename pack_options Chris@16: < hashtable_defaults, Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type packed_options; Chris@16: Chris@16: typedef typename detail::get_value_traits Chris@16: ::type value_traits; Chris@16: Chris@101: typedef typename make_bucket_traits Chris@101: ::type bucket_traits; Chris@16: Chris@16: typedef unordered_set_impl Chris@16: < value_traits Chris@16: , typename packed_options::hash Chris@16: , typename packed_options::equal Chris@16: , typename packed_options::size_type Chris@101: , bucket_traits Chris@16: , (std::size_t(true)*hash_bool_flags::unique_keys_pos) Chris@16: | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos) Chris@16: | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos) Chris@16: | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos) Chris@16: | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos) Chris@16: | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos) Chris@16: > implementation_defined; Chris@16: Chris@16: /// @endcond Chris@16: typedef implementation_defined type; Chris@16: }; Chris@16: Chris@16: #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class unordered_set Chris@16: : public make_unordered_set::type Chris@16: { Chris@16: typedef typename make_unordered_set Chris@16: ::type Base; Chris@16: Chris@16: //Assert if passed value traits are compatible with the type Chris@16: BOOST_STATIC_ASSERT((detail::is_same::value)); Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set) Chris@16: Chris@16: public: Chris@16: typedef typename Base::value_traits value_traits; Chris@16: typedef typename Base::bucket_traits bucket_traits; Chris@16: typedef typename Base::iterator iterator; Chris@16: typedef typename Base::const_iterator const_iterator; Chris@16: typedef typename Base::bucket_ptr bucket_ptr; Chris@16: typedef typename Base::size_type size_type; Chris@16: typedef typename Base::hasher hasher; Chris@16: typedef typename Base::key_equal key_equal; Chris@16: Chris@16: explicit unordered_set ( const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: template Chris@16: unordered_set ( Iterator b Chris@16: , Iterator e Chris@16: , const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(b, e, b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: unordered_set(BOOST_RV_REF(unordered_set) x) Chris@101: : Base(BOOST_MOVE_BASE(Base, x)) Chris@16: {} Chris@16: Chris@16: unordered_set& operator=(BOOST_RV_REF(unordered_set) x) Chris@101: { return static_cast(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); } Chris@16: }; Chris@16: Chris@16: #endif Chris@16: Chris@16: Chris@16: //! The class template unordered_multiset is an intrusive container, that mimics most of Chris@16: //! the interface of std::tr1::unordered_multiset as described in the C++ TR1. Chris@16: //! Chris@16: //! unordered_multiset is a semi-intrusive container: each object to be stored in the Chris@16: //! container must contain a proper hook, but the container also needs Chris@16: //! additional auxiliary memory to work: unordered_multiset needs a pointer to an array Chris@16: //! of type `bucket_type` to be passed in the constructor. This bucket array must Chris@16: //! have at least the same lifetime as the container. This makes the use of Chris@16: //! unordered_multiset more complicated than purely intrusive containers. Chris@16: //! `bucket_type` is default-constructible, copyable and assignable Chris@16: //! Chris@16: //! The template parameter \c T is the type to be managed by the container. Chris@16: //! The user can specify additional options and if no options are provided Chris@16: //! default options are used. Chris@16: //! Chris@16: //! The container supports the following options: Chris@16: //! \c base_hook<>/member_hook<>/value_traits<>, Chris@16: //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<> Chris@16: //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>. Chris@16: //! Chris@16: //! unordered_multiset only provides forward iterators but it provides 4 iterator types: Chris@16: //! iterator and const_iterator to navigate through the whole container and Chris@16: //! local_iterator and const_local_iterator to navigate through the values Chris@16: //! stored in a single bucket. Local iterators are faster and smaller. Chris@16: //! Chris@16: //! It's not recommended to use non constant-time size unordered_multisets because several Chris@16: //! key functions, like "empty()", become non-constant time functions. Non Chris@16: //! constant-time size unordered_multisets are mainly provided to support auto-unlink hooks. Chris@16: //! Chris@16: //! unordered_multiset, unlike std::unordered_set, does not make automatic rehashings nor Chris@16: //! offers functions related to a load factor. Rehashing can be explicitly requested Chris@16: //! and the user must provide a new bucket array that will be used from that moment. Chris@16: //! Chris@16: //! Since no automatic rehashing is done, iterators are never invalidated when Chris@16: //! inserting or erasing elements. Iterators are only invalidated when rehasing. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class unordered_multiset_impl Chris@16: : public hashtable_impl Chris@16: { Chris@16: /// @cond Chris@16: private: Chris@16: typedef hashtable_impl table_type; Chris@16: /// @endcond Chris@16: Chris@16: //Movable Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset_impl) Chris@16: Chris@16: typedef table_type implementation_defined; Chris@16: Chris@16: public: Chris@16: typedef typename implementation_defined::value_type value_type; Chris@16: typedef typename implementation_defined::value_traits value_traits; Chris@16: typedef typename implementation_defined::bucket_traits bucket_traits; Chris@16: typedef typename implementation_defined::pointer pointer; Chris@16: typedef typename implementation_defined::const_pointer const_pointer; Chris@16: typedef typename implementation_defined::reference reference; Chris@16: typedef typename implementation_defined::const_reference const_reference; Chris@16: typedef typename implementation_defined::difference_type difference_type; Chris@16: typedef typename implementation_defined::size_type size_type; Chris@16: typedef typename implementation_defined::key_type key_type; Chris@16: typedef typename implementation_defined::key_equal key_equal; Chris@16: typedef typename implementation_defined::hasher hasher; Chris@16: typedef typename implementation_defined::bucket_type bucket_type; Chris@16: typedef typename implementation_defined::bucket_ptr bucket_ptr; Chris@16: typedef typename implementation_defined::iterator iterator; Chris@16: typedef typename implementation_defined::const_iterator const_iterator; Chris@16: typedef typename implementation_defined::insert_commit_data insert_commit_data; Chris@16: typedef typename implementation_defined::local_iterator local_iterator; Chris@16: typedef typename implementation_defined::const_local_iterator const_local_iterator; Chris@16: typedef typename implementation_defined::node_traits node_traits; Chris@16: typedef typename implementation_defined::node node; Chris@16: typedef typename implementation_defined::node_ptr node_ptr; Chris@16: typedef typename implementation_defined::const_node_ptr const_node_ptr; Chris@16: typedef typename implementation_defined::node_algorithms node_algorithms; Chris@16: Chris@16: public: Chris@16: Chris@16: //! Requires: buckets must not be being used by any other resource. Chris@16: //! Chris@16: //! Effects: Constructs an empty unordered_multiset, storing a reference Chris@16: //! to the bucket array and copies of the hasher and equal functors. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If value_traits::node_traits::node Chris@16: //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) Chris@16: //! or the copy constructor or invocation of Hash or Equal throws. Chris@16: //! Chris@16: //! Notes: buckets array must be disposed only after Chris@16: //! *this is disposed. Chris@16: explicit unordered_multiset_impl ( const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : table_type(b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: //! Requires: buckets must not be being used by any other resource Chris@16: //! and Dereferencing iterator must yield an lvalue of type value_type. Chris@16: //! Chris@16: //! Effects: Constructs an empty unordered_multiset and inserts elements from Chris@16: //! [b, e). Chris@16: //! Chris@101: //! Complexity: If N is distance(b, e): Average case is O(N) Chris@16: //! (with a good hash function and with buckets_len >= N),worst case O(N2). Chris@16: //! Chris@16: //! Throws: If value_traits::node_traits::node Chris@16: //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) Chris@16: //! or the copy constructor or invocation of hasher or key_equal throws. Chris@16: //! Chris@16: //! Notes: buckets array must be disposed only after Chris@16: //! *this is disposed. Chris@16: template Chris@16: unordered_multiset_impl ( Iterator b Chris@16: , Iterator e Chris@16: , const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : table_type(b_traits, hash_func, equal_func, v_traits) Chris@16: { table_type::insert_equal(b, e); } Chris@16: Chris@16: //! Effects: to-do Chris@16: //! Chris@16: unordered_multiset_impl(BOOST_RV_REF(unordered_multiset_impl) x) Chris@101: : table_type(BOOST_MOVE_BASE(table_type, x)) Chris@16: {} Chris@16: Chris@16: //! Effects: to-do Chris@16: //! Chris@16: unordered_multiset_impl& operator=(BOOST_RV_REF(unordered_multiset_impl) x) Chris@101: { return static_cast(table_type::operator=(BOOST_MOVE_BASE(table_type, x))); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Effects: Detaches all elements from this. The objects in the unordered_multiset Chris@16: //! are not deleted (i.e. no destructors are called). Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements in the unordered_multiset, if Chris@16: //! it's a safe-mode or auto-unlink value. Otherwise constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: ~unordered_multiset_impl() Chris@16: {} Chris@16: Chris@16: //! Effects: Returns an iterator pointing to the beginning of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: iterator begin() Chris@16: { return table_type::begin(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the beginning Chris@16: //! of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator begin() const Chris@16: { return table_type::begin(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the beginning Chris@16: //! of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant time if `cache_begin<>` is true. Amortized Chris@16: //! constant time with worst case (empty unordered_set) O(this->bucket_count()) Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator cbegin() const Chris@16: { return table_type::cbegin(); } Chris@16: Chris@16: //! Effects: Returns an iterator pointing to the end of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: iterator end() Chris@16: { return table_type::end(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the end of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator end() const Chris@16: { return table_type::end(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the end of the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator cend() const Chris@16: { return table_type::cend(); } Chris@16: Chris@16: //! Effects: Returns the hasher object used by the unordered_set. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If hasher copy-constructor throws. Chris@16: hasher hash_function() const Chris@16: { return table_type::hash_function(); } Chris@16: Chris@16: //! Effects: Returns the key_equal object used by the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If key_equal copy-constructor throws. Chris@16: key_equal key_eq() const Chris@16: { return table_type::key_eq(); } Chris@16: Chris@16: //! Effects: Returns true if the container is empty. Chris@16: //! Chris@16: //! Complexity: if constant-time size and cache_last options are disabled, Chris@16: //! average constant time (worst case, with empty() == true: O(this->bucket_count()). Chris@16: //! Otherwise constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: bool empty() const Chris@16: { return table_type::empty(); } Chris@16: Chris@16: //! Effects: Returns the number of elements stored in the unordered_multiset. Chris@16: //! Chris@16: //! Complexity: Linear to elements contained in *this if Chris@16: //! constant-time size option is disabled. Constant-time otherwise. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type size() const Chris@16: { return table_type::size(); } Chris@16: Chris@16: //! Requires: the hasher and the equality function unqualified swap Chris@16: //! call should not throw. Chris@16: //! Chris@16: //! Effects: Swaps the contents of two unordered_multisets. Chris@16: //! Swaps also the contained bucket array and equality and hasher functors. Chris@16: //! Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the swap() call for the comparison or hash functors Chris@16: //! found using ADL throw. Basic guarantee. Chris@16: void swap(unordered_multiset_impl& other) Chris@16: { table_type::swap(other.table_); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Cloner should yield to nodes that compare equal and produce the same Chris@16: //! hash than the original node. Chris@16: //! Chris@16: //! Effects: Erases all the elements from *this Chris@16: //! calling Disposer::operator()(pointer), clones all the Chris@16: //! elements from src calling Cloner::operator()(const_reference ) Chris@16: //! and inserts them on *this. The hash function and the equality Chris@16: //! predicate are copied from the source. Chris@16: //! Chris@16: //! If store_hash option is true, this method does not use the hash function. Chris@16: //! Chris@16: //! If any operation throws, all cloned elements are unlinked and disposed Chris@16: //! calling Disposer::operator()(pointer). Chris@16: //! Chris@16: //! Complexity: Linear to erased plus inserted elements. Chris@16: //! Chris@16: //! Throws: If cloner or hasher throw or hash or equality predicate copying Chris@16: //! throws. Basic guarantee. Chris@16: template Chris@16: void clone_from(const unordered_multiset_impl &src, Cloner cloner, Disposer disposer) Chris@16: { table_type::clone_from(src.table_, cloner, disposer); } Chris@16: Chris@16: #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Requires: value must be an lvalue Chris@16: //! Chris@16: //! Effects: Inserts value into the unordered_multiset. Chris@16: //! Chris@16: //! Returns: An iterator to the new inserted value. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: Does not affect the validity of iterators and references. Chris@16: //! No copy-constructors are called. Chris@16: iterator insert(reference value) Chris@16: { return table_type::insert_equal(value); } Chris@16: Chris@16: //! Requires: Dereferencing iterator must yield an lvalue Chris@16: //! of type value_type. Chris@16: //! Chris@16: //! Effects: Equivalent to this->insert(t) for each element in [b, e). Chris@16: //! Chris@16: //! Complexity: Average case is O(N), where N is the Chris@16: //! size of the range. Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Does not affect the validity of iterators and references. Chris@16: //! No copy-constructors are called. Chris@16: template Chris@16: void insert(Iterator b, Iterator e) Chris@16: { table_type::insert_equal(b, e); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Effects: Erases the element pointed to by i. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased element. No destructors are called. Chris@16: void erase(const_iterator i) Chris@16: { table_type::erase(i); } Chris@16: Chris@16: //! Effects: Erases the range pointed to by b end e. Chris@16: //! Chris@101: //! Complexity: Average case O(distance(b, e)), Chris@16: //! worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: void erase(const_iterator b, const_iterator e) Chris@16: { table_type::erase(b, e); } Chris@16: Chris@16: //! Effects: Erases all the elements with the given value. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: size_type erase(const_reference value) Chris@16: { return table_type::erase(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Erases all the elements that have the same hash and Chris@16: //! compare equal with the given key. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the hash_func or the equal_func functors throws. Chris@16: //! Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::erase(key, hash_func, equal_func); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases the element pointed to by i. Chris@16: //! Disposer::operator()(pointer) is called for the removed element. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: void erase_and_dispose(const_iterator i, Disposer disposer Chris@16: /// @cond Chris@16: , typename detail::enable_if_c::value >::type * = 0 Chris@16: /// @endcond Chris@16: ) Chris@16: { table_type::erase_and_dispose(i, disposer); } Chris@16: Chris@16: #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: template Chris@16: void erase_and_dispose(const_iterator i, Disposer disposer) Chris@16: { this->erase_and_dispose(const_iterator(i), disposer); } Chris@16: #endif Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases the range pointed to by b end e. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@101: //! Complexity: Average case O(distance(b, e)), Chris@16: //! worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) Chris@16: { table_type::erase_and_dispose(b, e, disposer); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all the elements with the given value. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: size_type erase_and_dispose(const_reference value, Disposer disposer) Chris@16: { return table_type::erase_and_dispose(value, disposer); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all the elements with the given key. Chris@16: //! according to the comparison functor "equal_func". Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If hash_func or equal_func throw. Basic guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer) Chris@16: { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); } Chris@16: Chris@16: //! Effects: Erases all the elements of the container. Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements on the container. Chris@16: //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: void clear() Chris@16: { return table_type::clear(); } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@16: //! Effects: Erases all the elements of the container. Chris@16: //! Chris@16: //! Complexity: Linear to the number of elements on the container. Chris@16: //! Disposer::operator()(pointer) is called for the removed elements. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. No destructors are called. Chris@16: template Chris@16: void clear_and_dispose(Disposer disposer) Chris@16: { return table_type::clear_and_dispose(disposer); } Chris@16: Chris@16: //! Effects: Returns the number of contained elements with the given key Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: size_type count(const_reference value) const Chris@16: { return table_type::count(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns the number of contained elements with the given key Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: template Chris@16: size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::count(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Finds an iterator to the first element whose value is Chris@16: //! "value" or end() if that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: iterator find(const_reference value) Chris@16: { return table_type::find(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Finds an iterator to the first element whose key is Chris@16: //! "key" according to the given hasher and equality functor or end() if Chris@16: //! that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::find(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Finds a const_iterator to the first element whose key is Chris@16: //! "key" or end() if that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: const_iterator find(const_reference value) const Chris@16: { return table_type::find(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Finds an iterator to the first element whose key is Chris@16: //! "key" according to the given hasher and equality functor or end() if Chris@16: //! that element does not exist. Chris@16: //! Chris@16: //! Complexity: Average case O(1), worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::find(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Returns a range containing all elements with values equivalent Chris@16: //! to value. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: std::pair equal_range(const_reference value) Chris@16: { return table_type::equal_range(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns a range containing all elements with equivalent Chris@16: //! keys. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(key, hash_func, equal_func)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: std::pair equal_range Chris@16: (const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) Chris@16: { return table_type::equal_range(key, hash_func, equal_func); } Chris@16: Chris@16: //! Effects: Returns a range containing all elements with values equivalent Chris@16: //! to value. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(value)). Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: std::pair Chris@16: equal_range(const_reference value) const Chris@16: { return table_type::equal_range(value); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! "key_value_equal" must be a equality function that induces Chris@16: //! the same equality as key_equal. The difference is that Chris@16: //! "key_value_equal" compares an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Returns a range containing all elements with equivalent Chris@16: //! keys. Returns std::make_pair(this->end(), this->end()) if no such Chris@16: //! elements exist. Chris@16: //! Chris@16: //! Complexity: Average case O(this->count(key, hash_func, equal_func)). Chris@16: //! Worst case O(this->size()). Chris@16: //! Chris@16: //! Throws: If the internal hasher or the equality functor throws. Chris@16: //! Chris@16: //! Note: This function is used when constructing a value_type Chris@16: //! is expensive and the value_type can be compared with a cheaper Chris@16: //! key type. Usually this key is part of the value_type. Chris@16: template Chris@16: std::pair Chris@16: equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const Chris@16: { return table_type::equal_range(key, hash_func, equal_func); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_multiset of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid iterator belonging to the unordered_multiset Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the hash function throws. Chris@16: iterator iterator_to(reference value) Chris@16: { return table_type::iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_multiset of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_iterator belonging to the Chris@16: //! unordered_multiset that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the hash function throws. Chris@16: const_iterator iterator_to(const_reference value) const Chris@16: { return table_type::iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid local_iterator belonging to the unordered_set Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: This static function is available only if the value traits Chris@16: //! is stateless. Chris@16: static local_iterator s_local_iterator_to(reference value) Chris@16: { return table_type::s_local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_local_iterator belonging to Chris@16: //! the unordered_set that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: This static function is available only if the value traits Chris@16: //! is stateless. Chris@16: static const_local_iterator s_local_iterator_to(const_reference value) Chris@16: { return table_type::s_local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid local_iterator belonging to the unordered_set Chris@16: //! that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: local_iterator local_iterator_to(reference value) Chris@16: { return table_type::local_iterator_to(value); } Chris@16: Chris@16: //! Requires: value must be an lvalue and shall be in a unordered_set of Chris@16: //! appropriate type. Otherwise the behavior is undefined. Chris@16: //! Chris@16: //! Effects: Returns: a valid const_local_iterator belonging to Chris@16: //! the unordered_set that points to the value Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_local_iterator local_iterator_to(const_reference value) const Chris@16: { return table_type::local_iterator_to(value); } Chris@16: Chris@16: //! Effects: Returns the number of buckets passed in the constructor Chris@16: //! or the last rehash function. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type bucket_count() const Chris@16: { return table_type::bucket_count(); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns the number of elements in the nth bucket. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: size_type bucket_size(size_type n) const Chris@16: { return table_type::bucket_size(n); } Chris@16: Chris@16: //! Effects: Returns the index of the bucket in which elements Chris@16: //! with keys equivalent to k would be found, if any such element existed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the hash functor throws. Chris@16: //! Chris@16: //! Note: the return value is in the range [0, this->bucket_count()). Chris@16: size_type bucket(const value_type& k) const Chris@16: { return table_type::bucket(k); } Chris@16: Chris@16: //! Requires: "hash_func" must be a hash function that induces Chris@16: //! the same hash values as the stored hasher. The difference is that Chris@16: //! "hash_func" hashes the given key instead of the value_type. Chris@16: //! Chris@16: //! Effects: Returns the index of the bucket in which elements Chris@16: //! with keys equivalent to k would be found, if any such element existed. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the hash functor throws. Chris@16: //! Chris@16: //! Note: the return value is in the range [0, this->bucket_count()). Chris@16: template Chris@16: size_type bucket(const KeyType& k, const KeyHasher &hash_func) const Chris@16: { return table_type::bucket(k, hash_func); } Chris@16: Chris@16: //! Effects: Returns the bucket array pointer passed in the constructor Chris@16: //! or the last rehash function. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: bucket_ptr bucket_pointer() const Chris@16: { return table_type::bucket_pointer(); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: local_iterator begin(size_type n) Chris@16: { return table_type::begin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator begin(size_type n) const Chris@16: { return table_type::begin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the beginning Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator cbegin(size_type n) const Chris@16: { return table_type::cbegin(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: local_iterator end(size_type n) Chris@16: { return table_type::end(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator end(size_type n) const Chris@16: { return table_type::end(n); } Chris@16: Chris@16: //! Requires: n is in the range [0, this->bucket_count()). Chris@16: //! Chris@16: //! Effects: Returns a const_local_iterator pointing to the end Chris@16: //! of the sequence stored in the bucket n. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: [this->begin(n), this->end(n)) is a valid range Chris@16: //! containing all of the elements in the nth bucket. Chris@16: const_local_iterator cend(size_type n) const Chris@16: { return table_type::cend(n); } Chris@16: Chris@16: //! Requires: new_buckets must be a pointer to a new bucket array Chris@16: //! or the same as the old bucket array. new_size is the length of the Chris@16: //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer() Chris@16: //! n can be bigger or smaller than this->bucket_count(). Chris@16: //! Chris@16: //! Effects: Updates the internal reference with the new bucket erases Chris@16: //! the values from the old bucket and inserts then in the new one. Chris@16: //! Chris@16: //! If store_hash option is true, this method does not use the hash function. Chris@16: //! Chris@16: //! Complexity: Average case linear in this->size(), worst case quadratic. Chris@16: //! Chris@16: //! Throws: If the hasher functor throws. Chris@16: void rehash(const bucket_traits &new_bucket_traits) Chris@16: { table_type::rehash(new_bucket_traits); } Chris@16: Chris@16: //! Requires: Chris@16: //! Chris@16: //! Effects: Chris@16: //! Chris@16: //! Complexity: Chris@16: //! Chris@16: //! Throws: Chris@16: //! Chris@16: //! Note: this method is only available if incremental option is activated. Chris@16: bool incremental_rehash(bool grow = true) Chris@16: { return table_type::incremental_rehash(grow); } Chris@16: Chris@16: //! Note: this method is only available if incremental option is activated. Chris@16: bool incremental_rehash(const bucket_traits &new_bucket_traits) Chris@16: { return table_type::incremental_rehash(new_bucket_traits); } Chris@16: Chris@16: //! Requires: Chris@16: //! Chris@16: //! Effects: Chris@16: //! Chris@16: //! Complexity: Chris@16: //! Chris@16: //! Throws: Chris@16: size_type split_count() const Chris@16: { return table_type::split_count(); } Chris@16: Chris@16: //! Effects: Returns the nearest new bucket count optimized for Chris@16: //! the container that is bigger than n. This suggestion can be used Chris@16: //! to create bucket arrays with a size that will usually improve Chris@16: //! container's performance. If such value does not exist, the Chris@16: //! higher possible value is returned. Chris@16: //! Chris@16: //! Complexity: Amortized constant time. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: static size_type suggested_upper_bucket_count(size_type n) Chris@16: { return table_type::suggested_upper_bucket_count(n); } Chris@16: Chris@16: //! Effects: Returns the nearest new bucket count optimized for Chris@16: //! the container that is smaller than n. This suggestion can be used Chris@16: //! to create bucket arrays with a size that will usually improve Chris@16: //! container's performance. If such value does not exist, the Chris@16: //! lower possible value is returned. Chris@16: //! Chris@16: //! Complexity: Amortized constant time. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: static size_type suggested_lower_bucket_count(size_type n) Chris@16: { return table_type::suggested_lower_bucket_count(n); } Chris@16: Chris@16: #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: }; Chris@16: Chris@16: //! Helper metafunction to define an \c unordered_multiset that yields to the same type when the Chris@16: //! same options (either explicitly or implicitly) are used. Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: struct make_unordered_multiset Chris@16: { Chris@16: /// @cond Chris@16: typedef typename pack_options Chris@16: < hashtable_defaults, Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 Chris@16: #else Chris@16: Options... Chris@16: #endif Chris@16: >::type packed_options; Chris@16: Chris@16: typedef typename detail::get_value_traits Chris@16: ::type value_traits; Chris@16: Chris@101: typedef typename make_bucket_traits Chris@101: ::type bucket_traits; Chris@16: Chris@16: typedef unordered_multiset_impl Chris@16: < value_traits Chris@16: , typename packed_options::hash Chris@16: , typename packed_options::equal Chris@16: , typename packed_options::size_type Chris@101: , bucket_traits Chris@16: , (std::size_t(false)*hash_bool_flags::unique_keys_pos) Chris@16: | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos) Chris@16: | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos) Chris@16: | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos) Chris@16: | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos) Chris@16: | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos) Chris@16: > implementation_defined; Chris@16: Chris@16: /// @endcond Chris@16: typedef implementation_defined type; Chris@16: }; Chris@16: Chris@16: #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@16: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class unordered_multiset Chris@16: : public make_unordered_multiset::type Chris@16: { Chris@16: typedef typename make_unordered_multiset Chris@16: ::type Base; Chris@16: //Assert if passed value traits are compatible with the type Chris@16: BOOST_STATIC_ASSERT((detail::is_same::value)); Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset) Chris@16: Chris@16: public: Chris@16: typedef typename Base::value_traits value_traits; Chris@16: typedef typename Base::bucket_traits bucket_traits; Chris@16: typedef typename Base::iterator iterator; Chris@16: typedef typename Base::const_iterator const_iterator; Chris@16: typedef typename Base::bucket_ptr bucket_ptr; Chris@16: typedef typename Base::size_type size_type; Chris@16: typedef typename Base::hasher hasher; Chris@16: typedef typename Base::key_equal key_equal; Chris@16: Chris@16: explicit unordered_multiset( const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: template Chris@16: unordered_multiset( Iterator b Chris@16: , Iterator e Chris@16: , const bucket_traits &b_traits Chris@16: , const hasher & hash_func = hasher() Chris@16: , const key_equal &equal_func = key_equal() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(b, e, b_traits, hash_func, equal_func, v_traits) Chris@16: {} Chris@16: Chris@16: unordered_multiset(BOOST_RV_REF(unordered_multiset) x) Chris@101: : Base(BOOST_MOVE_BASE(Base, x)) Chris@16: {} Chris@16: Chris@16: unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x) Chris@101: { return static_cast(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); } Chris@16: }; Chris@16: Chris@16: #endif Chris@16: Chris@16: } //namespace intrusive Chris@16: } //namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //BOOST_INTRUSIVE_UNORDERED_SET_HPP