Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // (C) Copyright Ion Gaztanaga 2008-2013 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_TREAP_HPP Chris@16: #define BOOST_INTRUSIVE_TREAP_HPP Chris@16: Chris@16: #include Chris@101: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@101: Chris@101: #include Chris@101: #include Chris@101: #include Chris@101: Chris@101: #include Chris@101: #include Chris@101: #include //std::pair Chris@101: 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: /// @cond Chris@16: Chris@16: struct treap_defaults Chris@16: { Chris@101: typedef default_bstree_hook_applier proto_value_traits; Chris@16: static const bool constant_time_size = true; Chris@16: typedef std::size_t size_type; Chris@16: typedef void compare; Chris@16: typedef void priority; Chris@101: typedef void header_holder_type; Chris@16: }; Chris@16: Chris@16: /// @endcond Chris@16: Chris@16: //! The class template treap is an intrusive treap container that Chris@16: //! is used to construct intrusive set and multiset containers. The no-throw Chris@16: //! guarantee holds only, if the value_compare object and priority_compare object Chris@16: //! don't throw. 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<>, Chris@16: //! \c compare<> and \c priority_compare<> Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: template Chris@16: #else Chris@101: template Chris@16: #endif Chris@16: class treap_impl Chris@16: /// @cond Chris@101: : public bstree_impl Chris@101: //Use public inheritance to avoid MSVC bugs with closures Chris@101: , public detail::ebo_functor_holder Chris@16: < typename get_prio Chris@16: < VoidOrPrioComp Chris@16: , typename bstree_impl Chris@101: ::value_type>::type Chris@16: > Chris@16: /// @endcond Chris@16: { Chris@16: public: Chris@16: typedef ValueTraits value_traits; Chris@16: /// @cond Chris@16: typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType Chris@101: , ConstantTimeSize, BsTreeAlgorithms Chris@101: , HeaderHolder> tree_type; Chris@16: typedef tree_type implementation_defined; Chris@16: typedef get_prio Chris@16: < VoidOrPrioComp Chris@16: , typename tree_type::value_type> get_prio_type; Chris@16: Chris@16: typedef detail::ebo_functor_holder Chris@16: prio_base; Chris@16: Chris@16: /// @endcond Chris@16: Chris@16: typedef typename implementation_defined::pointer pointer; Chris@16: typedef typename implementation_defined::const_pointer const_pointer; Chris@16: typedef typename implementation_defined::value_type value_type; Chris@16: typedef typename implementation_defined::key_type key_type; 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::value_compare value_compare; Chris@16: typedef typename implementation_defined::key_compare key_compare; Chris@16: typedef typename implementation_defined::iterator iterator; Chris@16: typedef typename implementation_defined::const_iterator const_iterator; Chris@16: typedef typename implementation_defined::reverse_iterator reverse_iterator; Chris@16: typedef typename implementation_defined::const_reverse_iterator const_reverse_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 BOOST_INTRUSIVE_IMPDEF(treap_algorithms) node_algorithms; Chris@16: typedef BOOST_INTRUSIVE_IMPDEF(typename get_prio_type::type) priority_compare; Chris@16: Chris@16: static const bool constant_time_size = implementation_defined::constant_time_size; Chris@16: static const bool stateful_value_traits = implementation_defined::stateful_value_traits; Chris@101: static const bool safemode_or_autounlink = is_safe_autounlink::value; Chris@16: Chris@16: /// @cond Chris@16: private: Chris@16: Chris@16: //noncopyable Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_impl) Chris@16: Chris@16: const priority_compare &priv_pcomp() const Chris@16: { return static_cast(*this).get(); } Chris@16: Chris@16: priority_compare &priv_pcomp() Chris@16: { return static_cast(*this).get(); } Chris@16: Chris@16: /// @endcond Chris@16: Chris@16: public: Chris@16: typedef typename node_algorithms::insert_commit_data insert_commit_data; Chris@16: Chris@16: //! Effects: Constructs an empty container. 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 of the value_compare/priority_compare objects throw. Basic guarantee. Chris@16: explicit treap_impl( const value_compare &cmp = value_compare() Chris@16: , const priority_compare &pcmp = priority_compare() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : tree_type(cmp, v_traits), prio_base(pcmp) Chris@16: {} Chris@16: Chris@16: //! Requires: Dereferencing iterator must yield an lvalue of type value_type. Chris@16: //! cmp must be a comparison function that induces a strict weak ordering. Chris@16: //! Chris@16: //! Effects: Constructs an empty container and inserts elements from Chris@16: //! [b, e). Chris@16: //! Chris@16: //! Complexity: Linear in N if [b, e) is already sorted using Chris@16: //! comp and otherwise N * log N, where N is the distance between first and last. 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/operator() of the value_compare/priority_compare objects Chris@16: //! throw. Basic guarantee. Chris@16: template Chris@16: treap_impl( bool unique, Iterator b, Iterator e Chris@16: , const value_compare &cmp = value_compare() Chris@16: , const priority_compare &pcmp = priority_compare() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : tree_type(cmp, v_traits), prio_base(pcmp) Chris@16: { Chris@16: if(unique) Chris@16: this->insert_unique(b, e); Chris@16: else Chris@16: this->insert_equal(b, e); Chris@16: } Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) Chris@16: treap_impl(BOOST_RV_REF(treap_impl) x) Chris@101: : tree_type(BOOST_MOVE_BASE(tree_type, x)) Chris@16: , prio_base(::boost::move(x.priv_pcomp())) Chris@16: {} Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) Chris@16: treap_impl& operator=(BOOST_RV_REF(treap_impl) x) Chris@16: { this->swap(x); return *this; } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: //! @copydoc ::boost::intrusive::bstree::~bstree() Chris@16: ~treap_impl(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::begin() Chris@16: iterator begin(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::begin()const Chris@16: const_iterator begin() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::cbegin()const Chris@16: const_iterator cbegin() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::end() Chris@16: iterator end(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::end()const Chris@16: const_iterator end() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::cend()const Chris@16: const_iterator cend() const; Chris@16: #endif Chris@16: Chris@16: //! Effects: Returns an iterator pointing to the highest priority object of the treap. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: iterator top() Chris@101: { return this->tree_type::root(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the highest priority object of the treap.. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator top() const Chris@16: { return this->ctop(); } Chris@16: Chris@16: //! Effects: Returns a const_iterator pointing to the highest priority object of the treap.. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_iterator ctop() const Chris@101: { return this->tree_type::root(); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: //! @copydoc ::boost::intrusive::bstree::rbegin() Chris@16: reverse_iterator rbegin(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::rbegin()const Chris@16: const_reverse_iterator rbegin() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::crbegin()const Chris@16: const_reverse_iterator crbegin() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::rend() Chris@16: reverse_iterator rend(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::rend()const Chris@16: const_reverse_iterator rend() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::crend()const Chris@16: const_reverse_iterator crend() const; Chris@16: #endif Chris@16: Chris@16: //! Effects: Returns a reverse_iterator pointing to the highest priority object of the Chris@16: //! reversed treap. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: reverse_iterator rtop() Chris@16: { return reverse_iterator(this->top()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the highest priority objec Chris@16: //! of the reversed treap. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_reverse_iterator rtop() const Chris@16: { return const_reverse_iterator(this->top()); } Chris@16: Chris@16: //! Effects: Returns a const_reverse_iterator pointing to the highest priority object Chris@16: //! of the reversed treap. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: const_reverse_iterator crtop() const Chris@16: { return const_reverse_iterator(this->top()); } Chris@16: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) Chris@16: static treap_impl &container_from_end_iterator(iterator end_iterator); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) Chris@16: static const treap_impl &container_from_end_iterator(const_iterator end_iterator); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) Chris@16: static treap_impl &container_from_iterator(iterator it); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) Chris@16: static const treap_impl &container_from_iterator(const_iterator it); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::key_comp()const Chris@16: key_compare key_comp() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::value_comp()const Chris@16: value_compare value_comp() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::empty()const Chris@16: bool empty() const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::size()const Chris@16: size_type size() const; Chris@16: #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //! Effects: Returns the priority_compare object used by the container. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If priority_compare copy-constructor throws. Chris@16: priority_compare priority_comp() const Chris@16: { return this->priv_pcomp(); } Chris@16: Chris@16: //! Effects: Swaps the contents of two treaps. Chris@16: //! Chris@16: //! Complexity: Constant. Chris@16: //! Chris@16: //! Throws: If the comparison functor's swap call throws. Chris@16: void swap(treap_impl& other) Chris@16: { Chris@16: tree_type::swap(other); Chris@16: //This can throw Chris@101: ::boost::adl_move_swap(this->priv_pcomp(), other.priv_pcomp()); Chris@16: } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Cloner should yield to nodes equivalent to the original nodes. 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. Copies the predicate from the source container. Chris@16: //! Chris@16: //! If cloner 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 throws or predicate copy assignment throws. Basic guarantee. Chris@16: template Chris@16: void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer) Chris@16: { Chris@16: tree_type::clone_from(src, cloner, disposer); Chris@16: this->priv_pcomp() = src.priv_pcomp(); Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue Chris@16: //! Chris@16: //! Effects: Inserts value into the container before the upper bound. Chris@16: //! Chris@16: //! Complexity: Average complexity for insert element is at Chris@16: //! most logarithmic. Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. 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_equal(reference value) Chris@16: { Chris@101: detail::key_nodeptr_comp Chris@101: key_node_comp(this->value_comp(), &this->get_value_traits()); Chris@101: detail::key_nodeptr_comp Chris@101: key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@16: iterator ret(node_algorithms::insert_equal_upper_bound Chris@101: (this->tree_type::header_ptr(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr()); Chris@16: this->tree_type::sz_traits().increment(); Chris@16: return ret; Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue, and "hint" must be Chris@16: //! a valid iterator. Chris@16: //! Chris@16: //! Effects: Inserts x into the container, using "hint" as a hint to Chris@16: //! where it will be inserted. If "hint" is the upper_bound Chris@16: //! the insertion takes constant time (two comparisons in the worst case) Chris@16: //! Chris@16: //! Complexity: Logarithmic in general, but it is amortized Chris@16: //! constant time if t is inserted immediately before hint. Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. 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_equal(const_iterator hint, reference value) Chris@16: { Chris@101: detail::key_nodeptr_comp Chris@101: key_node_comp(this->value_comp(), &this->get_value_traits()); Chris@101: detail::key_nodeptr_comp Chris@101: key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@16: iterator ret (node_algorithms::insert_equal Chris@101: (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr()); Chris@16: this->tree_type::sz_traits().increment(); Chris@16: return ret; Chris@16: } Chris@16: Chris@16: //! Requires: Dereferencing iterator must yield an lvalue Chris@16: //! of type value_type. Chris@16: //! Chris@16: //! Effects: Inserts a each element of a range into the container Chris@16: //! before the upper bound of the key of each element. Chris@16: //! Chris@16: //! Complexity: Insert range is in general O(N * log(N)), where N is the Chris@16: //! size of the range. However, it is linear in N if the range is already sorted Chris@16: //! by value_comp(). Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. Chris@16: //! 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: template Chris@16: void insert_equal(Iterator b, Iterator e) Chris@16: { Chris@16: iterator iend(this->end()); Chris@16: for (; b != e; ++b) Chris@16: this->insert_equal(iend, *b); Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue Chris@16: //! Chris@16: //! Effects: Inserts value into the container if the value Chris@16: //! is not already present. Chris@16: //! Chris@16: //! Complexity: Average complexity for insert element is at Chris@16: //! most logarithmic. Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. Chris@16: //! 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_unique(reference value) Chris@16: { Chris@16: insert_commit_data commit_data; Chris@16: std::pair ret = insert_unique_check(value, this->value_comp(), this->priv_pcomp(), commit_data); Chris@16: if(!ret.second) Chris@16: return ret; Chris@16: return std::pair (insert_unique_commit(value, commit_data), true); Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue, and "hint" must be Chris@16: //! a valid iterator Chris@16: //! Chris@16: //! Effects: Tries to insert x into the container, using "hint" as a hint Chris@16: //! to where it will be inserted. Chris@16: //! Chris@16: //! Complexity: Logarithmic in general, but it is amortized Chris@16: //! constant time (two comparisons in the worst case) Chris@16: //! if t is inserted immediately before hint. Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. Chris@16: //! 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_unique(const_iterator hint, reference value) Chris@16: { Chris@16: insert_commit_data commit_data; Chris@16: std::pair ret = insert_unique_check(hint, value, this->value_comp(), this->priv_pcomp(), commit_data); Chris@16: if(!ret.second) Chris@16: return ret.first; Chris@16: return insert_unique_commit(value, commit_data); Chris@16: } Chris@16: Chris@16: //! Requires: Dereferencing iterator must yield an lvalue Chris@16: //! of type value_type. Chris@16: //! Chris@16: //! Effects: Tries to insert each element of a range into the container. Chris@16: //! Chris@16: //! Complexity: Insert range is in general O(N * log(N)), where N is the Chris@16: //! size of the range. However, it is linear in N if the range is already sorted Chris@16: //! by value_comp(). Chris@16: //! Chris@16: //! Throws: If the internal value_compare or priority_compare functions throw. Chris@16: //! 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: template Chris@16: void insert_unique(Iterator b, Iterator e) Chris@16: { Chris@16: if(this->empty()){ Chris@16: iterator iend(this->end()); Chris@16: for (; b != e; ++b) Chris@16: this->insert_unique(iend, *b); Chris@16: } Chris@16: else{ Chris@16: for (; b != e; ++b) Chris@16: this->insert_unique(*b); Chris@16: } Chris@16: } Chris@16: Chris@16: //! Requires: key_value_comp must be a comparison function that induces Chris@16: //! the same strict weak ordering as value_compare. Chris@16: //! key_value_pcomp must be a comparison function that induces Chris@16: //! the same strict weak ordering as priority_compare. The difference is that Chris@16: //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Checks if a value can be inserted in the container, 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 complexity is at most logarithmic. Chris@16: //! Chris@16: //! Throws: If the key_value_comp or key_value_pcomp Chris@16: //! ordering functions 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 order is much cheaper to construct Chris@16: //! than the value_type and this function offers the possibility to use that Chris@16: //! 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. This gives a total Chris@16: //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). 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 container. Chris@16: template Chris@16: std::pair insert_unique_check Chris@16: ( const KeyType &key, KeyValueCompare key_value_comp Chris@16: , KeyValuePrioCompare key_value_pcomp, insert_commit_data &commit_data) Chris@16: { Chris@101: detail::key_nodeptr_comp Chris@101: ocomp(key_value_comp, &this->get_value_traits()); Chris@101: detail::key_nodeptr_comp Chris@101: pcomp(key_value_pcomp, &this->get_value_traits()); Chris@16: std::pair ret = Chris@16: (node_algorithms::insert_unique_check Chris@16: (this->tree_type::header_ptr(), key, ocomp, pcomp, commit_data)); Chris@101: return std::pair(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); Chris@16: } Chris@16: Chris@16: //! Requires: key_value_comp must be a comparison function that induces Chris@16: //! the same strict weak ordering as value_compare. Chris@16: //! key_value_pcomp must be a comparison function that induces Chris@16: //! the same strict weak ordering as priority_compare. The difference is that Chris@16: //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values. Chris@16: //! Chris@16: //! Effects: Checks if a value can be inserted in the container, using Chris@16: //! a user provided key instead of the value itself, using "hint" Chris@16: //! as a hint to where it will be inserted. 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: Logarithmic in general, but it's amortized Chris@16: //! constant time if t is inserted immediately before hint. Chris@16: //! Chris@16: //! Throws: If the key_value_comp or key_value_pcomp Chris@16: //! ordering functions 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: //! constructing that is used to impose the order is much cheaper to construct Chris@16: //! than the value_type and this function offers the possibility to use that key Chris@16: //! 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. This can give a total Chris@16: //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). 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 container. Chris@16: template Chris@16: std::pair insert_unique_check Chris@16: ( const_iterator hint, const KeyType &key Chris@16: , KeyValueCompare key_value_comp Chris@16: , KeyValuePrioCompare key_value_pcomp Chris@16: , insert_commit_data &commit_data) Chris@16: { Chris@101: detail::key_nodeptr_comp Chris@101: ocomp(key_value_comp, &this->get_value_traits()); Chris@101: detail::key_nodeptr_comp Chris@101: pcomp(key_value_pcomp, &this->get_value_traits()); Chris@16: std::pair ret = Chris@16: (node_algorithms::insert_unique_check Chris@16: (this->tree_type::header_ptr(), hint.pointed_node(), key, ocomp, pcomp, commit_data)); Chris@101: return std::pair(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); Chris@16: } 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 container 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 avl_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: iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) Chris@16: { Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@16: node_algorithms::insert_unique_commit(this->tree_type::header_ptr(), to_insert, commit_data); Chris@16: this->tree_type::sz_traits().increment(); Chris@101: return iterator(to_insert, this->priv_value_traits_ptr()); Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue, "pos" must be Chris@16: //! a valid iterator (or end) and must be the succesor of value Chris@16: //! once inserted according to the predicate Chris@16: //! Chris@16: //! Effects: Inserts x into the container before "pos". Chris@16: //! Chris@16: //! Complexity: Constant time. Chris@16: //! Chris@16: //! Throws: If the internal priority_compare function throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: This function does not check preconditions so if "pos" is not Chris@16: //! the successor of "value" container ordering invariant will be broken. Chris@16: //! This is a low-level function to be used only for performance reasons Chris@16: //! by advanced users. Chris@16: iterator insert_before(const_iterator pos, reference value) Chris@16: { Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@101: detail::key_nodeptr_comp Chris@101: pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@16: iterator ret (node_algorithms::insert_before Chris@101: (this->tree_type::header_ptr(), pos.pointed_node(), to_insert, pcomp), this->priv_value_traits_ptr()); Chris@16: this->tree_type::sz_traits().increment(); Chris@16: return ret; Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue, and it must be no less Chris@16: //! than the greatest inserted key Chris@16: //! Chris@16: //! Effects: Inserts x into the container in the last position. Chris@16: //! Chris@16: //! Complexity: Constant time. Chris@16: //! Chris@16: //! Throws: If the internal priority_compare function throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: This function does not check preconditions so if value is Chris@16: //! less than the greatest inserted key container ordering invariant will be broken. Chris@16: //! This function is slightly more efficient than using "insert_before". Chris@16: //! This is a low-level function to be used only for performance reasons Chris@16: //! by advanced users. Chris@16: void push_back(reference value) Chris@16: { Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@101: detail::key_nodeptr_comp Chris@101: pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@16: node_algorithms::push_back(this->tree_type::header_ptr(), to_insert, pcomp); Chris@16: this->tree_type::sz_traits().increment(); Chris@16: } Chris@16: Chris@16: //! Requires: value must be an lvalue, and it must be no greater Chris@16: //! than the minimum inserted key Chris@16: //! Chris@16: //! Effects: Inserts x into the container in the first position. Chris@16: //! Chris@16: //! Complexity: Constant time. Chris@16: //! Chris@16: //! Throws: If the internal priority_compare function throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: This function does not check preconditions so if value is Chris@16: //! greater than the minimum inserted key container ordering invariant will be broken. Chris@16: //! This function is slightly more efficient than using "insert_before". Chris@16: //! This is a low-level function to be used only for performance reasons Chris@16: //! by advanced users. Chris@16: void push_front(reference value) Chris@16: { Chris@101: node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); Chris@101: detail::key_nodeptr_comp Chris@101: pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@16: node_algorithms::push_front(this->tree_type::header_ptr(), to_insert, pcomp); Chris@16: this->tree_type::sz_traits().increment(); Chris@16: } Chris@16: Chris@101: //! Effects: Erases the element pointed to by i. Chris@16: //! Chris@16: //! Complexity: Average complexity for erase element is constant time. Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Strong 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: iterator erase(const_iterator i) Chris@16: { Chris@16: const_iterator ret(i); Chris@16: ++ret; Chris@16: node_ptr to_erase(i.pointed_node()); Chris@16: if(safemode_or_autounlink) Chris@16: BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); Chris@101: detail::key_nodeptr_comp Chris@101: key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); Chris@16: node_algorithms::erase(this->tree_type::header_ptr(), to_erase, key_node_pcomp); Chris@16: this->tree_type::sz_traits().decrement(); Chris@16: if(safemode_or_autounlink) Chris@16: node_algorithms::init(to_erase); Chris@16: return ret.unconst(); Chris@16: } Chris@16: Chris@16: //! Effects: Erases the range pointed to by b end e. Chris@16: //! Chris@16: //! Complexity: Average complexity for erase range is at most Chris@16: //! O(log(size() + N)), where N is the number of elements in the range. Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Strong 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: iterator erase(const_iterator b, const_iterator e) Chris@16: { size_type n; return private_erase(b, e, n); } 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: O(log(size() + N). Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Strong 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 this->erase(value, this->value_comp()); } Chris@16: Chris@16: //! Effects: Erases all the elements with the given key. Chris@16: //! according to the comparison functor "comp". Chris@16: //! Chris@16: //! Returns: The number of erased elements. Chris@16: //! Chris@16: //! Complexity: O(log(size() + N). Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Chris@16: //! Equivalent guarantee to while(beg != end) erase(beg++); 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, KeyValueCompare comp Chris@16: /// @cond Chris@16: , typename detail::enable_if_c::value >::type * = 0 Chris@16: /// @endcond Chris@16: ) Chris@16: { Chris@16: std::pair p = this->equal_range(key, comp); Chris@16: size_type n; Chris@16: private_erase(p.first, p.second, n); Chris@16: return n; Chris@16: } Chris@16: Chris@16: //! Requires: Disposer::operator()(pointer) shouldn't throw. Chris@16: //! Chris@101: //! 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 complexity for erase element is constant time. Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: iterator erase_and_dispose(const_iterator i, Disposer disposer) Chris@16: { Chris@16: node_ptr to_erase(i.pointed_node()); Chris@16: iterator ret(this->erase(i)); Chris@101: disposer(this->get_value_traits().to_value_ptr(to_erase)); Chris@16: return ret; Chris@16: } Chris@16: Chris@16: #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: template Chris@16: iterator erase_and_dispose(iterator i, Disposer disposer) Chris@16: { return 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@16: //! Complexity: Average complexity for erase range is at most Chris@16: //! O(log(size() + N)), where N is the number of elements in the range. Chris@16: //! Chris@16: //! Throws: if the internal priority_compare function throws. Strong guarantee. Chris@16: //! Chris@16: //! Note: Invalidates the iterators Chris@16: //! to the erased elements. Chris@16: template Chris@16: iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) Chris@16: { size_type n; return private_erase(b, e, n, 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: O(log(size() + N). Chris@16: //! Chris@16: //! Throws: if the priority_compare function throws then weak guarantee and heap invariants are broken. Chris@16: //! The safest thing would be to clear or destroy the container. 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: { Chris@16: std::pair p = this->equal_range(value); Chris@16: size_type n; Chris@16: private_erase(p.first, p.second, n, disposer); Chris@16: return n; Chris@16: } 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 "comp". 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: O(log(size() + N). Chris@16: //! Chris@16: //! Throws: if the priority_compare function throws then weak guarantee and heap invariants are broken. Chris@16: //! The safest thing would be to clear or destroy the container. 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, KeyValueCompare comp, Disposer disposer Chris@16: /// @cond Chris@16: , typename detail::enable_if_c::value >::type * = 0 Chris@16: /// @endcond Chris@16: ) Chris@16: { Chris@16: std::pair p = this->equal_range(key, comp); Chris@16: size_type n; Chris@16: private_erase(p.first, p.second, n, disposer); Chris@16: return n; Chris@16: } 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: { tree_type::clear(); } Chris@16: Chris@16: //! Effects: Erases all of the elements calling disposer(p) for Chris@16: //! each node to be erased. Chris@16: //! Complexity: Average complexity for is at most O(log(size() + N)), Chris@16: //! where N is the number of elements in the container. Chris@16: //! Chris@16: //! Throws: Nothing. Chris@16: //! Chris@16: //! Note: Invalidates the iterators (but not the references) Chris@16: //! to the erased elements. Calls N times to disposer functor. Chris@16: template Chris@16: void clear_and_dispose(Disposer disposer) Chris@16: { Chris@16: node_algorithms::clear_and_dispose(this->tree_type::header_ptr() Chris@101: , detail::node_disposer(disposer, &this->get_value_traits())); Chris@16: node_algorithms::init_header(this->tree_type::header_ptr()); Chris@16: this->tree_type::sz_traits().set_size(0); Chris@16: } Chris@16: Chris@101: //! @copydoc ::boost::intrusive::bstree::check(ExtraChecker)const Chris@101: template Chris@101: void check(ExtraChecker extra_checker) const Chris@101: { Chris@101: typedef detail::key_nodeptr_comp nodeptr_prio_comp_t; Chris@101: nodeptr_prio_comp_t nodeptr_prio_comp(priv_pcomp(), &this->get_value_traits()); Chris@101: tree_type::check(detail::treap_node_extra_checker(nodeptr_prio_comp, extra_checker)); Chris@101: } Chris@101: Chris@101: //! @copydoc ::boost::intrusive::bstree::check()const Chris@101: void check() const Chris@101: { check(detail::empty_node_checker()); } Chris@101: Chris@16: #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: //! @copydoc ::boost::intrusive::bstree::count(const_reference)const Chris@16: size_type count(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const Chris@16: template Chris@16: size_type count(const KeyType& key, KeyValueCompare comp) const; Chris@101: Chris@16: //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) Chris@16: iterator lower_bound(const_reference value); Chris@101: Chris@16: //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) Chris@16: template Chris@16: iterator lower_bound(const KeyType& key, KeyValueCompare comp); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const Chris@16: const_iterator lower_bound(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const Chris@16: template Chris@16: const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) Chris@16: iterator upper_bound(const_reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) Chris@16: template Chris@16: iterator upper_bound(const KeyType& key, KeyValueCompare comp); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const Chris@16: const_iterator upper_bound(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const Chris@16: template Chris@16: const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::find(const_reference) Chris@16: iterator find(const_reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) Chris@16: template Chris@16: iterator find(const KeyType& key, KeyValueCompare comp); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::find(const_reference)const Chris@16: const_iterator find(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const Chris@16: template Chris@16: const_iterator find(const KeyType& key, KeyValueCompare comp) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) Chris@16: std::pair equal_range(const_reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) Chris@16: template Chris@16: std::pair equal_range(const KeyType& key, KeyValueCompare comp); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const Chris@16: std::pair Chris@16: equal_range(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const Chris@16: template Chris@16: std::pair Chris@16: equal_range(const KeyType& key, KeyValueCompare comp) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) Chris@16: std::pair bounded_range Chris@16: (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) Chris@16: template Chris@16: std::pair bounded_range Chris@16: (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const Chris@16: std::pair Chris@16: bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const Chris@16: template Chris@16: std::pair bounded_range Chris@16: (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) Chris@16: static iterator s_iterator_to(reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) Chris@16: static const_iterator s_iterator_to(const_reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) Chris@16: iterator iterator_to(reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const Chris@16: const_iterator iterator_to(const_reference value) const; Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::init_node(reference) Chris@16: static void init_node(reference value); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance Chris@16: pointer unlink_leftmost_without_rebalance(); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::replace_node Chris@16: void replace_node(iterator replace_this, reference with_this); Chris@16: Chris@16: //! @copydoc ::boost::intrusive::bstree::remove_node Chris@16: void remove_node(reference value); Chris@16: Chris@16: #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: /// @cond Chris@16: private: Chris@16: template Chris@16: iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer) Chris@16: { Chris@16: for(n = 0; b != e; ++n) Chris@16: this->erase_and_dispose(b++, disposer); Chris@16: return b.unconst(); Chris@16: } Chris@16: Chris@16: iterator private_erase(const_iterator b, const_iterator e, size_type &n) Chris@16: { Chris@16: for(n = 0; b != e; ++n) Chris@16: this->erase(b++); Chris@16: return b.unconst(); Chris@16: } Chris@16: /// @endcond Chris@16: }; Chris@16: Chris@16: #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: Chris@16: template Chris@16: bool operator< (const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: bool operator==(const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: bool operator!= (const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: bool operator>(const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: bool operator<=(const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: bool operator>=(const treap_impl &x, const treap_impl &y); Chris@16: Chris@16: template Chris@16: void swap(treap_impl &x, treap_impl &y); Chris@16: Chris@16: #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) Chris@16: Chris@16: //! Helper metafunction to define a \c treap 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_treap Chris@16: { Chris@16: typedef typename pack_options Chris@16: < treap_defaults, Chris@16: #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) Chris@101: O1, O2, O3, O4, O5 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@16: typedef treap_impl Chris@16: < value_traits Chris@16: , typename packed_options::compare Chris@16: , typename packed_options::priority Chris@16: , typename packed_options::size_type Chris@16: , packed_options::constant_time_size Chris@101: , typename packed_options::header_holder_type Chris@16: > implementation_defined; 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@101: template Chris@16: #else Chris@16: template Chris@16: #endif Chris@16: class treap Chris@16: : public make_treap::type Chris@16: { Chris@16: typedef typename make_treap Chris@16: ::type Base; Chris@16: BOOST_MOVABLE_BUT_NOT_COPYABLE(treap) Chris@16: Chris@16: public: Chris@16: typedef typename Base::value_compare value_compare; Chris@16: typedef typename Base::priority_compare priority_compare; Chris@16: typedef typename Base::value_traits value_traits; Chris@16: typedef typename Base::iterator iterator; Chris@16: typedef typename Base::const_iterator const_iterator; Chris@16: typedef typename Base::reverse_iterator reverse_iterator; Chris@16: typedef typename Base::const_reverse_iterator const_reverse_iterator; Chris@16: Chris@16: //Assert if passed value traits are compatible with the type Chris@101: BOOST_STATIC_ASSERT((detail::is_same::value)); Chris@16: Chris@16: explicit treap( const value_compare &cmp = value_compare() Chris@16: , const priority_compare &pcmp = priority_compare() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(cmp, pcmp, v_traits) Chris@16: {} Chris@16: Chris@16: template Chris@16: treap( bool unique, Iterator b, Iterator e Chris@16: , const value_compare &cmp = value_compare() Chris@16: , const priority_compare &pcmp = priority_compare() Chris@16: , const value_traits &v_traits = value_traits()) Chris@16: : Base(unique, b, e, cmp, pcmp, v_traits) Chris@16: {} Chris@16: Chris@16: treap(BOOST_RV_REF(treap) x) Chris@101: : Base(BOOST_MOVE_BASE(Base, x)) Chris@16: {} Chris@16: Chris@16: treap& operator=(BOOST_RV_REF(treap) x) Chris@101: { return static_cast(this->Base::operator=(BOOST_MOVE_BASE(Base, x))); } Chris@16: Chris@16: static treap &container_from_end_iterator(iterator end_iterator) Chris@16: { return static_cast(Base::container_from_end_iterator(end_iterator)); } Chris@16: Chris@16: static const treap &container_from_end_iterator(const_iterator end_iterator) Chris@16: { return static_cast(Base::container_from_end_iterator(end_iterator)); } Chris@16: Chris@16: static treap &container_from_iterator(iterator it) Chris@16: { return static_cast(Base::container_from_iterator(it)); } Chris@16: Chris@16: static const treap &container_from_iterator(const_iterator it) Chris@16: { return static_cast(Base::container_from_iterator(it)); } 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_TREAP_HPP