diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/intrusive | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/intrusive')
93 files changed, 17241 insertions, 26947 deletions
diff --git a/boost/intrusive/any_hook.hpp b/boost/intrusive/any_hook.hpp index 7d60de001a..1b538373d9 100644 --- a/boost/intrusive/any_hook.hpp +++ b/boost/intrusive/any_hook.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,31 +13,27 @@ #ifndef BOOST_INTRUSIVE_ANY_HOOK_HPP #define BOOST_INTRUSIVE_ANY_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> #include <boost/intrusive/detail/any_node_and_algorithms.hpp> #include <boost/intrusive/options.hpp> #include <boost/intrusive/detail/generic_hook.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/pointer_rebind.hpp> namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer> -struct get_any_node_algo -{ - typedef any_algorithms<VoidPointer> type; -}; -/// @endcond - //! Helper metafunction to define a \c \c any_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_any_base_hook { @@ -51,11 +47,11 @@ struct make_any_base_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_any_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < any_algorithms<typename packed_options::void_pointer> , typename packed_options::tag , packed_options::link_mode - , detail::AnyBaseHook + , AnyBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -75,7 +71,7 @@ struct make_any_base_hook //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else @@ -142,7 +138,7 @@ class any_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_any_member_hook { @@ -156,11 +152,11 @@ struct make_any_member_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_any_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < any_algorithms<typename packed_options::void_pointer> , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -175,7 +171,7 @@ struct make_any_member_hook //! \c link_mode<> will specify the linking mode of the hook (\c normal_link or \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else @@ -241,38 +237,34 @@ class any_member_hook namespace detail{ -template<class ValueTraits> -struct any_to_get_base_pointer_type -{ - typedef typename pointer_traits<typename ValueTraits::boost_intrusive_tags::node_traits::node_ptr>::template - rebind_pointer<void>::type type; -}; - -template<class ValueTraits> -struct any_to_get_member_pointer_type -{ - typedef typename pointer_traits - <typename ValueTraits::node_ptr>::template rebind_pointer<void>::type type; -}; +BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(old_proto_value_traits_base_hook, hooktags::is_base_hook) //!This option setter specifies that the container //!must use the specified base hook -template<class BaseHook, template <class> class NodeTraits> +template<class BasicHook, template <class> class NodeTraits> struct any_to_some_hook { - typedef typename BaseHook::template pack<none>::value_traits old_value_traits; + typedef typename BasicHook::template pack<empty>::proto_value_traits old_proto_value_traits; + template<class Base> struct pack : public Base { - struct value_traits : public old_value_traits + struct proto_value_traits { + //proto_value_traits::hooktags::is_base_hook is used by get_value_traits + //to detect base hooks, so mark it in case BasicHook has it. + struct hooktags + { + static const bool is_base_hook = old_proto_value_traits_base_hook_bool_is_true + <old_proto_value_traits>::value; + }; + + typedef old_proto_value_traits basic_hook_t; static const bool is_any_hook = true; - typedef typename detail::eval_if_c - < detail::internal_base_hook_bool_is_true<old_value_traits>::value - , any_to_get_base_pointer_type<old_value_traits> - , any_to_get_member_pointer_type<old_value_traits> - >::type void_pointer; - typedef NodeTraits<void_pointer> node_traits; + + template<class VoidPtr> + struct node_traits_from_voidptr + { typedef NodeTraits<VoidPtr> type; }; }; }; }; @@ -283,55 +275,55 @@ struct any_to_some_hook //!This option setter specifies that //!any hook should behave as an slist hook -template<class BaseHook> +template<class BasicHook> struct any_to_slist_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_slist_node_traits> + : public detail::any_to_some_hook<BasicHook, any_slist_node_traits> /// @endcond {}; //!This option setter specifies that //!any hook should behave as an list hook -template<class BaseHook> +template<class BasicHook> struct any_to_list_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_list_node_traits> + : public detail::any_to_some_hook<BasicHook, any_list_node_traits> /// @endcond {}; //!This option setter specifies that //!any hook should behave as a set hook -template<class BaseHook> +template<class BasicHook> struct any_to_set_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_rbtree_node_traits> + : public detail::any_to_some_hook<BasicHook, any_rbtree_node_traits> /// @endcond {}; //!This option setter specifies that //!any hook should behave as an avl_set hook -template<class BaseHook> +template<class BasicHook> struct any_to_avl_set_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_avltree_node_traits> + : public detail::any_to_some_hook<BasicHook, any_avltree_node_traits> /// @endcond {}; //!This option setter specifies that any //!hook should behave as a bs_set hook -template<class BaseHook> +template<class BasicHook> struct any_to_bs_set_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_tree_node_traits> + : public detail::any_to_some_hook<BasicHook, any_tree_node_traits> /// @endcond {}; //!This option setter specifies that any hook //!should behave as an unordered set hook -template<class BaseHook> +template<class BasicHook> struct any_to_unordered_set_hook /// @cond - : public detail::any_to_some_hook<BaseHook, any_unordered_node_traits> + : public detail::any_to_some_hook<BasicHook, any_unordered_node_traits> /// @endcond {}; diff --git a/boost/intrusive/avl_set.hpp b/boost/intrusive/avl_set.hpp index 91e2dbbdf0..58d6108f95 100644 --- a/boost/intrusive/avl_set.hpp +++ b/boost/intrusive/avl_set.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,12 +12,16 @@ #ifndef BOOST_INTRUSIVE_AVL_SET_HPP #define BOOST_INTRUSIVE_AVL_SET_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/avltree.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/move/move.hpp> -#include <iterator> +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { @@ -36,14 +40,15 @@ namespace intrusive { #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class avl_set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder> +#endif { /// @cond - typedef avltree_impl<Config> tree_type; - //! This class is - //! movable + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(avl_set_impl) typedef tree_type implementation_defined; @@ -71,1208 +76,385 @@ class avl_set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare object throws. - avl_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + + //! @copydoc ::boost::intrusive::avltree::avltree(const value_compare &,const value_traits &) + explicit avl_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty avl_set and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is std::distance(last, first). - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::avltree::avltree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> avl_set_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(true, b, e, cmp, v_traits) + : tree_type(true, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::avltree::avltree(avltree &&) avl_set_impl(BOOST_RV_REF(avl_set_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::avltree::operator=(avltree &&) avl_set_impl& operator=(BOOST_RV_REF(avl_set_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the avl_set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~avl_set_impl() - {} + { return static_cast<avl_set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::~avltree() + ~avl_set_impl(); + + //! @copydoc ::boost::intrusive::avltree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::avltree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::avltree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::avltree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::avltree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::avltree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::avltree::begin() + reverse_iterator avlegin(); + + //! @copydoc ::boost::intrusive::avltree::begin()const + const_reverse_iterator avlegin() const; + + //! @copydoc ::boost::intrusive::avltree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::avltree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::avltree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::avltree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::avltree::container_from_end_iterator(iterator) + static avl_set_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::avltree::container_from_end_iterator(const_iterator) + static const avl_set_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::avltree::container_from_iterator(iterator) + static avl_set_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::avltree::container_from_iterator(const_iterator) + static const avl_set_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::avltree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::avltree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::avltree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::avltree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::avltree::swap + void swap(avl_set_impl& other); - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of avl_set. - //! - //! <b>Effects</b>: Returns a const reference to the avl_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static avl_set_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<avl_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &avl_set_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of avl_set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const avl_set_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<avl_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &avl_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static avl_set_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<avl_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &avl_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const avl_set_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<avl_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &avl_set_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the avl_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true is the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the avl_set. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two sets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(avl_set_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::avltree::clone_from template <class Cloner, class Disposer> - void clone_from(const avl_set_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Treaps to inserts value into the avl_set. - //! - //! <b>Returns</b>: If the value - //! is not already present inserts it and returns a pair containing the - //! iterator to the new value and true. If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const avl_set_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::insert_unique(reference) std::pair<iterator, bool> insert(reference value) - { return tree_.insert_unique(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Treaps to to insert x into the avl_set, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the - //! new element was inserted into the avl_set. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique(value); } + + //! @copydoc ::boost::intrusive::avltree::insert_unique(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_unique(hint, value); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the avl_set, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the avl_set. + { return tree_type::insert_unique(hint, value); } + + //! @copydoc ::boost::intrusive::avltree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(key, key_value_comp, commit_data); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the avl_set, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the avl_set. + { return tree_type::insert_unique_check(key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::avltree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const_iterator hint, const KeyType &key ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the avl_set between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return tree_.insert_unique_commit(value, commit_data); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the avl_set. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique_check(hint, key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::avltree::insert_unique(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_unique(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate. "value" must not be equal to any - //! inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" or "value" is not unique tree ordering and uniqueness - //! invariants will be broken respectively. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be greater than - //! any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than or equal to the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be less - //! than any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than or equal to the the mimum inserted key tree ordering or uniqueness - //! invariants will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size()) + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_unique(b, e); } + + //! @copydoc ::boost::intrusive::avltree::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::avltree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::avltree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::avltree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::avltree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::avltree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::avltree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::clear + void clear(); + + //! @copydoc ::boost::intrusive::avltree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + void clear_and_dispose(Disposer disposer); + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::count(const_reference)const size_type count(const_reference value) const - { return tree_.find(value) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + { return static_cast<size_type>(this->tree_type::find(value) != this->tree_type::cend()); } + + //! @copydoc ::boost::intrusive::avltree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp) != end(); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + { return this->tree_type::lower_bound_range(key, comp); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + { return this->tree_type::lower_bound_range(key, comp); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! avl_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! avl_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a avl_set/avl_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const avl_set_impl &x, const avl_set_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::avltree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const avl_set_impl &x, const avl_set_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::avltree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::avltree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::avltree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::avltree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::avltree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y) -#else -(const avl_set_impl<Config> &x, const avl_set_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y) -#else -(const avl_set_impl<Config> &x, const avl_set_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y) -#else -(const avl_set_impl<Config> &x, const avl_set_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y) -#else -(const avl_set_impl<Config> &x, const avl_set_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const avl_set_impl<T, Options...> &x, const avl_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(avl_set_impl<T, Options...> &x, avl_set_impl<T, Options...> &y) -#else -(avl_set_impl<Config> &x, avl_set_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(avl_set_impl<T, Options...> &x, avl_set_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -//! Helper metafunction to define a \c avl_set that yields to the same type when the +//! Helper metafunction to define a \c set that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_avl_set { /// @cond - typedef avl_set_impl - < typename make_avltree_opt + typedef typename pack_options + < avltree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> + O1, O2, O3, O4, O5 #else - <T, Options...> + Options... #endif - ::type - > implementation_defined; + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef avl_set_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class avl_set - : public make_avl_set - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> - #else - <T, Options...> - #endif - ::type + : public make_avl_set<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type { typedef typename make_avl_set + <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> + O1, O2, O3, O4, O5 #else - <T, Options...> + Options... #endif - ::type Base; + >::type Base; BOOST_MOVABLE_BUT_NOT_COPYABLE(avl_set) public: @@ -1284,8 +466,8 @@ class avl_set //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - avl_set( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avl_set( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1301,7 +483,7 @@ class avl_set {} avl_set& operator=(BOOST_RV_REF(avl_set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<avl_set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static avl_set &container_from_end_iterator(iterator end_iterator) { return static_cast<avl_set &>(Base::container_from_end_iterator(end_iterator)); } @@ -1309,17 +491,17 @@ class avl_set static const avl_set &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const avl_set &>(Base::container_from_end_iterator(end_iterator)); } - static avl_set &container_from_iterator(iterator end_iterator) - { return static_cast<avl_set &>(Base::container_from_iterator(end_iterator)); } + static avl_set &container_from_iterator(iterator it) + { return static_cast<avl_set &>(Base::container_from_iterator(it)); } - static const avl_set &container_from_iterator(const_iterator end_iterator) - { return static_cast<const avl_set &>(Base::container_from_iterator(end_iterator)); } + static const avl_set &container_from_iterator(const_iterator it) + { return static_cast<const avl_set &>(Base::container_from_iterator(it)); } }; #endif //! The class template avl_multiset is an intrusive container, that mimics most of -//! the interface of std::avl_multiset as described in the C++ standard. +//! the interface of std::_multiset as described in the C++ standard. //! //! The template parameter \c T is the type to be managed by the container. //! The user can specify additional options and if no options are provided @@ -1332,14 +514,16 @@ class avl_set #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class avl_multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder> +#endif { /// @cond - typedef avltree_impl<Config> tree_type; + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder> tree_type; - //Movable BOOST_MOVABLE_BUT_NOT_COPYABLE(avl_multiset_impl) typedef tree_type implementation_defined; /// @endcond @@ -1366,1088 +550,325 @@ class avl_multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. - avl_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::avltree::avltree(const value_compare &,const value_traits &) + explicit avl_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty avl_multiset and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::avltree::avltree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> avl_multiset_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(false, b, e, cmp, v_traits) + : tree_type(false, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::avltree::avltree(avltree &&) avl_multiset_impl(BOOST_RV_REF(avl_multiset_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::avltree::operator=(avltree &&) avl_multiset_impl& operator=(BOOST_RV_REF(avl_multiset_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the avl_multiset - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~avl_multiset_impl() - {} + { return static_cast<avl_multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::avltree::~avltree() + ~avl_multiset_impl(); + + //! @copydoc ::boost::intrusive::avltree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::avltree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::avltree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::avltree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::avltree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::avltree::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of avl_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static avl_multiset_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<avl_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &avl_multiset_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of avl_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the avl_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const avl_multiset_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<avl_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &avl_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static avl_multiset_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<avl_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &avl_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const avl_multiset_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<avl_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &avl_multiset_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the avl_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true is the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the avl_multiset. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two avl_multisets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(avl_multiset_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::avltree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::avltree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::avltree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::avltree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::avltree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::avltree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::avltree::container_from_end_iterator(iterator) + static avl_multiset_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::avltree::container_from_end_iterator(const_iterator) + static const avl_multiset_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::avltree::container_from_iterator(iterator) + static avl_multiset_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::avltree::container_from_iterator(const_iterator) + static const avl_multiset_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::avltree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::avltree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::avltree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::avltree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::avltree::swap + void swap(avl_multiset_impl& other); + + //! @copydoc ::boost::intrusive::avltree::clone_from template <class Cloner, class Disposer> - void clone_from(const avl_multiset_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the avl_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const avl_multiset_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::avltree::insert_equal(reference) iterator insert(reference value) - { return tree_.insert_equal(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts x into the avl_multiset, using pos as a hint to - //! where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(value); } + + //! @copydoc ::boost::intrusive::avltree::insert_equal(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_equal(hint, value); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the avl_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(hint, value); } + + //! @copydoc ::boost::intrusive::avltree::insert_equal(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_equal(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate. "value" must not be equal to any - //! inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" or "value" is not unique tree ordering and uniqueness - //! invariants will be broken respectively. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be greater than - //! any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than or equal to the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be less - //! than any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than or equal to the the mimum inserted key tree ordering or uniqueness - //! invariants will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::avltree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::avltree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::avltree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::avltree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::avltree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::avltree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::clear + void clear(); + + //! @copydoc ::boost::intrusive::avltree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) const - { return tree_.count(value); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::avltree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.count(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::avltree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::avltree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! avl_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the avl_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a avl_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! avl_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a avl_multiset/avl_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const avl_multiset_impl &x, const avl_multiset_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::avltree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const avl_multiset_impl &x, const avl_multiset_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::avltree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::avltree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::avltree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::avltree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::avltree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::avltree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::avltree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y) -#else -(const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y) -#else -(const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y) -#else -(const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y) -#else -(const avl_multiset_impl<Config> &x, const avl_multiset_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const avl_multiset_impl<T, Options...> &x, const avl_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(avl_multiset_impl<T, Options...> &x, avl_multiset_impl<T, Options...> &y) -#else -(avl_multiset_impl<Config> &x, avl_multiset_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(avl_multiset_impl<T, Options...> &x, avl_multiset_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c avl_multiset that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_avl_multiset { /// @cond + typedef typename pack_options + < avltree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef avl_multiset_impl - < typename make_avltree_opt - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> - #else - <T, Options...> - #endif - ::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -2455,28 +876,29 @@ struct make_avl_multiset #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class avl_multiset : public make_avl_multiset<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type { - typedef typename make_avl_multiset + typedef typename make_avl_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> + O1, O2, O3, O4, O5 #else - <T, Options...> + Options... #endif - ::type Base; + >::type Base; BOOST_MOVABLE_BUT_NOT_COPYABLE(avl_multiset) + public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; @@ -2486,8 +908,8 @@ class avl_multiset //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - avl_multiset( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avl_multiset( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -2503,7 +925,7 @@ class avl_multiset {} avl_multiset& operator=(BOOST_RV_REF(avl_multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<avl_multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static avl_multiset &container_from_end_iterator(iterator end_iterator) { return static_cast<avl_multiset &>(Base::container_from_end_iterator(end_iterator)); } @@ -2511,11 +933,11 @@ class avl_multiset static const avl_multiset &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const avl_multiset &>(Base::container_from_end_iterator(end_iterator)); } - static avl_multiset &container_from_iterator(iterator end_iterator) - { return static_cast<avl_multiset &>(Base::container_from_iterator(end_iterator)); } + static avl_multiset &container_from_iterator(iterator it) + { return static_cast<avl_multiset &>(Base::container_from_iterator(it)); } - static const avl_multiset &container_from_iterator(const_iterator end_iterator) - { return static_cast<const avl_multiset &>(Base::container_from_iterator(end_iterator)); } + static const avl_multiset &container_from_iterator(const_iterator it) + { return static_cast<const avl_multiset &>(Base::container_from_iterator(it)); } }; #endif diff --git a/boost/intrusive/avl_set_hook.hpp b/boost/intrusive/avl_set_hook.hpp index 825921f509..6fdc51b707 100644 --- a/boost/intrusive/avl_set_hook.hpp +++ b/boost/intrusive/avl_set_hook.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,9 +13,13 @@ #ifndef BOOST_INTRUSIVE_AVL_SET_HOOK_HPP #define BOOST_INTRUSIVE_AVL_SET_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/detail/avltree_node.hpp> #include <boost/intrusive/avltree_algorithms.hpp> #include <boost/intrusive/options.hpp> @@ -24,20 +28,12 @@ namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer, bool OptimizeSize = false> -struct get_avl_set_node_algo -{ - typedef avltree_algorithms<avltree_node_traits<VoidPointer, OptimizeSize> > type; -}; -/// @endcond - //! Helper metafunction to define a \c avl_set_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_avl_set_base_hook { @@ -50,12 +46,11 @@ struct make_avl_set_base_hook #endif ::type packed_options; - typedef detail::generic_hook - < get_avl_set_node_algo<typename packed_options::void_pointer - ,packed_options::optimize_size> + typedef generic_hook + < avltree_algorithms<avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> > , typename packed_options::tag , packed_options::link_mode - , detail::AvlSetBaseHook + , AvlTreeBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -74,7 +69,7 @@ struct make_avl_set_base_hook //! unique tag. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). @@ -168,7 +163,7 @@ class avl_set_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_avl_set_member_hook { @@ -181,12 +176,11 @@ struct make_avl_set_member_hook #endif ::type packed_options; - typedef detail::generic_hook - < get_avl_set_node_algo<typename packed_options::void_pointer - ,packed_options::optimize_size> + typedef generic_hook + < avltree_algorithms<avltree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> > , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -200,7 +194,7 @@ struct make_avl_set_member_hook //! \c link_mode<> and \c optimize_size<>. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). diff --git a/boost/intrusive/avltree.hpp b/boost/intrusive/avltree.hpp index 84376a87c7..d2adf24917 100644 --- a/boost/intrusive/avltree.hpp +++ b/boost/intrusive/avltree.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,55 +12,50 @@ #ifndef BOOST_INTRUSIVE_AVLTREE_HPP #define BOOST_INTRUSIVE_AVLTREE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <algorithm> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> #include <functional> -#include <iterator> #include <utility> -#include <boost/intrusive/detail/assert.hpp> #include <boost/static_assert.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/avl_set_hook.hpp> #include <boost/intrusive/detail/avltree_node.hpp> +#include <boost/intrusive/bstree.hpp> #include <boost/intrusive/detail/tree_node.hpp> #include <boost/intrusive/detail/ebo_functor_holder.hpp> #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> -#include <boost/intrusive/options.hpp> -#include <boost/intrusive/detail/utilities.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> #include <boost/intrusive/avltree_algorithms.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/move/move.hpp> +#include <boost/move/utility_core.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize> -struct avl_setopt +struct default_avltree_hook_applier +{ template <class T> struct apply{ typedef typename T::default_avltree_hook type; }; }; + +template<> +struct is_default_hook_tag<default_avltree_hook_applier> +{ static const bool value = true; }; + +struct avltree_defaults { - typedef ValueTraits value_traits; - typedef Compare compare; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; + typedef default_avltree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + typedef void header_holder_type; }; -template <class T> -struct avl_set_defaults - : pack_options - < none - , base_hook<detail::default_avl_set_hook> - , constant_time_size<true> - , size_type<std::size_t> - , compare<std::less<T> > - >::type -{}; - /// @endcond //! The class template avltree is an intrusive AVL tree container, that @@ -79,1672 +74,441 @@ struct avl_set_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class avltree_impl - : private detail::clear_on_destructor_base<avltree_impl<Config> > + /// @cond + : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, AvlTreeAlgorithms, HeaderHolder> + /// @endcond { - template<class C> friend class detail::clear_on_destructor_base; public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; + typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType + , ConstantTimeSize, AvlTreeAlgorithms + , HeaderHolder> tree_type; + typedef tree_type implementation_defined; /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - typedef typename boost::intrusive:: - pointer_traits<pointer>::element_type value_type; - typedef value_type key_type; - typedef typename boost::intrusive:: - pointer_traits<pointer>::reference reference; - typedef typename boost::intrusive:: - pointer_traits<const_pointer>::reference const_reference; - typedef typename boost::intrusive:: - pointer_traits<pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef typename Config::compare value_compare; - typedef value_compare key_compare; - typedef tree_iterator<avltree_impl, false> iterator; - typedef tree_iterator<avltree_impl, true> const_iterator; - typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; - typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <const node>::type const_node_ptr; - typedef avltree_algorithms<node_traits> node_algorithms; - - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::store_cont_ptr_on_it<avltree_impl>::value; + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::key_type key_type; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef typename implementation_defined::node_algorithms node_algorithms; + + static const bool constant_time_size = implementation_defined::constant_time_size; /// @cond private: - typedef detail::size_holder<constant_time_size, size_type> size_traits; - //noncopyable, movable + //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; + /// @endcond - //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); + public: - struct header_plus_size : public size_traits - { node header_; }; + typedef typename implementation_defined::insert_commit_data insert_commit_data; - struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare> - { - node_plus_pred_t(const value_compare &comp) - : detail::ebo_functor_holder<value_compare>(comp) - {} - header_plus_size header_plus_size_; - }; - struct data_t : public avltree_impl::value_traits - { - typedef typename avltree_impl::value_traits value_traits; - data_t(const value_compare & comp, const value_traits &val_traits) - : value_traits(val_traits), node_plus_pred_(comp) - {} - node_plus_pred_t node_plus_pred_; - } data_; + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit avltree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} - const value_compare &priv_comp() const - { return data_.node_plus_pred_.get(); } + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) + template<class Iterator> + avltree_impl( bool unique, Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(unique, b, e, cmp, v_traits) + {} - value_compare &priv_comp() - { return data_.node_plus_pred_.get(); } + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) + avltree_impl(BOOST_RV_REF(avltree_impl) x) + : tree_type(::boost::move(static_cast<tree_type&>(x))) + {} - const value_traits &priv_value_traits() const - { return data_; } + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) + avltree_impl& operator=(BOOST_RV_REF(avltree_impl) x) + { return static_cast<avltree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - value_traits &priv_value_traits() - { return data_; } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - node_ptr priv_header_ptr() - { return pointer_traits<node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~avltree_impl(); - const_node_ptr priv_header_ptr() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; - size_traits &priv_size_traits() - { return data_.node_plus_pred_.header_plus_size_; } + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; - const size_traits &priv_size_traits() const - { return data_.node_plus_pred_.header_plus_size_; } + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; - /// @endcond + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; - public: + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - typedef typename node_algorithms::insert_commit_data insert_commit_data; - - //! <b>Effects</b>: Constructs an empty tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare object throws. Basic guarantee. - avltree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty tree and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee. - template<class Iterator> - avltree_impl( bool unique, Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - if(unique) - this->insert_unique(b, e); - else - this->insert_equal(b, e); - } - - //! <b>Effects</b>: to-do - //! - avltree_impl(BOOST_RV_REF(avltree_impl) x) - : data_(::boost::move(x.priv_comp()), ::boost::move(x.priv_value_traits())) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - this->swap(x); - } - - //! <b>Effects</b>: to-do - //! - avltree_impl& operator=(BOOST_RV_REF(avltree_impl) x) - { this->swap(x); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called), but the nodes according to - //! the value_traits template parameter are reinitialized and thus can be reused. - //! - //! <b>Complexity</b>: Linear to elements contained in *this. - //! - //! <b>Throws</b>: Nothing. - ~avltree_impl() - {} + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return iterator (node_traits::get_left(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return cbegin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return const_iterator (node_traits::get_left(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return iterator (this->priv_header_ptr(), this); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return cend(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return const_iterator (uncast(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return const_reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return const_reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return reverse_iterator(begin()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return const_reverse_iterator(begin()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return const_reverse_iterator(begin()); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of avltree. - //! - //! <b>Effects</b>: Returns a const reference to the avltree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static avltree_impl &container_from_end_iterator(iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of avltree. - //! - //! <b>Effects</b>: Returns a const reference to the avltree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const avltree_impl &container_from_end_iterator(const_iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } - - //! <b>Precondition</b>: it must be a valid iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static avltree_impl &container_from_iterator(iterator it) - { return priv_container_from_iterator(it); } - - //! <b>Precondition</b>: it must be a valid end const_iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const avltree_impl &container_from_iterator(const_iterator it) - { return priv_container_from_iterator(it); } - - //! <b>Effects</b>: Returns the value_compare object used by the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return priv_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return node_algorithms::unique(this->priv_header_ptr()); } - - //! <b>Effects</b>: Returns the number of elements stored in the tree. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { - if(constant_time_size) - return this->priv_size_traits().get_size(); - else{ - return (size_type)node_algorithms::size(this->priv_header_ptr()); - } - } - - //! <b>Effects</b>: Swaps the contents of two avltrees. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the comparison functor's swap call throws. - void swap(avltree_impl& other) - { - //This can throw - using std::swap; - swap(priv_comp(), priv_comp()); - //These can't throw - node_algorithms::swap_tree(this->priv_header_ptr(), other.priv_header_ptr()); - if(constant_time_size){ - size_type backup = this->priv_size_traits().get_size(); - this->priv_size_traits().set_size(other.priv_size_traits().get_size()); - other.priv_size_traits().set_size(backup); - } - } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree before the upper bound. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(reference value) - { - detail::key_nodeptr_comp<value_compare, avltree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_equal_upper_bound - (this->priv_header_ptr(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } - - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator. - //! - //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case) - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(const_iterator hint, reference value) - { - detail::key_nodeptr_comp<value_compare, avltree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_equal - (this->priv_header_ptr(), hint.pointed_node(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a each element of a range into the tree - //! before the upper bound of the key of each element. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - template<class Iterator> - void insert_equal(Iterator b, Iterator e) - { - iterator end(this->end()); - for (; b != e; ++b) - this->insert_equal(end, *b); - } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree if the value - //! is not already present. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - std::pair<iterator, bool> insert_unique(reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), commit_data); - if(!ret.second) - return ret; - return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true); - } - - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator - //! - //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint - //! to where it will be inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time (two comparisons in the worst case) - //! if t is inserted immediately before hint. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_unique(const_iterator hint, reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), commit_data); - if(!ret.second) - return ret.first; - return insert_unique_commit(value, commit_data); - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Tries to insert each element of a range into the tree. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static avltree_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const avltree_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static avltree_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const avltree_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::bstree::swap + void swap(avltree_impl& other); + + //! @copydoc ::boost::intrusive::bstree::clone_from + template <class Cloner, class Disposer> + void clone_from(const avltree_impl &src, Cloner cloner, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::insert_equal(reference) + iterator insert_equal(reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference) + iterator insert_equal(const_iterator hint, reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator) template<class Iterator> - void insert_unique(Iterator b, Iterator e) - { - if(this->empty()){ - iterator end(this->end()); - for (; b != e; ++b) - this->insert_unique(end, *b); - } - else{ - for (; b != e; ++b) - this->insert_unique(*b); - } - } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + void insert_equal(Iterator b, Iterator e); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(reference) + std::pair<iterator, bool> insert_unique(reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference) + iterator insert_unique(const_iterator hint, reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check - (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - (node_algorithms::insert_unique_check - (this->priv_header_ptr(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check (const_iterator hint, const KeyType &key - ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - (node_algorithms::insert_unique_check - (this->priv_header_ptr(), hint.pointed_node(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the container between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::insert_unique_commit - (this->priv_header_ptr(), to_insert, commit_data); - this->priv_size_traits().increment(); - return iterator(to_insert, this); - } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" tree ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_before - (this->priv_header_ptr(), pos.pointed_node(), to_insert), this); - this->priv_size_traits().increment(); - return ret; - } - - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::push_back(this->priv_header_ptr(), to_insert); - this->priv_size_traits().increment(); - } - - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::push_front(this->priv_header_ptr(), to_insert); - this->priv_size_traits().increment(); - } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { - const_iterator ret(i); - ++ret; - node_ptr to_erase(i.pointed_node()); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); - node_algorithms::erase(this->priv_header_ptr(), to_erase); - this->priv_size_traits().decrement(); - if(safemode_or_autounlink) - node_algorithms::init(to_erase); - return ret.unconst(); - } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { size_type n; return private_erase(b, e, n); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return this->erase(value, priv_comp()); } - - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_commit + iterator insert_unique_commit(reference value, const insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator) + template<class Iterator> + void insert_unique(Iterator b, Iterator e); + + //! @copydoc ::boost::intrusive::bstree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::bstree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::bstree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n); - return n; - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { - node_ptr to_erase(i.pointed_node()); - iterator ret(this->erase(i)); - disposer(get_real_value_traits().to_value_ptr(to_erase)); - return ret; - } - - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + size_type erase(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + iterator erase_and_dispose(const_iterator i, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { size_type n; return private_erase(b, e, n, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { - std::pair<iterator,iterator> p = this->equal_range(value); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } - - //! <b>Effects</b>: Erases all of the elements. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { - if(safemode_or_autounlink){ - this->clear_and_dispose(detail::null_disposer()); - } - else{ - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - } - - //! <b>Effects</b>: Erases all of the elements calling disposer(p) for - //! each node to be erased. - //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)), - //! where N is the number of elements in the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. Calls N times to disposer functor. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::clear + void clear(); + + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { - node_algorithms::clear_and_dispose(this->priv_header_ptr() - , detail::node_disposer<Disposer, avltree_impl>(disposer, this)); - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count(const_reference value) const - { return this->count(value, priv_comp()); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType &key, KeyValueCompare comp) const - { - std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); - return std::distance(ret.first, ret.second); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator lower_bound(const_reference value) - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator lower_bound(const_reference value) const - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator upper_bound(const_reference value) - { return this->upper_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator upper_bound(const_reference value) const - { return this->upper_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator find(const_reference value) - { return this->find(value, priv_comp()); } - - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator find(const_reference value) const - { return this->find(value, priv_comp()); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - return const_iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<iterator,iterator> equal_range(const_reference value) - { return this->equal_range(value, priv_comp()); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return this->equal_range(value, priv_comp()); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator,const_iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator,const_iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { - detail::key_nodeptr_comp<KeyValueCompare, avltree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const avltree_impl &src, Cloner cloner, Disposer disposer) - { - this->clear_and_dispose(disposer); - if(!src.empty()){ - detail::exception_disposer<avltree_impl, Disposer> - rollback(*this, disposer); - node_algorithms::clone - (src.priv_header_ptr() - ,this->priv_header_ptr() - ,detail::node_cloner<Cloner, avltree_impl>(cloner, this) - ,detail::node_disposer<Disposer, avltree_impl>(disposer, this)); - this->priv_size_traits().set_size(src.priv_size_traits().get_size()); - this->priv_comp() = src.priv_comp(); - rollback.release(); - } - } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { - node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance - (this->priv_header_ptr())); - if(!to_be_disposed) - return 0; - this->priv_size_traits().decrement(); - if(safemode_or_autounlink)//If this is commented does not work with normal_link - node_algorithms::init(to_be_disposed); - return get_real_value_traits().to_value_ptr(to_be_disposed); - } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { - node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this) - , this->priv_header_ptr() - , get_real_value_traits().to_node_ptr(with_this)); - if(safemode_or_autounlink) - node_algorithms::init(replace_this.pointed_node()); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return iterator (value_traits::to_node_ptr(value), 0); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return iterator (value_traits::to_node_ptr(value), this); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); } - - //! <b>Requires</b>: value shall not be in a tree. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { node_algorithms::init(value_traits::to_node_ptr(value)); } - -/* - //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect, - //! if x is not in such a tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This static function is only usable with the "safe mode" - //! hook and non-constant time size lists. Otherwise, the user must use - //! the non-static "erase(reference )" member. If the user calls - //! this function with a non "safe mode" or constant time size list - //! a compilation error will be issued. - template<class T> - static void remove_node(T& value) - { - //This function is only usable for safe mode hooks and non-constant - //time lists. - //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size))); - BOOST_STATIC_ASSERT((!constant_time_size)); - BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value)); - node_ptr to_remove(value_traits::to_node_ptr(value)); - node_algorithms::unlink_and_rebalance(to_remove); - if(safemode_or_autounlink) - node_algorithms::init(to_remove); - } -*/ + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - private: - template<class Disposer> - iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer) - { - for(n = 0; b != e; ++n) - this->erase_and_dispose(b++, disposer); - return b.unconst(); - } - - iterator private_erase(const_iterator b, const_iterator e, size_type &n) - { - for(n = 0; b != e; ++n) - this->erase(b++); - return b.unconst(); - } - /// @endcond + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); - private: - static avltree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) - { - header_plus_size *r = detail::parent_from_member<header_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &header_plus_size::header_); - node_plus_pred_t *n = detail::parent_from_member - <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_); - data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_); - avltree_impl *avl = detail::parent_from_member<avltree_impl, data_t>(d, &avltree_impl::data_); - return *avl; - } - - static avltree_impl &priv_container_from_iterator(const const_iterator &it) - { return priv_container_from_end_iterator(it.end_iterator_from_it()); } + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator< -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } +bool operator< (const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -bool operator== -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ - typedef avltree_impl<Config> tree_type; - typedef typename tree_type::const_iterator const_iterator; - - if(tree_type::constant_time_size && x.size() != y.size()){ - return false; - } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } -} +bool operator==(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y) -#else -(const avltree_impl<Config> &x, const avltree_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const avltree_impl<T, Options...> &x, const avltree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(avltree_impl<T, Options...> &x, avltree_impl<T, Options...> &y) -#else -(avltree_impl<Config> &x, avltree_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(avltree_impl<T, Options...> &x, avltree_impl<T, Options...> &y); -/// @cond +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - > -#else +//! Helper metafunction to define a \c avltree that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif -struct make_avltree_opt +struct make_avltree { + /// @cond typedef typename pack_options + < avltree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - < avl_set_defaults<T>, O1, O2, O3, O4> + O1, O2, O3, O4, O5 #else - < avl_set_defaults<T>, Options...> + Options... #endif - ::type packed_options; + >::type packed_options; typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; - typedef avl_setopt + typedef avltree_impl < value_traits , typename packed_options::compare , typename packed_options::size_type , packed_options::constant_time_size - > type; -}; -/// @endcond - -//! Helper metafunction to define a \c avltree that yields to the same type when the -//! same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class ...Options> -#else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#endif -struct make_avltree -{ - /// @cond - typedef avltree_impl - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - < typename make_avltree_opt<T, O1, O2, O3, O4>::type - #else - < typename make_avltree_opt<T, Options...>::type - #endif - > implementation_defined; + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class avltree - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - : public make_avltree<T, O1, O2, O3, O4>::type - #else - : public make_avltree<T, Options...>::type - #endif + : public make_avltree<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type { typedef typename make_avltree - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - <T, O1, O2, O3, O4> - #else - <T, Options...> - #endif - ::type Base; - + <T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type Base; BOOST_MOVABLE_BUT_NOT_COPYABLE(avltree) public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::reverse_iterator reverse_iterator; + typedef typename Base::const_reverse_iterator const_reverse_iterator; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - avltree( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit avltree( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1760,7 +524,7 @@ class avltree {} avltree& operator=(BOOST_RV_REF(avltree) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<avltree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static avltree &container_from_end_iterator(iterator end_iterator) { return static_cast<avltree &>(Base::container_from_end_iterator(end_iterator)); } @@ -1777,7 +541,6 @@ class avltree #endif - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/avltree_algorithms.hpp b/boost/intrusive/avltree_algorithms.hpp index 11463c71fb..e5bcfde160 100644 --- a/boost/intrusive/avltree_algorithms.hpp +++ b/boost/intrusive/avltree_algorithms.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Daniel K. O. 2005. -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,27 +14,93 @@ #ifndef BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP #define BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> -#include <boost/intrusive/pointer_traits.hpp> - +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/detail/ebo_functor_holder.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> namespace boost { namespace intrusive { +/// @cond + +template<class NodeTraits, class F> +struct avltree_node_cloner + : private detail::ebo_functor_holder<F> +{ + typedef typename NodeTraits::node_ptr node_ptr; + typedef detail::ebo_functor_holder<F> base_t; + + avltree_node_cloner(F f) + : base_t(f) + {} + + node_ptr operator()(const node_ptr & p) + { + node_ptr n = base_t::get()(p); + NodeTraits::set_balance(n, NodeTraits::get_balance(p)); + return n; + } +}; + +namespace detail { + +template<class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct avltree_node_checker + : public bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> base_checker_t; + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::const_node_ptr const_node_ptr; + + struct return_type + : public base_checker_t::return_type + { + return_type() : height(0) {} + int height; + }; + + avltree_node_checker(const NodePtrCompare& comp, ExtraChecker extra_checker) + : base_checker_t(comp, extra_checker) + {} + + void operator () (const const_node_ptr& p, + const return_type& check_return_left, const return_type& check_return_right, + return_type& check_return) + { + const int height_diff = check_return_right.height - check_return_left.height; (void)height_diff; + BOOST_INTRUSIVE_INVARIANT_ASSERT( + (height_diff == -1 && node_traits::get_balance(p) == node_traits::negative()) || + (height_diff == 0 && node_traits::get_balance(p) == node_traits::zero()) || + (height_diff == 1 && node_traits::get_balance(p) == node_traits::positive()) + ); + check_return.height = 1 + + (check_return_left.height > check_return_right.height ? check_return_left.height : check_return_right.height); + base_checker_t::operator()(p, check_return_left, check_return_right, check_return); + } +}; + +} // namespace detail + +/// @endcond + //! avltree_algorithms is configured with a NodeTraits class, which encapsulates the //! information about the node to be manipulated. NodeTraits must support the //! following interface: //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the binary search tree //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -67,6 +133,9 @@ namespace intrusive { //! <tt>static balance positive();</tt> template<class NodeTraits> class avltree_algorithms + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_algorithms<NodeTraits> + #endif { public: typedef typename NodeTraits::node node; @@ -77,161 +146,69 @@ class avltree_algorithms /// @cond private: - typedef detail::tree_algorithms<NodeTraits> tree_algorithms; - - template<class F> - struct avltree_node_cloner - : private detail::ebo_functor_holder<F> - { - typedef detail::ebo_functor_holder<F> base_t; - - avltree_node_cloner(F f) - : base_t(f) - {} - - node_ptr operator()(const node_ptr &p) - { - node_ptr n = base_t::get()(p); - NodeTraits::set_balance(n, NodeTraits::get_balance(p)); - return n; - } - }; - - struct avltree_erase_fixup - { - void operator()(const node_ptr &to_erase, const node_ptr &successor) - { NodeTraits::set_balance(successor, NodeTraits::get_balance(to_erase)); } - }; + typedef bstree_algorithms<NodeTraits> bstree_algo; - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } /// @endcond public: - static node_ptr begin_node(const const_node_ptr & header) - { return tree_algorithms::begin_node(header); } - - static node_ptr end_node(const const_node_ptr & header) - { return tree_algorithms::end_node(header); } - //! This type is the information that will be //! filled by insert_unique_check - typedef typename tree_algorithms::insert_commit_data insert_commit_data; + typedef typename bstree_algo::insert_commit_data insert_commit_data; - //! <b>Requires</b>: header1 and header2 must be the header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two trees. After the function header1 will contain - //! links to the second tree and header2 will have links to the first tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static void swap_tree(const node_ptr & header1, const node_ptr & header2) - { return tree_algorithms::swap_tree(header1, header2); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const const_node_ptr&) + static node_ptr get_header(const const_node_ptr & n); + + //! @copydoc ::boost::intrusive::bstree_algorithms::begin_node + static node_ptr begin_node(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::end_node + static node_ptr end_node(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree + static void swap_tree(const node_ptr & header1, const node_ptr & header2); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&) static void swap_nodes(const node_ptr & node1, const node_ptr & node2) { if(node1 == node2) return; - node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2)); + node_ptr header1(bstree_algo::get_header(node1)), header2(bstree_algo::get_header(node2)); swap_nodes(node1, header1, node2, header2); } - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees with header header1 and header2. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&,const node_ptr&,const node_ptr&) static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2) { if(node1 == node2) return; - tree_algorithms::swap_nodes(node1, header1, node2, header2); + bstree_algo::swap_nodes(node1, header1, node2, header2); //Swap balance balance c = NodeTraits::get_balance(node1); NodeTraits::set_balance(node1, NodeTraits::get_balance(node2)); NodeTraits::set_balance(node2, c); } - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&) static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) { if(node_to_be_replaced == new_node) return; - replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node); + replace_node(node_to_be_replaced, bstree_algo::get_header(node_to_be_replaced), new_node); } - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! with header "header" and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&,const node_ptr&) static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::replace_node(node_to_be_replaced, header, new_node); + bstree_algo::replace_node(node_to_be_replaced, header, new_node); NodeTraits::set_balance(new_node, NodeTraits::get_balance(node_to_be_replaced)); } - //! <b>Requires</b>: node is a tree node but not the header. - //! - //! <b>Effects</b>: Unlinks the node and rebalances the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink(const node_ptr&) static void unlink(const node_ptr & node) { node_ptr x = NodeTraits::get_parent(node); @@ -242,84 +219,25 @@ class avltree_algorithms } } - //! <b>Requires</b>: header is the header of a tree. - //! - //! <b>Effects</b>: Unlinks the leftmost node from the tree, and - //! updates the header link to the new leftmost node. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header) - { return tree_algorithms::unlink_leftmost_without_rebalance(header); } - - //! <b>Requires</b>: node is a node of the tree or an node initialized - //! by init(...). - //! - //! <b>Effects</b>: Returns true if the node is initialized by init(). - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - static bool unique(const const_node_ptr & node) - { return tree_algorithms::unique(node); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance + static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header); - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & node) - { return tree_algorithms::count(node); } + //! @copydoc ::boost::intrusive::bstree_algorithms::unique(const const_node_ptr&) + static bool unique(const const_node_ptr & node); - //! <b>Requires</b>: header is the header node of the tree. - //! - //! <b>Effects</b>: Returns the number of nodes above the header. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t size(const const_node_ptr & header) - { return tree_algorithms::size(header); } + //! @copydoc ::boost::intrusive::bstree_algorithms::size(const const_node_ptr&) + static std::size_t size(const const_node_ptr & header); - //! <b>Requires</b>: p is a node from the tree except the header. - //! - //! <b>Effects</b>: Returns the next node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr next_node(const node_ptr & p) - { return tree_algorithms::next_node(p); } + //! @copydoc ::boost::intrusive::bstree_algorithms::next_node(const node_ptr&) + static node_ptr next_node(const node_ptr & node); - //! <b>Requires</b>: p is a node from the tree except the leftmost node. - //! - //! <b>Effects</b>: Returns the previous node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr prev_node(const node_ptr & p) - { return tree_algorithms::prev_node(p); } + //! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(const node_ptr&) + static node_ptr prev_node(const node_ptr & node); - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: After the function unique(node) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init(const node_ptr & node) - { tree_algorithms::init(node); } + //! @copydoc ::boost::intrusive::bstree_algorithms::init(const node_ptr&) + static void init(const node_ptr & node); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Requires</b>: node must not be part of any tree. //! @@ -333,451 +251,238 @@ class avltree_algorithms //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. static void init_header(const node_ptr & header) { - tree_algorithms::init_header(header); + bstree_algo::init_header(header); NodeTraits::set_balance(header, NodeTraits::zero()); } - //! <b>Requires</b>: header must be the header of a tree, z a node - //! of that tree and z != header. - //! - //! <b>Effects</b>: Erases node "z" from the tree with header "header". - //! - //! <b>Complexity</b>: Amortized constant time. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree_algorithms::erase(const node_ptr&,const node_ptr&) static node_ptr erase(const node_ptr & header, const node_ptr & z) { - typename tree_algorithms::data_for_rebalance info; - tree_algorithms::erase(header, z, avltree_erase_fixup(), info); - node_ptr x = info.x; - node_ptr x_parent = info.x_parent; - + typename bstree_algo::data_for_rebalance info; + bstree_algo::erase(header, z, info); + if(info.y != z){ + NodeTraits::set_balance(info.y, NodeTraits::get_balance(z)); + } //Rebalance avltree - rebalance_after_erasure(header, x, x_parent); + rebalance_after_erasure(header, info.x, info.x_parent); return z; } - //! <b>Requires</b>: "cloner" must be a function - //! object taking a node_ptr and returning a new cloned node of it. "disposer" must - //! take a node_ptr and shouldn't throw. - //! - //! <b>Effects</b>: First empties target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! Then, duplicates the entire tree pointed by "source_header" cloning each - //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain - //! the nodes of the target tree. If "cloner" throws, the cloned target nodes - //! are disposed using <tt>void disposer(const node_ptr &)</tt>. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + //! @copydoc ::boost::intrusive::bstree_algorithms::clone(const const_node_ptr&,const node_ptr&,Cloner,Disposer) template <class Cloner, class Disposer> static void clone (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer) { - avltree_node_cloner<Cloner> new_cloner(cloner); - tree_algorithms::clone(source_header, target_header, new_cloner, disposer); + avltree_node_cloner<NodeTraits, Cloner> new_cloner(cloner); + bstree_algo::clone(source_header, target_header, new_cloner, disposer); } - //! <b>Requires</b>: "disposer" must be an object function - //! taking a node_ptr parameter and shouldn't throw. - //! - //! <b>Effects</b>: Empties the target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(const node_ptr&,Disposer) template<class Disposer> - static void clear_and_dispose(const node_ptr & header, Disposer disposer) - { tree_algorithms::clear_and_dispose(header, disposer); } + static void clear_and_dispose(const node_ptr & header, Disposer disposer); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is - //! not less than "key" according to "comp" or "header" if that element does - //! not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr lower_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::lower_bound(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater - //! than "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr upper_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::upper_bound(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to - //! "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr find - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::find(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing - //! all elements that are equivalent to "key" according to "comp" or an - //! empty range that indicates the position where those elements would be - //! if they there are no equivalent elements. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> equal_range - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::equal_range(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp - , bool left_closed, bool right_closed) - { return tree_algorithms::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); } + , bool left_closed, bool right_closed); - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the upper bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + template<class KeyType, class KeyNodePtrCompare> + static std::size_t count(const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_upper_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal_upper_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal_upper_bound(h, new_node, comp); + bstree_algo::insert_equal_upper_bound(h, new_node, comp); rebalance_after_insertion(h, new_node); return new_node; } - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the lower bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_lower_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal_lower_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal_lower_bound(h, new_node, comp); + bstree_algo::insert_equal_lower_bound(h, new_node, comp); rebalance_after_insertion(h, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from - //! the "header"'s tree. - //! - //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case). - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if new_node is inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal(const node_ptr&,const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal (const node_ptr & header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal(header, hint, new_node, comp); + bstree_algo::insert_equal(header, hint, new_node, comp); rebalance_after_insertion(header, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "pos" must be a valid iterator or header (end) node. - //! "pos" must be an iterator pointing to the successor to "new_node" - //! once inserted according to the order of already inserted nodes. This function does not - //! check "pos" and this precondition must be guaranteed by the caller. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node" - //! tree invariants might be broken. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_before(const node_ptr&,const node_ptr&,const node_ptr&) static node_ptr insert_before (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node) { - tree_algorithms::insert_before(header, pos, new_node); + bstree_algo::insert_before(header, pos, new_node); rebalance_after_insertion(header, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering no less than the - //! greatest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is less than the greatest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_back(const node_ptr&,const node_ptr&) static void push_back(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_back(header, new_node); + bstree_algo::push_back(header, new_node); rebalance_after_insertion(header, new_node); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering, no greater than the - //! lowest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is greater than the lowest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_front(const node_ptr&,const node_ptr&) static void push_front(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_front(header, new_node); + bstree_algo::push_front(header, new_node); rebalance_after_insertion(header, new_node); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) - { return tree_algorithms::insert_unique_check(header, key, comp, commit_data); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! "hint" is node from the "header"'s tree. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" using "hint" as a hint to where it should be - //! inserted and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! If "hint" is the upper_bound the function has constant time - //! complexity (two comparisons in the worst case). - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic, but it is - //! amortized constant time if new_node should be inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + ,KeyNodePtrCompare comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const node_ptr &hint, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) - { return tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "commit_data" must have been obtained from a previous call to - //! "insert_unique_check". No objects should have been inserted or erased - //! from the set between the "insert_unique_check" that filled "commit_data" - //! and the call to "insert_commit". - //! - //! - //! <b>Effects</b>: Inserts new_node in the set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. + ,KeyNodePtrCompare comp, insert_commit_data &commit_data); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_commit(const node_ptr&,const node_ptr&,const insert_commit_data &) static void insert_unique_commit (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data) { - tree_algorithms::insert_unique_commit(header, new_value, commit_data); + bstree_algo::insert_unique_commit(header, new_value, commit_data); rebalance_after_insertion(header, new_value); } - //! <b>Requires</b>: "n" must be a node inserted in a tree. - //! - //! <b>Effects</b>: Returns a pointer to the header node of the tree. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - static node_ptr get_header(const node_ptr & n) - { return tree_algorithms::get_header(n); } + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header + static bool is_header(const const_node_ptr & p) + { return NodeTraits::get_balance(p) == NodeTraits::zero() && bstree_algo::is_header(p); } + /// @cond + static bool verify(const node_ptr &header) + { + std::size_t height; + std::size_t count; + return verify_recursion(NodeTraits::get_parent(header), count, height); + } + private: - //! <b>Requires</b>: p is a node of a tree. - //! - //! <b>Effects</b>: Returns true if p is the header of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static bool is_header(const const_node_ptr & p) - { return NodeTraits::get_balance(p) == NodeTraits::zero() && tree_algorithms::is_header(p); } + static bool verify_recursion(node_ptr n, std::size_t &count, std::size_t &height) + { + if (!n){ + count = 0; + height = 0; + return true; + } + std::size_t leftcount, rightcount; + std::size_t leftheight, rightheight; + if(!verify_recursion(NodeTraits::get_left (n), leftcount, leftheight) || + !verify_recursion(NodeTraits::get_right(n), rightcount, rightheight) ){ + return false; + } + count = 1u + leftcount + rightcount; + height = 1u + (leftheight > rightheight ? leftheight : rightheight); + + //If equal height, balance must be zero + if(rightheight == leftheight){ + if(NodeTraits::get_balance(n) != NodeTraits::zero()){ + BOOST_ASSERT(0); + return false; + } + } + //If right is taller than left, then the difference must be at least 1 and the balance positive + else if(rightheight > leftheight){ + if(rightheight - leftheight > 1 ){ + BOOST_ASSERT(0); + return false; + } + else if(NodeTraits::get_balance(n) != NodeTraits::positive()){ + BOOST_ASSERT(0); + return false; + } + } + //If left is taller than right, then the difference must be at least 1 and the balance negative + else{ + if(leftheight - rightheight > 1 ){ + BOOST_ASSERT(0); + return false; + } + else if(NodeTraits::get_balance(n) != NodeTraits::negative()){ + BOOST_ASSERT(0); + return false; + } + } + return true; + } - static void rebalance_after_erasure(const node_ptr & header, const node_ptr & xnode, const node_ptr & xnode_parent) + static void rebalance_after_erasure(const node_ptr & header, node_ptr x, node_ptr x_parent) { - node_ptr x(xnode), x_parent(xnode_parent); - for (node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)) { + for ( node_ptr root = NodeTraits::get_parent(header) + ; x != root + ; root = NodeTraits::get_parent(header), x_parent = NodeTraits::get_parent(x)) { const balance x_parent_balance = NodeTraits::get_balance(x_parent); + //Don't cache x_is_leftchild or similar because x can be null and + //equal to both x_parent_left and x_parent_right + const node_ptr x_parent_left (NodeTraits::get_left(x_parent)); + const node_ptr x_parent_right(NodeTraits::get_right(x_parent)); + if(x_parent_balance == NodeTraits::zero()){ - NodeTraits::set_balance(x_parent, - (x == NodeTraits::get_right(x_parent) ? NodeTraits::negative() : NodeTraits::positive())); + NodeTraits::set_balance( x_parent, x == x_parent_right ? NodeTraits::negative() : NodeTraits::positive() ); break; // the height didn't change, let's stop here } else if(x_parent_balance == NodeTraits::negative()){ - if (x == NodeTraits::get_left(x_parent)) { + if (x == x_parent_left) { ////x is left child or x and sibling are null NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced x = x_parent; - x_parent = NodeTraits::get_parent(x_parent); } else { - // x is right child - // a is left child - node_ptr a = NodeTraits::get_left(x_parent); - BOOST_INTRUSIVE_INVARIANT_ASSERT(a); - if (NodeTraits::get_balance(a) == NodeTraits::positive()) { - // a MUST have a right child - BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(a)); - rotate_left_right(x_parent, header); - x = NodeTraits::get_parent(x_parent); - x_parent = NodeTraits::get_parent(x); + // x is right child (x_parent_left is the left child) + BOOST_INTRUSIVE_INVARIANT_ASSERT(x_parent_left); + if (NodeTraits::get_balance(x_parent_left) == NodeTraits::positive()) { + // x_parent_left MUST have a right child + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(x_parent_left)); + x = avl_rotate_left_right(x_parent, x_parent_left, header); } else { - rotate_right(x_parent, header); - x = NodeTraits::get_parent(x_parent); - x_parent = NodeTraits::get_parent(x); + avl_rotate_right(x_parent, x_parent_left, header); + x = x_parent_left; } // if changed from negative to NodeTraits::positive(), no need to check above @@ -787,28 +492,21 @@ class avltree_algorithms } } else if(x_parent_balance == NodeTraits::positive()){ - if (x == NodeTraits::get_right(x_parent)) { + if (x == x_parent_right) { //x is right child or x and sibling are null NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced x = x_parent; - x_parent = NodeTraits::get_parent(x_parent); } else { - // x is left child - // a is right child - node_ptr a = NodeTraits::get_right(x_parent); - BOOST_INTRUSIVE_INVARIANT_ASSERT(a); - if (NodeTraits::get_balance(a) == NodeTraits::negative()) { - // a MUST have then a left child - BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(a)); - rotate_right_left(x_parent, header); - - x = NodeTraits::get_parent(x_parent); - x_parent = NodeTraits::get_parent(x); + // x is left child (x_parent_right is the right child) + BOOST_INTRUSIVE_INVARIANT_ASSERT(x_parent_right); + if (NodeTraits::get_balance(x_parent_right) == NodeTraits::negative()) { + // x_parent_right MUST have then a left child + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(x_parent_right)); + x = avl_rotate_right_left(x_parent, x_parent_right, header); } else { - rotate_left(x_parent, header); - x = NodeTraits::get_parent(x_parent); - x_parent = NodeTraits::get_parent(x); + avl_rotate_left(x_parent, x_parent_right, header); + x = x_parent_right; } // if changed from NodeTraits::positive() to negative, no need to check above if (NodeTraits::get_balance(x) == NodeTraits::negative()){ @@ -822,44 +520,43 @@ class avltree_algorithms } } - static void rebalance_after_insertion(const node_ptr & header, const node_ptr & xnode) + static void rebalance_after_insertion(const node_ptr & header, node_ptr x) { - node_ptr x(xnode); NodeTraits::set_balance(x, NodeTraits::zero()); // Rebalance. for(node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)){ - const balance x_parent_balance = NodeTraits::get_balance(NodeTraits::get_parent(x)); - + node_ptr const x_parent(NodeTraits::get_parent(x)); + node_ptr const x_parent_left(NodeTraits::get_left(x_parent)); + const balance x_parent_balance = NodeTraits::get_balance(x_parent); + const bool x_is_leftchild(x == x_parent_left); if(x_parent_balance == NodeTraits::zero()){ // if x is left, parent will have parent->bal_factor = negative // else, parent->bal_factor = NodeTraits::positive() - NodeTraits::set_balance( NodeTraits::get_parent(x) - , x == NodeTraits::get_left(NodeTraits::get_parent(x)) - ? NodeTraits::negative() : NodeTraits::positive() ); - x = NodeTraits::get_parent(x); + NodeTraits::set_balance( x_parent, x_is_leftchild ? NodeTraits::negative() : NodeTraits::positive() ); + x = x_parent; } else if(x_parent_balance == NodeTraits::positive()){ // if x is a left child, parent->bal_factor = zero - if (x == NodeTraits::get_left(NodeTraits::get_parent(x))) - NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero()); + if (x_is_leftchild) + NodeTraits::set_balance(x_parent, NodeTraits::zero()); else{ // x is a right child, needs rebalancing if (NodeTraits::get_balance(x) == NodeTraits::negative()) - rotate_right_left(NodeTraits::get_parent(x), header); + avl_rotate_right_left(x_parent, x, header); else - rotate_left(NodeTraits::get_parent(x), header); + avl_rotate_left(x_parent, x, header); } break; } else if(x_parent_balance == NodeTraits::negative()){ // if x is a left child, needs rebalancing - if (x == NodeTraits::get_left(NodeTraits::get_parent(x))) { + if (x_is_leftchild) { if (NodeTraits::get_balance(x) == NodeTraits::positive()) - rotate_left_right(NodeTraits::get_parent(x), header); + avl_rotate_left_right(x_parent, x, header); else - rotate_right(NodeTraits::get_parent(x), header); + avl_rotate_right(x_parent, x, header); } else - NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero()); + NodeTraits::set_balance(x_parent, NodeTraits::zero()); break; } else{ @@ -873,26 +570,28 @@ class avltree_algorithms // balancing... const balance c_balance = NodeTraits::get_balance(c); const balance zero_balance = NodeTraits::zero(); + const balance posi_balance = NodeTraits::positive(); + const balance nega_balance = NodeTraits::negative(); NodeTraits::set_balance(c, zero_balance); - if(c_balance == NodeTraits::negative()){ - NodeTraits::set_balance(a, NodeTraits::positive()); + if(c_balance == nega_balance){ + NodeTraits::set_balance(a, posi_balance); NodeTraits::set_balance(b, zero_balance); } else if(c_balance == zero_balance){ NodeTraits::set_balance(a, zero_balance); NodeTraits::set_balance(b, zero_balance); } - else if(c_balance == NodeTraits::positive()){ + else if(c_balance == posi_balance){ NodeTraits::set_balance(a, zero_balance); - NodeTraits::set_balance(b, NodeTraits::negative()); + NodeTraits::set_balance(b, nega_balance); } else{ BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached } } - static void rotate_left_right(const node_ptr a, const node_ptr & hdr) - { + static node_ptr avl_rotate_left_right(const node_ptr a, const node_ptr a_oldleft, const node_ptr & hdr) + { // [note: 'a_oldleft' is 'b'] // | | // // a(-2) c // // / \ / \ // @@ -900,16 +599,19 @@ class avltree_algorithms // (pos)b [g] b a // // / \ / \ / \ // // [d] c [d] e f [g] // - // / \ // - // e f // - node_ptr b = NodeTraits::get_left(a), c = NodeTraits::get_right(b); - tree_algorithms::rotate_left(b, hdr); - tree_algorithms::rotate_right(a, hdr); - left_right_balancing(a, b, c); + // / \ // + // e f // + const node_ptr c = NodeTraits::get_right(a_oldleft); + bstree_algo::rotate_left_no_parent_fix(a_oldleft, c); + //No need to link c with a [NodeTraits::set_parent(c, a) + NodeTraits::set_left(a, c)] + //as c is not root and another rotation is coming + bstree_algo::rotate_right(a, c, NodeTraits::get_parent(a), hdr); + left_right_balancing(a, a_oldleft, c); + return c; } - static void rotate_right_left(const node_ptr a, const node_ptr & hdr) - { + static node_ptr avl_rotate_right_left(const node_ptr a, const node_ptr a_oldright, const node_ptr & hdr) + { // [note: 'a_oldright' is 'b'] // | | // // a(pos) c // // / \ / \ // @@ -919,47 +621,64 @@ class avltree_algorithms // c [g] [d] e f [g] // // / \ // // e f // - node_ptr b = NodeTraits::get_right(a), c = NodeTraits::get_left(b); - tree_algorithms::rotate_right(b, hdr); - tree_algorithms::rotate_left(a, hdr); - left_right_balancing(b, a, c); + const node_ptr c (NodeTraits::get_left(a_oldright)); + bstree_algo::rotate_right_no_parent_fix(a_oldright, c); + //No need to link c with a [NodeTraits::set_parent(c, a) + NodeTraits::set_right(a, c)] + //as c is not root and another rotation is coming. + bstree_algo::rotate_left(a, c, NodeTraits::get_parent(a), hdr); + left_right_balancing(a_oldright, a, c); + return c; } - static void rotate_left(const node_ptr x, const node_ptr & hdr) + static void avl_rotate_left(const node_ptr &x, const node_ptr &x_oldright, const node_ptr & hdr) { - const node_ptr y = NodeTraits::get_right(x); - tree_algorithms::rotate_left(x, hdr); + bstree_algo::rotate_left(x, x_oldright, NodeTraits::get_parent(x), hdr); // reset the balancing factor - if (NodeTraits::get_balance(y) == NodeTraits::positive()) { + if (NodeTraits::get_balance(x_oldright) == NodeTraits::positive()) { NodeTraits::set_balance(x, NodeTraits::zero()); - NodeTraits::set_balance(y, NodeTraits::zero()); + NodeTraits::set_balance(x_oldright, NodeTraits::zero()); } else { // this doesn't happen during insertions NodeTraits::set_balance(x, NodeTraits::positive()); - NodeTraits::set_balance(y, NodeTraits::negative()); + NodeTraits::set_balance(x_oldright, NodeTraits::negative()); } } - static void rotate_right(const node_ptr x, const node_ptr & hdr) + static void avl_rotate_right(const node_ptr &x, const node_ptr &x_oldleft, const node_ptr & hdr) { - const node_ptr y = NodeTraits::get_left(x); - tree_algorithms::rotate_right(x, hdr); + bstree_algo::rotate_right(x, x_oldleft, NodeTraits::get_parent(x), hdr); // reset the balancing factor - if (NodeTraits::get_balance(y) == NodeTraits::negative()) { + if (NodeTraits::get_balance(x_oldleft) == NodeTraits::negative()) { NodeTraits::set_balance(x, NodeTraits::zero()); - NodeTraits::set_balance(y, NodeTraits::zero()); + NodeTraits::set_balance(x_oldleft, NodeTraits::zero()); } else { // this doesn't happen during insertions NodeTraits::set_balance(x, NodeTraits::negative()); - NodeTraits::set_balance(y, NodeTraits::positive()); + NodeTraits::set_balance(x_oldleft, NodeTraits::positive()); } } /// @endcond }; +/// @cond + +template<class NodeTraits> +struct get_algo<AvlTreeAlgorithms, NodeTraits> +{ + typedef avltree_algorithms<NodeTraits> type; +}; + +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<AvlTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::avltree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/bs_set.hpp b/boost/intrusive/bs_set.hpp new file mode 100644 index 0000000000..b87a543a5e --- /dev/null +++ b/boost/intrusive/bs_set.hpp @@ -0,0 +1,948 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2013-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// +#ifndef BOOST_INTRUSIVE_BS_SET_HPP +#define BOOST_INTRUSIVE_BS_SET_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/bstree.hpp> +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> + +namespace boost { +namespace intrusive { + +//! The class template bs_set is an intrusive container, that mimics most of +//! the interface of std::set as described in the C++ standard. +//! +//! The template parameter \c T is the type to be managed by the container. +//! The user can specify additional options and if no options are provided +//! default options are used. +//! +//! The container supports the following options: +//! \c base_hook<>/member_hook<>/value_traits<>, +//! \c constant_time_size<>, \c size_type<> and +//! \c compare<>. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> +#endif +class bs_set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder> +#endif +{ + /// @cond + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder> tree_type; + BOOST_MOVABLE_BUT_NOT_COPYABLE(bs_set_impl) + + typedef tree_type implementation_defined; + /// @endcond + + public: + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::value_traits value_traits; + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::insert_commit_data insert_commit_data; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef typename implementation_defined::node_algorithms node_algorithms; + + static const bool constant_time_size = tree_type::constant_time_size; + + public: + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit bs_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} + + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) + template<class Iterator> + bs_set_impl( Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(true, b, e, cmp, v_traits) + {} + + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) + bs_set_impl(BOOST_RV_REF(bs_set_impl) x) + : tree_type(::boost::move(static_cast<tree_type&>(x))) + {} + + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) + bs_set_impl& operator=(BOOST_RV_REF(bs_set_impl) x) + { return static_cast<bs_set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~bs_set_impl(); + + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static bs_set_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const bs_set_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static bs_set_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const bs_set_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::bstree::swap + void swap(bs_set_impl& other); + + //! @copydoc ::boost::intrusive::bstree::clone_from + template <class Cloner, class Disposer> + void clone_from(const bs_set_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::insert_unique(reference) + std::pair<iterator, bool> insert(reference value) + { return tree_type::insert_unique(value); } + + //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference) + iterator insert(const_iterator hint, reference value) + { return tree_type::insert_unique(hint, value); } + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_check + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) + { return tree_type::insert_unique_check(key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_check + (const_iterator hint, const KeyType &key + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) + { return tree_type::insert_unique_check(hint, key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator) + template<class Iterator> + void insert(Iterator b, Iterator e) + { tree_type::insert_unique(b, e); } + + //! @copydoc ::boost::intrusive::bstree::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::bstree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::bstree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + size_type erase(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) + template<class Disposer> + iterator erase_and_dispose(const_iterator i, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) + template<class Disposer> + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) + template<class Disposer> + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) + template<class KeyType, class KeyValueCompare, class Disposer> + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::clear + void clear(); + + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose + template<class Disposer> + void clear_and_dispose(Disposer disposer); + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const + { return static_cast<size_type>(this->tree_type::find(value) == this->tree_type::cend()); } + + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + size_type count(const KeyType& key, KeyValueCompare comp) const + { return static_cast<size_type>(this->tree_type::find(key, comp) == this->tree_type::cend()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value) + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) + { return this->tree_type::lower_bound_range(key, comp); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const + std::pair<const_iterator, const_iterator> + equal_range(const_reference value) const + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> + equal_range(const KeyType& key, KeyValueCompare comp) const + { return this->tree_type::lower_bound_range(key, comp); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) + std::pair<iterator,iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +}; + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +template<class T, class ...Options> +bool operator!= (const bs_set_impl<T, Options...> &x, const bs_set_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator>(const bs_set_impl<T, Options...> &x, const bs_set_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator<=(const bs_set_impl<T, Options...> &x, const bs_set_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator>=(const bs_set_impl<T, Options...> &x, const bs_set_impl<T, Options...> &y); + +template<class T, class ...Options> +void swap(bs_set_impl<T, Options...> &x, bs_set_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +//! Helper metafunction to define a \c bs_set that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> +#endif +struct make_bs_set +{ + /// @cond + typedef typename pack_options + < bstree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef bs_set_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class O1, class O2, class O3, class O4, class O5> +#else +template<class T, class ...Options> +#endif +class bs_set + : public make_bs_set<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type +{ + typedef typename make_bs_set + <T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type Base; + + BOOST_MOVABLE_BUT_NOT_COPYABLE(bs_set) + public: + typedef typename Base::value_compare value_compare; + typedef typename Base::value_traits value_traits; + typedef typename Base::iterator iterator; + typedef typename Base::const_iterator const_iterator; + + //Assert if passed value traits are compatible with the type + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); + + explicit bs_set( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(cmp, v_traits) + {} + + template<class Iterator> + bs_set( Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(b, e, cmp, v_traits) + {} + + bs_set(BOOST_RV_REF(bs_set) x) + : Base(::boost::move(static_cast<Base&>(x))) + {} + + bs_set& operator=(BOOST_RV_REF(bs_set) x) + { return static_cast<bs_set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } + + static bs_set &container_from_end_iterator(iterator end_iterator) + { return static_cast<bs_set &>(Base::container_from_end_iterator(end_iterator)); } + + static const bs_set &container_from_end_iterator(const_iterator end_iterator) + { return static_cast<const bs_set &>(Base::container_from_end_iterator(end_iterator)); } + + static bs_set &container_from_iterator(iterator it) + { return static_cast<bs_set &>(Base::container_from_iterator(it)); } + + static const bs_set &container_from_iterator(const_iterator it) + { return static_cast<const bs_set &>(Base::container_from_iterator(it)); } +}; + +#endif + +//! The class template bs_multiset is an intrusive container, that mimics most of +//! the interface of std::multiset as described in the C++ standard. +//! +//! The template parameter \c T is the type to be managed by the container. +//! The user can specify additional options and if no options are provided +//! default options are used. +//! +//! The container supports the following options: +//! \c base_hook<>/member_hook<>/value_traits<>, +//! \c constant_time_size<>, \c size_type<> and +//! \c compare<>. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> +#endif +class bs_multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> +#endif +{ + /// @cond + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> tree_type; + + BOOST_MOVABLE_BUT_NOT_COPYABLE(bs_multiset_impl) + typedef tree_type implementation_defined; + /// @endcond + + public: + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::value_traits value_traits; + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::insert_commit_data insert_commit_data; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef typename implementation_defined::node_algorithms node_algorithms; + + static const bool constant_time_size = tree_type::constant_time_size; + + public: + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit bs_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} + + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) + template<class Iterator> + bs_multiset_impl( Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(false, b, e, cmp, v_traits) + {} + + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) + bs_multiset_impl(BOOST_RV_REF(bs_multiset_impl) x) + : tree_type(::boost::move(static_cast<tree_type&>(x))) + {} + + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) + bs_multiset_impl& operator=(BOOST_RV_REF(bs_multiset_impl) x) + { return static_cast<bs_multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~bs_multiset_impl(); + + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static bs_multiset_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const bs_multiset_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static bs_multiset_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const bs_multiset_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::bstree::swap + void swap(bs_multiset_impl& other); + + //! @copydoc ::boost::intrusive::bstree::clone_from + template <class Cloner, class Disposer> + void clone_from(const bs_multiset_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::insert_equal(reference) + iterator insert(reference value) + { return tree_type::insert_equal(value); } + + //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference) + iterator insert(const_iterator hint, reference value) + { return tree_type::insert_equal(hint, value); } + + //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator) + template<class Iterator> + void insert(Iterator b, Iterator e) + { tree_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::bstree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::bstree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + size_type erase(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) + template<class Disposer> + iterator erase_and_dispose(const_iterator i, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) + template<class Disposer> + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) + template<class Disposer> + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) + template<class KeyType, class KeyValueCompare, class Disposer> + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::clear + void clear(); + + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose + template<class Disposer> + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const + std::pair<const_iterator, const_iterator> + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) + std::pair<iterator,iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED +}; + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +template<class T, class ...Options> +bool operator!= (const bs_multiset_impl<T, Options...> &x, const bs_multiset_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator>(const bs_multiset_impl<T, Options...> &x, const bs_multiset_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator<=(const bs_multiset_impl<T, Options...> &x, const bs_multiset_impl<T, Options...> &y); + +template<class T, class ...Options> +bool operator>=(const bs_multiset_impl<T, Options...> &x, const bs_multiset_impl<T, Options...> &y); + +template<class T, class ...Options> +void swap(bs_multiset_impl<T, Options...> &x, bs_multiset_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +//! Helper metafunction to define a \c bs_multiset that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> +#endif +struct make_bs_multiset +{ + /// @cond + typedef typename pack_options + < bstree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef bs_multiset_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class O1, class O2, class O3, class O4, class O5> +#else +template<class T, class ...Options> +#endif +class bs_multiset + : public make_bs_multiset<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type +{ + typedef typename make_bs_multiset<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type Base; + + BOOST_MOVABLE_BUT_NOT_COPYABLE(bs_multiset) + + public: + typedef typename Base::value_compare value_compare; + typedef typename Base::value_traits value_traits; + typedef typename Base::iterator iterator; + typedef typename Base::const_iterator const_iterator; + + //Assert if passed value traits are compatible with the type + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); + + explicit bs_multiset( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(cmp, v_traits) + {} + + template<class Iterator> + bs_multiset( Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(b, e, cmp, v_traits) + {} + + bs_multiset(BOOST_RV_REF(bs_multiset) x) + : Base(::boost::move(static_cast<Base&>(x))) + {} + + bs_multiset& operator=(BOOST_RV_REF(bs_multiset) x) + { return static_cast<bs_multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } + + static bs_multiset &container_from_end_iterator(iterator end_iterator) + { return static_cast<bs_multiset &>(Base::container_from_end_iterator(end_iterator)); } + + static const bs_multiset &container_from_end_iterator(const_iterator end_iterator) + { return static_cast<const bs_multiset &>(Base::container_from_end_iterator(end_iterator)); } + + static bs_multiset &container_from_iterator(iterator it) + { return static_cast<bs_multiset &>(Base::container_from_iterator(it)); } + + static const bs_multiset &container_from_iterator(const_iterator it) + { return static_cast<const bs_multiset &>(Base::container_from_iterator(it)); } +}; + +#endif + +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_BS_SET_HPP diff --git a/boost/intrusive/bs_set_hook.hpp b/boost/intrusive/bs_set_hook.hpp index 682426a960..cb5af30d63 100644 --- a/boost/intrusive/bs_set_hook.hpp +++ b/boost/intrusive/bs_set_hook.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,31 +13,27 @@ #ifndef BOOST_INTRUSIVE_BS_SET_HOOK_HPP #define BOOST_INTRUSIVE_BS_SET_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/detail/tree_node.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> #include <boost/intrusive/options.hpp> #include <boost/intrusive/detail/generic_hook.hpp> namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer> -struct get_bs_set_node_algo -{ - typedef detail::tree_algorithms<tree_node_traits<VoidPointer> > type; -}; -/// @endcond - //! Helper metafunction to define a \c bs_set_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_bs_set_base_hook { @@ -50,14 +46,11 @@ struct make_bs_set_base_hook #endif ::type packed_options; - //Scapegoat trees can't be auto unlink trees - BOOST_STATIC_ASSERT(((int)packed_options::link_mode != (int)auto_unlink)); - - typedef detail::generic_hook - < get_bs_set_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < bstree_algorithms<tree_node_traits<typename packed_options::void_pointer> > , typename packed_options::tag , packed_options::link_mode - , detail::BsSetBaseHook + , BsTreeBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -76,7 +69,7 @@ struct make_bs_set_base_hook //! unique tag. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). @@ -168,7 +161,7 @@ class bs_set_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_bs_set_member_hook { @@ -182,14 +175,11 @@ struct make_bs_set_member_hook ::type packed_options; - //Scapegoat trees can't be auto unlink trees - BOOST_STATIC_ASSERT(((int)packed_options::link_mode != (int)auto_unlink)); - - typedef detail::generic_hook - < get_bs_set_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < bstree_algorithms<tree_node_traits<typename packed_options::void_pointer> > , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -202,7 +192,7 @@ struct make_bs_set_member_hook //! The hook admits the following options: \c void_pointer<>, \c link_mode<>. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). diff --git a/boost/intrusive/bstree.hpp b/boost/intrusive/bstree.hpp new file mode 100644 index 0000000000..44b02bb790 --- /dev/null +++ b/boost/intrusive/bstree.hpp @@ -0,0 +1,2177 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2013-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// +#ifndef BOOST_INTRUSIVE_BSTREE_HPP +#define BOOST_INTRUSIVE_BSTREE_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> + +#include <boost/intrusive/detail/assert.hpp> +#include <boost/static_assert.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> +#include <boost/intrusive/bs_set_hook.hpp> +#include <boost/intrusive/detail/tree_node.hpp> +#include <boost/intrusive/detail/tree_iterator.hpp> +#include <boost/intrusive/detail/ebo_functor_holder.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> +#include <boost/intrusive/detail/empty_node_checker.hpp> +#include <boost/intrusive/detail/default_header_holder.hpp> +#include <boost/intrusive/detail/reverse_iterator.hpp> +#include <boost/intrusive/detail/exception_disposer.hpp> +#include <boost/intrusive/detail/node_cloner_disposer.hpp> +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> +#include <boost/intrusive/detail/simple_disposers.hpp> +#include <boost/intrusive/detail/size_holder.hpp> +#include <boost/intrusive/detail/algo_type.hpp> + +#include <boost/intrusive/detail/get_value_traits.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> +#include <boost/intrusive/link_mode.hpp> +#include <boost/intrusive/parent_from_member.hpp> +#include <boost/move/utility_core.hpp> + +#include <utility> //pair,lexicographical_compare +#include <algorithm> //swap +#include <cstddef> //size_t... +#include <functional>//less, equal_to + + +namespace boost { +namespace intrusive { + +/// @cond + +struct default_bstree_hook_applier +{ template <class T> struct apply{ typedef typename T::default_bstree_hook type; }; }; + +template<> +struct is_default_hook_tag<default_bstree_hook_applier> +{ static const bool value = true; }; + +struct bstree_defaults +{ + typedef default_bstree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + static const bool floating_point = true; //For sgtree + typedef void priority; //For treap + typedef void header_holder_type; +}; + +template<class ValueTraits, algo_types AlgoType, typename HeaderHolder> +struct bstbase3 +{ + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::node node_type; + typedef typename get_algo<AlgoType, node_traits>::type node_algorithms; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + typedef tree_iterator<value_traits, false> iterator; + typedef tree_iterator<value_traits, true> const_iterator; + typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; + typedef boost::intrusive::detail::reverse_iterator<const_iterator> const_reverse_iterator; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type; + typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type; + typedef HeaderHolder header_holder_type; + + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; + static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; + static const bool has_container_from_iterator = + detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value; + + struct holder_t : public ValueTraits + { + explicit holder_t(const ValueTraits &vtraits) + : ValueTraits(vtraits) + {} + header_holder_type root; + } holder; + + static bstbase3 &get_tree_base_from_end_iterator(const const_iterator &end_iterator) + { + BOOST_STATIC_ASSERT(has_container_from_iterator); + node_ptr p = end_iterator.pointed_node(); + header_holder_type* h = header_holder_type::get_holder(p); + holder_t *holder = get_parent_from_member<holder_t, header_holder_type>(h, &holder_t::root); + bstbase3 *base = get_parent_from_member<bstbase3, holder_t> (holder, &bstbase3::holder); + return *base; + } + + bstbase3(const ValueTraits &vtraits) + : holder(vtraits) + { + node_algorithms::init_header(this->header_ptr()); + } + + node_ptr header_ptr() + { return holder.root.get_node(); } + + const_node_ptr header_ptr() const + { return holder.root.get_node(); } + + const value_traits &get_value_traits() const + { return this->holder; } + + value_traits &get_value_traits() + { return this->holder; } + + typedef typename boost::intrusive::value_traits_pointers + <ValueTraits>::const_value_traits_ptr const_value_traits_ptr; + + const_value_traits_ptr priv_value_traits_ptr() const + { return pointer_traits<const_value_traits_ptr>::pointer_to(this->get_value_traits()); } + + iterator begin() + { return iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + const_iterator begin() const + { return cbegin(); } + + const_iterator cbegin() const + { return const_iterator(node_algorithms::begin_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + iterator end() + { return iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + const_iterator end() const + { return cend(); } + + const_iterator cend() const + { return const_iterator(node_algorithms::end_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + iterator root() + { return iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + const_iterator root() const + { return croot(); } + + const_iterator croot() const + { return const_iterator(node_algorithms::root_node(this->header_ptr()), this->priv_value_traits_ptr()); } + + reverse_iterator rbegin() + { return reverse_iterator(end()); } + + const_reverse_iterator rbegin() const + { return const_reverse_iterator(end()); } + + const_reverse_iterator crbegin() const + { return const_reverse_iterator(end()); } + + reverse_iterator rend() + { return reverse_iterator(begin()); } + + const_reverse_iterator rend() const + { return const_reverse_iterator(begin()); } + + const_reverse_iterator crend() const + { return const_reverse_iterator(begin()); } + + void replace_node(iterator replace_this, reference with_this) + { + node_algorithms::replace_node( get_value_traits().to_node_ptr(*replace_this) + , this->header_ptr() + , get_value_traits().to_node_ptr(with_this)); + if(safemode_or_autounlink) + node_algorithms::init(replace_this.pointed_node()); + } + + void rebalance() + { node_algorithms::rebalance(this->header_ptr()); } + + iterator rebalance_subtree(iterator root) + { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this->priv_value_traits_ptr()); } + + static iterator s_iterator_to(reference value) + { + BOOST_STATIC_ASSERT((!stateful_value_traits)); + return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr()); + } + + static const_iterator s_iterator_to(const_reference value) + { + BOOST_STATIC_ASSERT((!stateful_value_traits)); + return const_iterator (value_traits::to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), const_value_traits_ptr()); + } + + iterator iterator_to(reference value) + { return iterator (this->get_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); } + + const_iterator iterator_to(const_reference value) const + { return const_iterator (this->get_value_traits().to_node_ptr(*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value))), this->priv_value_traits_ptr()); } + + static void init_node(reference value) + { node_algorithms::init(value_traits::to_node_ptr(value)); } + +}; + +template<class Less, class T> +struct get_less +{ + typedef Less type; +}; + +template<class T> +struct get_less<void, T> +{ + typedef ::std::less<T> type; +}; + +template<class ValueTraits, class VoidOrKeyComp, algo_types AlgoType, typename HeaderHolder> +struct bstbase2 + //Put the (possibly empty) functor in the first position to get EBO in MSVC + : public detail::ebo_functor_holder<typename get_less< VoidOrKeyComp + , typename ValueTraits::value_type + >::type> + , public bstbase3<ValueTraits, AlgoType, HeaderHolder> +{ + typedef bstbase3<ValueTraits, AlgoType, HeaderHolder> treeheader_t; + typedef typename treeheader_t::value_traits value_traits; + typedef typename treeheader_t::node_algorithms node_algorithms; + typedef typename get_less + < VoidOrKeyComp, typename value_traits::value_type>::type value_compare; + typedef BOOST_INTRUSIVE_IMPDEF(value_compare) key_compare; + typedef typename treeheader_t::iterator iterator; + typedef typename treeheader_t::const_iterator const_iterator; + typedef typename treeheader_t::node_ptr node_ptr; + typedef typename treeheader_t::const_node_ptr const_node_ptr; + + bstbase2(const value_compare &comp, const ValueTraits &vtraits) + : detail::ebo_functor_holder<value_compare>(comp), treeheader_t(vtraits) + {} + + const value_compare &comp() const + { return this->get(); } + + value_compare &comp() + { return this->get(); } + + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type; + typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type; + typedef typename node_algorithms::insert_commit_data insert_commit_data; + + value_compare value_comp() const + { return this->comp(); } + + key_compare key_comp() const + { return this->comp(); } + + //lower_bound + iterator lower_bound(const_reference value) + { return this->lower_bound(value, this->comp()); } + + const_iterator lower_bound(const_reference value) const + { return this->lower_bound(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + iterator lower_bound(const KeyType &key, KeyValueCompare comp) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return iterator(node_algorithms::lower_bound + (this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + template<class KeyType, class KeyValueCompare> + const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return const_iterator(node_algorithms::lower_bound + (this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + //upper_bound + iterator upper_bound(const_reference value) + { return this->upper_bound(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + iterator upper_bound(const KeyType &key, KeyValueCompare comp) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return iterator(node_algorithms::upper_bound + (this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + const_iterator upper_bound(const_reference value) const + { return this->upper_bound(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return const_iterator(node_algorithms::upper_bound + (this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + //find + iterator find(const_reference value) + { return this->find(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + iterator find(const KeyType &key, KeyValueCompare comp) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return iterator + (node_algorithms::find(this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + const_iterator find(const_reference value) const + { return this->find(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + const_iterator find(const KeyType &key, KeyValueCompare comp) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + return const_iterator + (node_algorithms::find(this->header_ptr(), key, key_node_comp), this->priv_value_traits_ptr()); + } + + //equal_range + std::pair<iterator,iterator> equal_range(const_reference value) + { return this->equal_range(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::equal_range(this->header_ptr(), key, key_node_comp)); + return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr()) + , iterator(ret.second, this->priv_value_traits_ptr())); + } + + std::pair<const_iterator, const_iterator> + equal_range(const_reference value) const + { return this->equal_range(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> + equal_range(const KeyType &key, KeyValueCompare comp) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::equal_range(this->header_ptr(), key, key_node_comp)); + return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr()) + , const_iterator(ret.second, this->priv_value_traits_ptr())); + } + + //lower_bound_range + std::pair<iterator,iterator> lower_bound_range(const_reference value) + { return this->lower_bound_range(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> lower_bound_range(const KeyType &key, KeyValueCompare comp) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::lower_bound_range(this->header_ptr(), key, key_node_comp)); + return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr()) + , iterator(ret.second, this->priv_value_traits_ptr())); + } + + std::pair<const_iterator, const_iterator> + lower_bound_range(const_reference value) const + { return this->lower_bound_range(value, this->comp()); } + + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> + lower_bound_range(const KeyType &key, KeyValueCompare comp) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::lower_bound_range(this->header_ptr(), key, key_node_comp)); + return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr()) + , const_iterator(ret.second, this->priv_value_traits_ptr())); + } + + //bounded_range + std::pair<iterator,iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) + { return this->bounded_range(lower_value, upper_value, this->comp(), left_closed, right_closed); } + + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> bounded_range + (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::bounded_range + (this->header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); + return std::pair<iterator, iterator>( iterator(ret.first, this->priv_value_traits_ptr()) + , iterator(ret.second, this->priv_value_traits_ptr())); + } + + std::pair<const_iterator,const_iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const + { return this->bounded_range(lower_value, upper_value, this->comp(), left_closed, right_closed); } + + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator,const_iterator> bounded_range + (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + std::pair<node_ptr, node_ptr> ret + (node_algorithms::bounded_range + (this->header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); + return std::pair<const_iterator, const_iterator>( const_iterator(ret.first, this->priv_value_traits_ptr()) + , const_iterator(ret.second, this->priv_value_traits_ptr())); + } + + //insert_unique_check + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_unique_check + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + ocomp(key_value_comp, &this->get_value_traits()); + std::pair<node_ptr, bool> ret = + (node_algorithms::insert_unique_check + (this->header_ptr(), key, ocomp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); + } + + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_unique_check + (const_iterator hint, const KeyType &key + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) + { + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + ocomp(key_value_comp, &this->get_value_traits()); + std::pair<node_ptr, bool> ret = + (node_algorithms::insert_unique_check + (this->header_ptr(), hint.pointed_node(), key, ocomp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); + } +}; + +//Due to MSVC's EBO implementation, to save space and maintain the ABI, we must put the non-empty size member +//in the first position, but if size is not going to be stored then we'll use an specialization +//that doesn't inherit from size_holder +template<class ValueTraits, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder> +struct bstbase_hack + : public detail::size_holder<ConstantTimeSize, SizeType> + , public bstbase2 < ValueTraits, VoidOrKeyComp, AlgoType, HeaderHolder> +{ + typedef bstbase2< ValueTraits, VoidOrKeyComp, AlgoType, HeaderHolder> base_type; + typedef typename base_type::value_compare value_compare; + typedef SizeType size_type; + typedef typename base_type::node_traits node_traits; + typedef typename get_algo + <AlgoType, node_traits>::type algo_type; + + bstbase_hack(const value_compare & comp, const ValueTraits &vtraits) + : base_type(comp, vtraits) + { + this->sz_traits().set_size(size_type(0)); + } + + typedef detail::size_holder<ConstantTimeSize, SizeType> size_traits; + + size_traits &sz_traits() + { return static_cast<size_traits &>(*this); } + + const size_traits &sz_traits() const + { return static_cast<const size_traits &>(*this); } +}; + +//Specialization for ConstantTimeSize == false +template<class ValueTraits, class VoidOrKeyComp, class SizeType, algo_types AlgoType, typename HeaderHolder> +struct bstbase_hack<ValueTraits, VoidOrKeyComp, false, SizeType, AlgoType, HeaderHolder> + : public bstbase2 < ValueTraits, VoidOrKeyComp, AlgoType, HeaderHolder> +{ + typedef bstbase2< ValueTraits, VoidOrKeyComp, AlgoType, HeaderHolder> base_type; + typedef typename base_type::value_compare value_compare; + bstbase_hack(const value_compare & comp, const ValueTraits &vtraits) + : base_type(comp, vtraits) + {} + + typedef detail::size_holder<true, SizeType> size_traits; + + size_traits &sz_traits() + { return s_size_traits; } + + const size_traits &sz_traits() const + { return s_size_traits; } + + static size_traits s_size_traits; +}; + +template<class ValueTraits, class VoidOrKeyComp, class SizeType, algo_types AlgoType, typename HeaderHolder> +detail::size_holder<true, SizeType> bstbase_hack<ValueTraits, VoidOrKeyComp, false, SizeType, AlgoType, HeaderHolder>::s_size_traits; + +//This class will +template<class ValueTraits, class VoidOrKeyComp, bool ConstantTimeSize, class SizeType, algo_types AlgoType, typename HeaderHolder> +struct bstbase + : public bstbase_hack< ValueTraits, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> +{ + typedef bstbase_hack< ValueTraits, VoidOrKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> base_type; + typedef ValueTraits value_traits; + typedef typename base_type::value_compare value_compare; + typedef value_compare key_compare; + typedef typename base_type::const_reference const_reference; + typedef typename base_type::reference reference; + typedef typename base_type::iterator iterator; + typedef typename base_type::const_iterator const_iterator; + typedef typename base_type::node_traits node_traits; + typedef typename get_algo + <AlgoType, node_traits>::type node_algorithms; + typedef SizeType size_type; + + bstbase(const value_compare & comp, const ValueTraits &vtraits) + : base_type(comp, vtraits) + {} + + //Detach all inserted nodes. This will add exception safety to bstree_impl + //constructors inserting elements. + ~bstbase() + { + if(is_safe_autounlink<value_traits::link_mode>::value){ + node_algorithms::clear_and_dispose + ( this->header_ptr() + , detail::node_disposer<detail::null_disposer, value_traits, AlgoType> + (detail::null_disposer(), &this->get_value_traits())); + node_algorithms::init(this->header_ptr()); + } + } +}; + + +/// @endcond + +//! The class template bstree is an unbalanced intrusive binary search tree +//! container. The no-throw guarantee holds only, if the value_compare object +//! doesn't throw. +//! +//! The complexity guarantees only hold if the tree is balanced, logarithmic +//! complexity would increase to linear if the tree is totally unbalanced. +//! +//! The template parameter \c T is the type to be managed by the container. +//! The user can specify additional options and if no options are provided +//! default options are used. +//! +//! The container supports the following options: +//! \c base_hook<>/member_hook<>/value_traits<>, +//! \c constant_time_size<>, \c size_type<> and +//! \c compare<>. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +class bstree_impl + : public bstbase<ValueTraits, VoidKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> +{ + public: + /// @cond + typedef bstbase<ValueTraits, VoidKeyComp, ConstantTimeSize, SizeType, AlgoType, HeaderHolder> data_type; + typedef tree_iterator<ValueTraits, false> iterator_type; + typedef tree_iterator<ValueTraits, true> const_iterator_type; + /// @endcond + + typedef BOOST_INTRUSIVE_IMPDEF(ValueTraits) value_traits; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::pointer) pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::const_pointer) const_pointer; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::element_type) value_type; + typedef BOOST_INTRUSIVE_IMPDEF(value_type) key_type; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<pointer>::reference) reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::reference) const_reference; + typedef BOOST_INTRUSIVE_IMPDEF(typename pointer_traits<const_pointer>::difference_type) difference_type; + typedef BOOST_INTRUSIVE_IMPDEF(SizeType) size_type; + typedef BOOST_INTRUSIVE_IMPDEF(typename data_type::value_compare) value_compare; + typedef BOOST_INTRUSIVE_IMPDEF(value_compare) key_compare; + typedef BOOST_INTRUSIVE_IMPDEF(iterator_type) iterator; + typedef BOOST_INTRUSIVE_IMPDEF(const_iterator_type) const_iterator; + typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::detail::reverse_iterator<iterator>) reverse_iterator; + typedef BOOST_INTRUSIVE_IMPDEF(boost::intrusive::detail::reverse_iterator<const_iterator>) const_reverse_iterator; + typedef BOOST_INTRUSIVE_IMPDEF(typename value_traits::node_traits) node_traits; + typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node) node; + typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::node_ptr) node_ptr; + typedef BOOST_INTRUSIVE_IMPDEF(typename node_traits::const_node_ptr) const_node_ptr; + /// @cond + typedef typename get_algo<AlgoType, node_traits>::type algo_type; + /// @endcond + typedef BOOST_INTRUSIVE_IMPDEF(algo_type) node_algorithms; + + static const bool constant_time_size = ConstantTimeSize; + static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; + /// @cond + private: + + //noncopyable + BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree_impl) + + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; + + //Constant-time size is incompatible with auto-unlink hooks! + BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink))); + + + protected: + + + /// @endcond + + public: + + typedef typename node_algorithms::insert_commit_data insert_commit_data; + + //! <b>Effects</b>: Constructs an empty container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: If value_traits::node_traits::node + //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) + //! or the copy constructor of the value_compare object throws. Basic guarantee. + explicit bstree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : data_type(cmp, v_traits) + {} + + //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. + //! cmp must be a comparison function that induces a strict weak ordering. + //! + //! <b>Effects</b>: Constructs an empty container and inserts elements from + //! [b, e). + //! + //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using + //! comp and otherwise N * log N, where N is the distance between first and last. + //! + //! <b>Throws</b>: If value_traits::node_traits::node + //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) + //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee. + template<class Iterator> + bstree_impl( bool unique, Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : data_type(cmp, v_traits) + { + //bstbase releases elements in case of exceptions + if(unique) + this->insert_unique(b, e); + else + this->insert_equal(b, e); + } + + //! <b>Effects</b>: to-do + //! + bstree_impl(BOOST_RV_REF(bstree_impl) x) + : data_type(::boost::move(x.comp()), ::boost::move(x.get_value_traits())) + { + this->swap(x); + } + + //! <b>Effects</b>: to-do + //! + bstree_impl& operator=(BOOST_RV_REF(bstree_impl) x) + { this->swap(x); return *this; } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! <b>Effects</b>: Detaches all elements from this. The objects in the set + //! are not deleted (i.e. no destructors are called), but the nodes according to + //! the value_traits template parameter are reinitialized and thus can be reused. + //! + //! <b>Complexity</b>: Linear to elements contained in *this. + //! + //! <b>Throws</b>: Nothing. + ~bstree_impl() + {} + + //! <b>Effects</b>: Returns an iterator pointing to the beginning of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + iterator begin(); + + //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_iterator begin() const; + + //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_iterator cbegin() const; + + //! <b>Effects</b>: Returns an iterator pointing to the end of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + iterator end(); + + //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_iterator end() const; + + //! <b>Effects</b>: Returns a const_iterator pointing to the end of the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_iterator cend() const; + + //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the + //! reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + reverse_iterator rbegin(); + + //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning + //! of the reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_reverse_iterator rbegin() const; + + //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning + //! of the reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_reverse_iterator crbegin() const; + + //! <b>Effects</b>: Returns a reverse_iterator pointing to the end + //! of the reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + reverse_iterator rend(); + + //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end + //! of the reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_reverse_iterator rend() const; + + //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end + //! of the reversed container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_reverse_iterator crend() const; + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Precondition</b>: end_iterator must be a valid end iterator + //! of the container. + //! + //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Constant. + static bstree_impl &container_from_end_iterator(iterator end_iterator) + { + return static_cast<bstree_impl&> + (data_type::get_tree_base_from_end_iterator(end_iterator)); + } + + //! <b>Precondition</b>: end_iterator must be a valid end const_iterator + //! of the container. + //! + //! <b>Effects</b>: Returns a const reference to the container associated to the iterator + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Constant. + static const bstree_impl &container_from_end_iterator(const_iterator end_iterator) + { + return static_cast<bstree_impl&> + (data_type::get_tree_base_from_end_iterator(end_iterator)); + } + + //! <b>Precondition</b>: it must be a valid iterator + //! of the container. + //! + //! <b>Effects</b>: Returns a const reference to the container associated to the iterator + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Logarithmic. + static bstree_impl &container_from_iterator(iterator it) + { return container_from_end_iterator(it.end_iterator_from_it()); } + + //! <b>Precondition</b>: it must be a valid end const_iterator + //! of container. + //! + //! <b>Effects</b>: Returns a const reference to the container associated to the end iterator + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Logarithmic. + static const bstree_impl &container_from_iterator(const_iterator it) + { return container_from_end_iterator(it.end_iterator_from_it()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Effects</b>: Returns the key_compare object used by the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: If value_compare copy-constructor throws. + key_compare key_comp() const; + + //! <b>Effects</b>: Returns the value_compare object used by the container. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: If value_compare copy-constructor throws. + value_compare value_comp() const; + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Effects</b>: Returns true if the container is empty. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + bool empty() const + { + if(ConstantTimeSize){ + return !this->data_type::sz_traits().get_size(); + } + else{ + return algo_type::unique(this->header_ptr()); + } + } + + //! <b>Effects</b>: Returns the number of elements stored in the container. + //! + //! <b>Complexity</b>: Linear to elements contained in *this + //! if constant-time size option is disabled. Constant time otherwise. + //! + //! <b>Throws</b>: Nothing. + size_type size() const + { + if(constant_time_size) + return this->sz_traits().get_size(); + else{ + return (size_type)node_algorithms::size(this->header_ptr()); + } + } + + //! <b>Effects</b>: Swaps the contents of two containers. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: If the comparison functor's swap call throws. + void swap(bstree_impl& other) + { + //This can throw + using std::swap; + swap(this->comp(), this->comp()); + //These can't throw + node_algorithms::swap_tree(this->header_ptr(), node_ptr(other.header_ptr())); + if(constant_time_size){ + size_type backup = this->sz_traits().get_size(); + this->sz_traits().set_size(other.sz_traits().get_size()); + other.sz_traits().set_size(backup); + } + } + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! Cloner should yield to nodes equivalent to the original nodes. + //! + //! <b>Effects</b>: Erases all the elements from *this + //! calling Disposer::operator()(pointer), clones all the + //! elements from src calling Cloner::operator()(const_reference ) + //! and inserts them on *this. Copies the predicate from the source container. + //! + //! If cloner throws, all cloned elements are unlinked and disposed + //! calling Disposer::operator()(pointer). + //! + //! <b>Complexity</b>: Linear to erased plus inserted elements. + //! + //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + template <class Cloner, class Disposer> + void clone_from(const bstree_impl &src, Cloner cloner, Disposer disposer) + { + this->clear_and_dispose(disposer); + if(!src.empty()){ + detail::exception_disposer<bstree_impl, Disposer> + rollback(*this, disposer); + node_algorithms::clone + (const_node_ptr(src.header_ptr()) + ,node_ptr(this->header_ptr()) + ,detail::node_cloner <Cloner, value_traits, AlgoType>(cloner, &this->get_value_traits()) + ,detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits())); + this->sz_traits().set_size(src.sz_traits().get_size()); + this->comp() = src.comp(); + rollback.release(); + } + } + + //! <b>Requires</b>: value must be an lvalue + //! + //! <b>Effects</b>: Inserts value into the container before the upper bound. + //! + //! <b>Complexity</b>: Average complexity for insert element is at + //! most logarithmic. + //! + //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + iterator insert_equal(reference value) + { + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->comp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + iterator ret(node_algorithms::insert_equal_upper_bound + (this->header_ptr(), to_insert, key_node_comp), this->priv_value_traits_ptr()); + this->sz_traits().increment(); + return ret; + } + + //! <b>Requires</b>: value must be an lvalue, and "hint" must be + //! a valid iterator. + //! + //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to + //! where it will be inserted. If "hint" is the upper_bound + //! the insertion takes constant time (two comparisons in the worst case) + //! + //! <b>Complexity</b>: Logarithmic in general, but it is amortized + //! constant time if t is inserted immediately before hint. + //! + //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + iterator insert_equal(const_iterator hint, reference value) + { + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->comp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + iterator ret(node_algorithms::insert_equal + (this->header_ptr(), hint.pointed_node(), to_insert, key_node_comp), this->priv_value_traits_ptr()); + this->sz_traits().increment(); + return ret; + } + + //! <b>Requires</b>: Dereferencing iterator must yield an lvalue + //! of type value_type. + //! + //! <b>Effects</b>: Inserts a each element of a range into the container + //! before the upper bound of the key of each element. + //! + //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the + //! size of the range. However, it is linear in N if the range is already sorted + //! by value_comp(). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + template<class Iterator> + void insert_equal(Iterator b, Iterator e) + { + iterator iend(this->end()); + for (; b != e; ++b) + this->insert_equal(iend, *b); + } + + //! <b>Requires</b>: value must be an lvalue + //! + //! <b>Effects</b>: Inserts value into the container if the value + //! is not already present. + //! + //! <b>Complexity</b>: Average complexity for insert element is at + //! most logarithmic. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + std::pair<iterator, bool> insert_unique(reference value) + { + insert_commit_data commit_data; + std::pair<iterator, bool> ret = this->insert_unique_check(value, this->comp(), commit_data); + if(!ret.second) + return ret; + return std::pair<iterator, bool> (this->insert_unique_commit(value, commit_data), true); + } + + //! <b>Requires</b>: value must be an lvalue, and "hint" must be + //! a valid iterator + //! + //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint + //! to where it will be inserted. + //! + //! <b>Complexity</b>: Logarithmic in general, but it is amortized + //! constant time (two comparisons in the worst case) + //! if t is inserted immediately before hint. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + iterator insert_unique(const_iterator hint, reference value) + { + insert_commit_data commit_data; + std::pair<iterator, bool> ret = this->insert_unique_check(hint, value, this->comp(), commit_data); + if(!ret.second) + return ret.first; + return this->insert_unique_commit(value, commit_data); + } + + //! <b>Requires</b>: Dereferencing iterator must yield an lvalue + //! of type value_type. + //! + //! <b>Effects</b>: Tries to insert each element of a range into the container. + //! + //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the + //! size of the range. However, it is linear in N if the range is already sorted + //! by value_comp(). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Does not affect the validity of iterators and references. + //! No copy-constructors are called. + template<class Iterator> + void insert_unique(Iterator b, Iterator e) + { + if(this->empty()){ + iterator iend(this->end()); + for (; b != e; ++b) + this->insert_unique(iend, *b); + } + else{ + for (; b != e; ++b) + this->insert_unique(*b); + } + } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Requires</b>: key_value_comp must be a comparison function that induces + //! the same strict weak ordering as value_compare. The difference is that + //! key_value_comp compares an arbitrary key with the contained values. + //! + //! <b>Effects</b>: Checks if a value can be inserted in the container, using + //! a user provided key instead of the value itself. + //! + //! <b>Returns</b>: If there is an equivalent value + //! returns a pair containing an iterator to the already present value + //! and false. If the value can be inserted returns true in the returned + //! pair boolean and fills "commit_data" that is meant to be used with + //! the "insert_commit" function. + //! + //! <b>Complexity</b>: Average complexity is at most logarithmic. + //! + //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. + //! + //! <b>Notes</b>: This function is used to improve performance when constructing + //! a value_type is expensive: if there is an equivalent value + //! the constructed object must be discarded. Many times, the part of the + //! node that is used to impose the order is much cheaper to construct + //! than the value_type and this function offers the possibility to use that + //! part to check if the insertion will be successful. + //! + //! If the check is successful, the user can construct the value_type and use + //! "insert_commit" to insert the object in constant-time. This gives a total + //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). + //! + //! "commit_data" remains valid for a subsequent "insert_commit" only if no more + //! objects are inserted or erased from the container. + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_unique_check + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + //! <b>Requires</b>: key_value_comp must be a comparison function that induces + //! the same strict weak ordering as value_compare. The difference is that + //! key_value_comp compares an arbitrary key with the contained values. + //! + //! <b>Effects</b>: Checks if a value can be inserted in the container, using + //! a user provided key instead of the value itself, using "hint" + //! as a hint to where it will be inserted. + //! + //! <b>Returns</b>: If there is an equivalent value + //! returns a pair containing an iterator to the already present value + //! and false. If the value can be inserted returns true in the returned + //! pair boolean and fills "commit_data" that is meant to be used with + //! the "insert_commit" function. + //! + //! <b>Complexity</b>: Logarithmic in general, but it's amortized + //! constant time if t is inserted immediately before hint. + //! + //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. + //! + //! <b>Notes</b>: This function is used to improve performance when constructing + //! a value_type is expensive: if there is an equivalent value + //! the constructed object must be discarded. Many times, the part of the + //! constructing that is used to impose the order is much cheaper to construct + //! than the value_type and this function offers the possibility to use that key + //! to check if the insertion will be successful. + //! + //! If the check is successful, the user can construct the value_type and use + //! "insert_commit" to insert the object in constant-time. This can give a total + //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). + //! + //! "commit_data" remains valid for a subsequent "insert_commit" only if no more + //! objects are inserted or erased from the container. + template<class KeyType, class KeyValueCompare> + std::pair<iterator, bool> insert_unique_check + (const_iterator hint, const KeyType &key + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data + //! must have been obtained from a previous call to "insert_check". + //! No objects should have been inserted or erased from the container between + //! the "insert_check" that filled "commit_data" and the call to "insert_commit". + //! + //! <b>Effects</b>: Inserts the value in the container using the information obtained + //! from the "commit_data" that a previous "insert_check" filled. + //! + //! <b>Returns</b>: An iterator to the newly inserted object. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Notes</b>: This function has only sense if a "insert_check" has been + //! previously executed to fill "commit_data". No value should be inserted or + //! erased between the "insert_check" and "insert_commit" calls. + iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) + { + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + node_algorithms::insert_unique_commit + (this->header_ptr(), to_insert, commit_data); + this->sz_traits().increment(); + return iterator(to_insert, this->priv_value_traits_ptr()); + } + + //! <b>Requires</b>: value must be an lvalue, "pos" must be + //! a valid iterator (or end) and must be the succesor of value + //! once inserted according to the predicate + //! + //! <b>Effects</b>: Inserts x into the container before "pos". + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This function does not check preconditions so if "pos" is not + //! the successor of "value" container ordering invariant will be broken. + //! This is a low-level function to be used only for performance reasons + //! by advanced users. + iterator insert_before(const_iterator pos, reference value) + { + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + this->sz_traits().increment(); + return iterator(node_algorithms::insert_before + (this->header_ptr(), pos.pointed_node(), to_insert), this->priv_value_traits_ptr()); + } + + //! <b>Requires</b>: value must be an lvalue, and it must be no less + //! than the greatest inserted key + //! + //! <b>Effects</b>: Inserts x into the container in the last position. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This function does not check preconditions so if value is + //! less than the greatest inserted key container ordering invariant will be broken. + //! This function is slightly more efficient than using "insert_before". + //! This is a low-level function to be used only for performance reasons + //! by advanced users. + void push_back(reference value) + { + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + this->sz_traits().increment(); + node_algorithms::push_back(this->header_ptr(), to_insert); + } + + //! <b>Requires</b>: value must be an lvalue, and it must be no greater + //! than the minimum inserted key + //! + //! <b>Effects</b>: Inserts x into the container in the first position. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This function does not check preconditions so if value is + //! greater than the minimum inserted key container ordering invariant will be broken. + //! This function is slightly more efficient than using "insert_before". + //! This is a low-level function to be used only for performance reasons + //! by advanced users. + void push_front(reference value) + { + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); + this->sz_traits().increment(); + node_algorithms::push_front(this->header_ptr(), to_insert); + } + + //! <b>Effects</b>: Erases the element pointed to by pos. + //! + //! <b>Complexity</b>: Average complexity for erase element is constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + iterator erase(const_iterator i) + { + const_iterator ret(i); + ++ret; + node_ptr to_erase(i.pointed_node()); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); + node_algorithms::erase(this->header_ptr(), to_erase); + this->sz_traits().decrement(); + if(safemode_or_autounlink) + node_algorithms::init(to_erase); + return ret.unconst(); + } + + //! <b>Effects</b>: Erases the range pointed to by b end e. + //! + //! <b>Complexity</b>: Average complexity for erase range is at most + //! O(log(size() + N)), where N is the number of elements in the range. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + iterator erase(const_iterator b, const_iterator e) + { size_type n; return this->private_erase(b, e, n); } + + //! <b>Effects</b>: Erases all the elements with the given value. + //! + //! <b>Returns</b>: The number of erased elements. + //! + //! <b>Complexity</b>: O(log(size() + N). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + size_type erase(const_reference value) + { return this->erase(value, this->comp()); } + + //! <b>Effects</b>: Erases all the elements with the given key. + //! according to the comparison functor "comp". + //! + //! <b>Returns</b>: The number of erased elements. + //! + //! <b>Complexity</b>: O(log(size() + N). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + template<class KeyType, class KeyValueCompare> + size_type erase(const KeyType& key, KeyValueCompare comp + /// @cond + , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 + /// @endcond + ) + { + std::pair<iterator,iterator> p = this->equal_range(key, comp); + size_type n; + this->private_erase(p.first, p.second, n); + return n; + } + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! + //! <b>Effects</b>: Erases the element pointed to by pos. + //! Disposer::operator()(pointer) is called for the removed element. + //! + //! <b>Complexity</b>: Average complexity for erase element is constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators + //! to the erased elements. + template<class Disposer> + iterator erase_and_dispose(const_iterator i, Disposer disposer) + { + node_ptr to_erase(i.pointed_node()); + iterator ret(this->erase(i)); + disposer(this->get_value_traits().to_value_ptr(to_erase)); + return ret; + } + + #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class Disposer> + iterator erase_and_dispose(iterator i, Disposer disposer) + { return this->erase_and_dispose(const_iterator(i), disposer); } + #endif + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! + //! <b>Effects</b>: Erases all the elements with the given value. + //! Disposer::operator()(pointer) is called for the removed elements. + //! + //! <b>Returns</b>: The number of erased elements. + //! + //! <b>Complexity</b>: O(log(size() + N). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + template<class Disposer> + size_type erase_and_dispose(const_reference value, Disposer disposer) + { + std::pair<iterator,iterator> p = this->equal_range(value); + size_type n; + this->private_erase(p.first, p.second, n, disposer); + return n; + } + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! + //! <b>Effects</b>: Erases the range pointed to by b end e. + //! Disposer::operator()(pointer) is called for the removed elements. + //! + //! <b>Complexity</b>: Average complexity for erase range is at most + //! O(log(size() + N)), where N is the number of elements in the range. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators + //! to the erased elements. + template<class Disposer> + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) + { size_type n; return this->private_erase(b, e, n, disposer); } + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! + //! <b>Effects</b>: Erases all the elements with the given key. + //! according to the comparison functor "comp". + //! Disposer::operator()(pointer) is called for the removed elements. + //! + //! <b>Returns</b>: The number of erased elements. + //! + //! <b>Complexity</b>: O(log(size() + N). + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators + //! to the erased elements. + template<class KeyType, class KeyValueCompare, class Disposer> + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer + /// @cond + , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 + /// @endcond + ) + { + std::pair<iterator,iterator> p = this->equal_range(key, comp); + size_type n; + this->private_erase(p.first, p.second, n, disposer); + return n; + } + + //! <b>Effects</b>: Erases all of the elements. + //! + //! <b>Complexity</b>: Linear to the number of elements on the container. + //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. No destructors are called. + void clear() + { + if(safemode_or_autounlink){ + this->clear_and_dispose(detail::null_disposer()); + } + else{ + node_algorithms::init_header(this->header_ptr()); + this->sz_traits().set_size(0); + } + } + + //! <b>Effects</b>: Erases all of the elements calling disposer(p) for + //! each node to be erased. + //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)), + //! where N is the number of elements in the container. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: Invalidates the iterators (but not the references) + //! to the erased elements. Calls N times to disposer functor. + template<class Disposer> + void clear_and_dispose(Disposer disposer) + { + node_algorithms::clear_and_dispose(this->header_ptr() + , detail::node_disposer<Disposer, value_traits, AlgoType>(disposer, &this->get_value_traits())); + node_algorithms::init_header(this->header_ptr()); + this->sz_traits().set_size(0); + } + + //! <b>Effects</b>: Returns the number of contained elements with the given value + //! + //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal + //! to number of objects with the given value. + //! + //! <b>Throws</b>: If `value_compare` throws. + size_type count(const_reference value) const + { return size_type(this->count(value, this->comp())); } + + //! <b>Effects</b>: Returns the number of contained elements with the given key + //! + //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal + //! to number of objects with the given key. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + size_type count(const KeyType &key, KeyValueCompare comp) const + { + std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); + size_type n = 0; + for(; ret.first != ret.second; ++ret.first){ ++n; } + return n; + } + + #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + + //Add non-const overloads to theoretically const members + //as some algorithms have different behavior when non-const versions are used (like splay trees). + size_type count(const_reference value) + { return size_type(this->count(value, this->comp())); } + + template<class KeyType, class KeyValueCompare> + size_type count(const KeyType &key, KeyValueCompare comp) + { + std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); + size_type n = 0; + for(; ret.first != ret.second; ++ret.first){ ++n; } + return n; + } + + #else //defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is not less than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + iterator lower_bound(const_reference value); + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is not less than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + const_iterator lower_bound(const_reference value) const; + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is not less than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + iterator lower_bound(const KeyType &key, KeyValueCompare comp); + + //! <b>Effects</b>: Returns a const iterator to the first element whose + //! key is not less than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const; + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is greater than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + iterator upper_bound(const_reference value); + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is greater than k according to comp or end() if that element + //! does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + iterator upper_bound(const KeyType &key, KeyValueCompare comp); + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is greater than k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + const_iterator upper_bound(const_reference value) const; + + //! <b>Effects</b>: Returns an iterator to the first element whose + //! key is greater than k according to comp or end() if that element + //! does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const; + + //! <b>Effects</b>: Finds an iterator to the first element whose key is + //! k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + iterator find(const_reference value); + + //! <b>Effects</b>: Finds an iterator to the first element whose key is + //! k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + iterator find(const KeyType &key, KeyValueCompare comp); + + //! <b>Effects</b>: Finds a const_iterator to the first element whose key is + //! k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + const_iterator find(const_reference value) const; + + //! <b>Effects</b>: Finds a const_iterator to the first element whose key is + //! k or end() if that element does not exist. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + const_iterator find(const KeyType &key, KeyValueCompare comp) const; + + //! <b>Effects</b>: Finds a range containing all elements whose key is k or + //! an empty range that indicates the position where those elements would be + //! if they there is no elements with key k. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + std::pair<iterator,iterator> equal_range(const_reference value); + + //! <b>Effects</b>: Finds a range containing all elements whose key is k or + //! an empty range that indicates the position where those elements would be + //! if they there is no elements with key k. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp); + + //! <b>Effects</b>: Finds a range containing all elements whose key is k or + //! an empty range that indicates the position where those elements would be + //! if they there is no elements with key k. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + std::pair<const_iterator, const_iterator> + equal_range(const_reference value) const; + + //! <b>Effects</b>: Finds a range containing all elements whose key is k or + //! an empty range that indicates the position where those elements would be + //! if they there is no elements with key k. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> + equal_range(const KeyType &key, KeyValueCompare comp) const; + + //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If + //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. + //! + //! <b>Effects</b>: Returns an a pair with the following criteria: + //! + //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise + //! + //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + //! + //! <b>Note</b>: This function can be more efficient than calling upper_bound + //! and lower_bound for lower_value and upper_value. + //! + //! <b>Note</b>: Experimental function, the interface might change in future releases. + std::pair<iterator,iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the container. + //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If + //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. + //! + //! <b>Effects</b>: Returns an a pair with the following criteria: + //! + //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise + //! + //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + //! + //! <b>Note</b>: This function can be more efficient than calling upper_bound + //! and lower_bound for lower_key and upper_key. + //! + //! <b>Note</b>: Experimental function, the interface might change in future releases. + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> bounded_range + (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If + //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. + //! + //! <b>Effects</b>: Returns an a pair with the following criteria: + //! + //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise + //! + //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `value_compare` throws. + //! + //! <b>Note</b>: This function can be more efficient than calling upper_bound + //! and lower_bound for lower_value and upper_value. + //! + //! <b>Note</b>: Experimental function, the interface might change in future releases. + std::pair<const_iterator,const_iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the container. + //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If + //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. + //! + //! <b>Effects</b>: Returns an a pair with the following criteria: + //! + //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise + //! + //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If `comp` throws. + //! + //! <b>Note</b>: This function can be more efficient than calling upper_bound + //! and lower_bound for lower_key and upper_key. + //! + //! <b>Note</b>: Experimental function, the interface might change in future releases. + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator,const_iterator> bounded_range + (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; + + //! <b>Requires</b>: value must be an lvalue and shall be in a set of + //! appropriate type. Otherwise the behavior is undefined. + //! + //! <b>Effects</b>: Returns: a valid iterator i belonging to the set + //! that points to the value + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This static function is available only if the <i>value traits</i> + //! is stateless. + static iterator s_iterator_to(reference value); + + //! <b>Requires</b>: value must be an lvalue and shall be in a set of + //! appropriate type. Otherwise the behavior is undefined. + //! + //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the + //! set that points to the value + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This static function is available only if the <i>value traits</i> + //! is stateless. + static const_iterator s_iterator_to(const_reference value); + + //! <b>Requires</b>: value must be an lvalue and shall be in a set of + //! appropriate type. Otherwise the behavior is undefined. + //! + //! <b>Effects</b>: Returns: a valid iterator i belonging to the set + //! that points to the value + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + iterator iterator_to(reference value); + + //! <b>Requires</b>: value must be an lvalue and shall be in a set of + //! appropriate type. Otherwise the behavior is undefined. + //! + //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the + //! set that points to the value + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + const_iterator iterator_to(const_reference value) const; + + //! <b>Requires</b>: value shall not be in a container. + //! + //! <b>Effects</b>: init_node puts the hook of a value in a well-known default + //! state. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Note</b>: This function puts the hook in the well-known default state + //! used by auto_unlink and safe hooks. + static void init_node(reference value); + + #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + + //! <b>Effects</b>: Unlinks the leftmost node from the container. + //! + //! <b>Complexity</b>: Average complexity is constant time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Notes</b>: This function breaks the container and the container can + //! only be used for more unlink_leftmost_without_rebalance calls. + //! This function is normally used to achieve a step by step + //! controlled destruction of the container. + pointer unlink_leftmost_without_rebalance() + { + node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance + (this->header_ptr())); + if(!to_be_disposed) + return 0; + this->sz_traits().decrement(); + if(safemode_or_autounlink)//If this is commented does not work with normal_link + node_algorithms::init(to_be_disposed); + return this->get_value_traits().to_value_ptr(to_be_disposed); + } + + #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + + //! <b>Requires</b>: replace_this must be a valid iterator of *this + //! and with_this must not be inserted in any container. + //! + //! <b>Effects</b>: Replaces replace_this in its position in the + //! container with with_this. The container does not need to be rebalanced. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: This function will break container ordering invariants if + //! with_this is not equivalent to *replace_this according to the + //! ordering rules. This function is faster than erasing and inserting + //! the node, since no rebalancing or comparison is needed. + void replace_node(iterator replace_this, reference with_this); + + //! <b>Effects</b>: Rebalances the tree. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Linear. + void rebalance(); + + //! <b>Requires</b>: old_root is a node of a tree. + //! + //! <b>Effects</b>: Rebalances the subtree rooted at old_root. + //! + //! <b>Returns</b>: The new root of the subtree. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Linear to the elements in the subtree. + iterator rebalance_subtree(iterator root); + + #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + + //! <b>Effects</b>: removes "value" from the container. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Logarithmic time. + //! + //! <b>Note</b>: This static function is only usable with non-constant + //! time size containers that have stateless comparison functors. + //! + //! If the user calls + //! this function with a constant time size container or stateful comparison + //! functor a compilation error will be issued. + static void remove_node(reference value) + { + BOOST_STATIC_ASSERT((!constant_time_size)); + node_ptr to_remove(value_traits::to_node_ptr(value)); + node_algorithms::unlink(to_remove); + if(safemode_or_autounlink) + node_algorithms::init(to_remove); + } + + //! <b>Effects</b>: Asserts the integrity of the container with additional checks provided by the user. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Note</b>: The method might not have effect when asserts are turned off (e.g., with NDEBUG). + //! Experimental function, interface might change in future versions. + template <class ExtraChecker> + void check(ExtraChecker extra_checker) const + { + typedef detail::key_nodeptr_comp<value_compare, value_traits> nodeptr_comp_t; + nodeptr_comp_t nodeptr_comp(this->comp(), &this->get_value_traits()); + typedef typename get_node_checker<AlgoType, ValueTraits, nodeptr_comp_t, ExtraChecker>::type node_checker_t; + typename node_checker_t::return_type checker_return; + node_algorithms::check(this->header_ptr(), node_checker_t(nodeptr_comp, extra_checker), checker_return); + if (constant_time_size) + BOOST_INTRUSIVE_INVARIANT_ASSERT(this->sz_traits().get_size() == checker_return.node_count); + } + + //! <b>Effects</b>: Asserts the integrity of the container. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG). + //! Experimental function, interface might change in future versions. + void check() const + { + check(detail::empty_node_checker<ValueTraits>()); + } + + /// @cond + private: + template<class Disposer> + iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer) + { + for(n = 0; b != e; ++n) + this->erase_and_dispose(b++, disposer); + return b.unconst(); + } + + iterator private_erase(const_iterator b, const_iterator e, size_type &n) + { + for(n = 0; b != e; ++n) + this->erase(b++); + return b.unconst(); + } + /// @endcond +}; + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline bool operator< +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +bool operator== +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ + typedef bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> tree_type; + typedef typename tree_type::const_iterator const_iterator; + + if(tree_type::constant_time_size && x.size() != y.size()){ + return false; + } + const_iterator end1 = x.end(); + const_iterator i1 = x.begin(); + const_iterator i2 = y.begin(); + if(tree_type::constant_time_size){ + while (i1 != end1 && *i1 == *i2) { + ++i1; + ++i2; + } + return i1 == end1; + } + else{ + const_iterator end2 = y.end(); + while (i1 != end1 && i2 != end2 && *i1 == *i2) { + ++i1; + ++i2; + } + return i1 == end1 && i2 == end2; + } +} + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline bool operator!= +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ return !(x == y); } + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline bool operator> +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ return y < x; } + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline bool operator<= +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ return !(y < x); } + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline bool operator>= +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(const bstree_impl<T, Options...> &x, const bstree_impl<T, Options...> &y) +#else +( const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, const bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ return !(x < y); } + +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +template<class T, class ...Options> +#else +template<class ValueTraits, class VoidKeyComp, class SizeType, bool ConstantTimeSize, algo_types AlgoType, typename HeaderHolder> +#endif +inline void swap +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) +(bstree_impl<T, Options...> &x, bstree_impl<T, Options...> &y) +#else +( bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &x +, bstree_impl<ValueTraits, VoidKeyComp, SizeType, ConstantTimeSize, AlgoType, HeaderHolder> &y) +#endif +{ x.swap(y); } + +//! Helper metafunction to define a \c bstree that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> +#endif +struct make_bstree +{ + /// @cond + typedef typename pack_options + < bstree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef bstree_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , BsTreeAlgorithms + , header_holder_type + > implementation_defined; + /// @endcond + typedef implementation_defined type; +}; + + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template<class T, class O1, class O2, class O3, class O4, class O5> +#else +template<class T, class ...Options> +#endif +class bstree + : public make_bstree<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type +{ + typedef typename make_bstree + <T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type Base; + BOOST_MOVABLE_BUT_NOT_COPYABLE(bstree) + + public: + typedef typename Base::value_compare value_compare; + typedef typename Base::value_traits value_traits; + typedef typename Base::iterator iterator; + typedef typename Base::const_iterator const_iterator; + + //Assert if passed value traits are compatible with the type + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); + + bstree( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(cmp, v_traits) + {} + + template<class Iterator> + bstree( bool unique, Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : Base(unique, b, e, cmp, v_traits) + {} + + bstree(BOOST_RV_REF(bstree) x) + : Base(::boost::move(static_cast<Base&>(x))) + {} + + bstree& operator=(BOOST_RV_REF(bstree) x) + { return static_cast<bstree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } + + static bstree &container_from_end_iterator(iterator end_iterator) + { return static_cast<bstree &>(Base::container_from_end_iterator(end_iterator)); } + + static const bstree &container_from_end_iterator(const_iterator end_iterator) + { return static_cast<const bstree &>(Base::container_from_end_iterator(end_iterator)); } + + static bstree &container_from_iterator(iterator it) + { return static_cast<bstree &>(Base::container_from_iterator(it)); } + + static const bstree &container_from_iterator(const_iterator it) + { return static_cast<const bstree &>(Base::container_from_iterator(it)); } +}; + +#endif +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_BSTREE_HPP diff --git a/boost/intrusive/detail/tree_algorithms.hpp b/boost/intrusive/bstree_algorithms.hpp index c92d39b3b9..de5445ec52 100644 --- a/boost/intrusive/detail/tree_algorithms.hpp +++ b/boost/intrusive/bstree_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -10,20 +10,95 @@ // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP -#define BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP +#ifndef BOOST_INTRUSIVE_BSTREE_ALGORITHMS_HPP +#define BOOST_INTRUSIVE_BSTREE_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <cstddef> #include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <cstddef> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/assert.hpp> +#include <boost/intrusive/detail/uncast.hpp> +#include <boost/intrusive/detail/math.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <utility> namespace boost { namespace intrusive { + +/// @cond + +//! This type is the information that will be filled by insert_unique_check +template <class NodePtr> +struct insert_commit_data_t +{ + insert_commit_data_t() + : link_left(false) + , node() + {} + bool link_left; + NodePtr node; +}; + +template <class NodePtr> +struct data_for_rebalance_t +{ + NodePtr x; + NodePtr x_parent; + NodePtr y; +}; + namespace detail { +template<class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct bstree_node_checker + : public ExtraChecker +{ + typedef ExtraChecker base_checker_t; + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::const_node_ptr const_node_ptr; + + struct return_type + : public base_checker_t::return_type + { + return_type() : min_key_node_ptr(const_node_ptr()), max_key_node_ptr(const_node_ptr()), node_count(0) {} + + const_node_ptr min_key_node_ptr; + const_node_ptr max_key_node_ptr; + size_t node_count; + }; + + bstree_node_checker(const NodePtrCompare& comp, ExtraChecker extra_checker) + : base_checker_t(extra_checker), comp_(comp) + {} + + void operator () (const const_node_ptr& p, + const return_type& check_return_left, const return_type& check_return_right, + return_type& check_return) + { + if (check_return_left.max_key_node_ptr) + BOOST_INTRUSIVE_INVARIANT_ASSERT(!comp_(p, check_return_left.max_key_node_ptr)); + if (check_return_right.min_key_node_ptr) + BOOST_INTRUSIVE_INVARIANT_ASSERT(!comp_(check_return_right.min_key_node_ptr, p)); + check_return.min_key_node_ptr = node_traits::get_left(p)? check_return_left.min_key_node_ptr : p; + check_return.max_key_node_ptr = node_traits::get_right(p)? check_return_right.max_key_node_ptr : p; + check_return.node_count = check_return_left.node_count + check_return_right.node_count + 1; + base_checker_t::operator()(p, check_return_left, check_return_right, check_return); + } + + const NodePtrCompare comp_; +}; + +} // namespace detail + +/// @endcond + + + //! This is an implementation of a binary search tree. //! A node in the search tree has references to its children and its parent. This //! is to allow traversal of the whole tree from a given node making the @@ -66,14 +141,13 @@ namespace detail { //! | | | | | | | | //! +---------+ +---------+ +---------+ +---------+ //! - -//! tree_algorithms is configured with a NodeTraits class, which encapsulates the +//! bstree_algorithms is configured with a NodeTraits class, which encapsulates the //! information about the node to be manipulated. NodeTraits must support the //! following interface: //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the binary search tree //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -93,31 +167,18 @@ namespace detail { //! //! <tt>static void set_right(node_ptr n, node_ptr right);</tt> template<class NodeTraits> -class tree_algorithms +class bstree_algorithms { public: typedef typename NodeTraits::node node; typedef NodeTraits node_traits; typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; - - //! This type is the information that will be filled by insert_unique_check - struct insert_commit_data - { - insert_commit_data() - : link_left(false) - , node() - {} - bool link_left; - node_ptr node; - }; - - struct nop_erase_fixup - { - void operator()(const node_ptr&, const node_ptr&){} - }; + typedef insert_commit_data_t<node_ptr> insert_commit_data; + typedef data_for_rebalance_t<node_ptr> data_for_rebalance; /// @cond + private: template<class Disposer> struct dispose_subtree_disposer @@ -136,22 +197,46 @@ class tree_algorithms } } Disposer *disposer_; - node_ptr subtree_; + const node_ptr subtree_; }; - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - /// @endcond public: + //! <b>Requires</b>: 'header' is the header node of a tree. + //! + //! <b>Effects</b>: Returns the first node of the tree, the header if the tree is empty. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. static node_ptr begin_node(const const_node_ptr & header) { return node_traits::get_left(header); } + //! <b>Requires</b>: 'header' is the header node of a tree. + //! + //! <b>Effects</b>: Returns the header of the tree. + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. static node_ptr end_node(const const_node_ptr & header) - { return uncast(header); } + { return detail::uncast(header); } + + //! <b>Requires</b>: 'header' is the header node of a tree. + //! + //! <b>Effects</b>: Returns the root of the tree if any, header otherwise + //! + //! <b>Complexity</b>: Constant time. + //! + //! <b>Throws</b>: Nothing. + static node_ptr root_node(const const_node_ptr & header) + { + node_ptr p = node_traits::get_parent(header); + return p ? p : detail::uncast(header); + } - //! <b>Requires</b>: 'node' is a node of the tree or an node initialized + //! <b>Requires</b>: 'node' is a node of the tree or a node initialized //! by init(...) or init_node. //! //! <b>Effects</b>: Returns true if the node is initialized by init() or init_node(). @@ -162,15 +247,48 @@ class tree_algorithms static bool unique(const const_node_ptr & node) { return !NodeTraits::get_parent(node); } + //! <b>Requires</b>: 'node' is a node of the tree or a header node. + //! + //! <b>Effects</b>: Returns the header of the tree. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: Nothing. static node_ptr get_header(const const_node_ptr & node) { - node_ptr h = uncast(node); - if(NodeTraits::get_parent(node)){ - h = NodeTraits::get_parent(node); - while(!is_header(h)) - h = NodeTraits::get_parent(h); + node_ptr n(detail::uncast(node)); + node_ptr p(NodeTraits::get_parent(node)); + //If p is null, then n is the header of an empty tree + if(p){ + //Non-empty tree, check if n is neither root nor header + node_ptr pp(NodeTraits::get_parent(p)); + //If granparent is not equal to n, then n is neither root nor header, + //the try the fast path + if(n != pp){ + do{ + n = p; + p = pp; + pp = NodeTraits::get_parent(pp); + }while(n != pp); + n = p; + } + //Check if n is root or header when size() > 0 + else if(!is_header(n)){ + n = p; + } + } + return n; + /* + node_ptr h = detail::uncast(node); + node_ptr p = NodeTraits::get_parent(node); + if(p){ + while(!is_header(p)) + p = NodeTraits::get_parent(p); + return p; } - return h; + else{ + return h; + }*/ } //! <b>Requires</b>: node1 and node2 can't be header nodes @@ -358,9 +476,7 @@ class tree_algorithms //! <b>Note</b>: This function will break container ordering invariants if //! new_node is not equivalent to node_to_be_replaced according to the //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function + //! the node, since no rebalancing and comparison is needed. Experimental function static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) { if(node_to_be_replaced == new_node) @@ -381,9 +497,7 @@ class tree_algorithms //! <b>Note</b>: This function will break container ordering invariants if //! new_node is not equivalent to node_to_be_replaced according to the //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function + //! the node, since no rebalancing or comparison is needed. Experimental function static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) { if(node_to_be_replaced == new_node) @@ -436,18 +550,18 @@ class tree_algorithms //! <b>Throws</b>: Nothing. static node_ptr next_node(const node_ptr & node) { - node_ptr p_right(NodeTraits::get_right(node)); - if(p_right){ - return minimum(p_right); + node_ptr const n_right(NodeTraits::get_right(node)); + if(n_right){ + return minimum(n_right); } else { - node_ptr p(node); - node_ptr x = NodeTraits::get_parent(p); - while(p == NodeTraits::get_right(x)){ - p = x; - x = NodeTraits::get_parent(x); + node_ptr n(node); + node_ptr p(NodeTraits::get_parent(n)); + while(n == NodeTraits::get_right(p)){ + n = p; + p = NodeTraits::get_parent(p); } - return NodeTraits::get_right(p) != x ? x : uncast(p); + return NodeTraits::get_right(n) != p ? p : n; } } @@ -485,15 +599,14 @@ class tree_algorithms //! <b>Complexity</b>: Logarithmic to the size of the subtree. //! //! <b>Throws</b>: Nothing. - static node_ptr minimum (const node_ptr & node) + static node_ptr minimum(node_ptr node) { - node_ptr p(node); - for(node_ptr p_left = NodeTraits::get_left(p) + for(node_ptr p_left = NodeTraits::get_left(node) ;p_left - ;p_left = NodeTraits::get_left(p)){ - p = p_left; + ;p_left = NodeTraits::get_left(node)){ + node = p_left; } - return p; + return node; } //! <b>Requires</b>: 'node' is a node of a tree but not the header. @@ -503,15 +616,14 @@ class tree_algorithms //! <b>Complexity</b>: Logarithmic to the size of the subtree. //! //! <b>Throws</b>: Nothing. - static node_ptr maximum(const node_ptr & node) + static node_ptr maximum(node_ptr node) { - node_ptr p(node); - for(node_ptr p_right = NodeTraits::get_right(p) + for(node_ptr p_right = NodeTraits::get_right(node) ;p_right - ;p_right = NodeTraits::get_right(p)){ - p = p_right; + ;p_right = NodeTraits::get_right(node)){ + node = p_right; } - return p; + return node; } //! <b>Requires</b>: 'node' must not be part of any tree. @@ -604,7 +716,7 @@ class tree_algorithms if (leftmost_right){ NodeTraits::set_parent(leftmost_right, leftmost_parent); - NodeTraits::set_left(header, tree_algorithms::minimum(leftmost_right)); + NodeTraits::set_left(header, bstree_algorithms::minimum(leftmost_right)); if (is_root) NodeTraits::set_parent(header, leftmost_right); @@ -630,42 +742,6 @@ class tree_algorithms //! <b>Complexity</b>: Linear time. //! //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & subtree) - { - if(!subtree) return 0; - std::size_t count = 0; - node_ptr p = minimum(uncast(subtree)); - bool continue_looping = true; - while(continue_looping){ - ++count; - node_ptr p_right(NodeTraits::get_right(p)); - if(p_right){ - p = minimum(p_right); - } - else { - for(;;){ - node_ptr q; - if (p == subtree){ - continue_looping = false; - break; - } - q = p; - p = NodeTraits::get_parent(p); - if (NodeTraits::get_left(p) == q) - break; - } - } - } - return count; - } - - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. static std::size_t size(const const_node_ptr & header) { node_ptr beg(begin_node(header)); @@ -724,6 +800,13 @@ class tree_algorithms } } + //! <b>Requires</b>: p is a node of a tree. + //! + //! <b>Effects</b>: Returns true if p is the header of the tree. + //! + //! <b>Complexity</b>: Constant. + //! + //! <b>Throws</b>: Nothing. static bool is_header(const const_node_ptr & p) { node_ptr p_left (NodeTraits::get_left(p)); @@ -746,7 +829,7 @@ class tree_algorithms //! ordering compatible with the strict weak ordering used to create the //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to + //! <b>Effects</b>: Returns a node_ptr to the first element that is equivalent to //! "key" according to "comp" or "header" if that element does not exist. //! //! <b>Complexity</b>: Logarithmic. @@ -756,7 +839,7 @@ class tree_algorithms static node_ptr find (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - node_ptr end = uncast(header); + node_ptr end = detail::uncast(header); node_ptr y = lower_bound(header, key, comp); return (y == end || comp(key, y)) ? end : y; } @@ -780,6 +863,8 @@ class tree_algorithms //! //! <b>Note</b>: This function can be more efficient than calling upper_bound //! and lower_bound for lower_key and upper_key. + //! + //! <b>Note</b>: Experimental function, the interface might change. template< class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range ( const const_node_ptr & header @@ -789,7 +874,7 @@ class tree_algorithms , bool left_closed , bool right_closed) { - node_ptr y = uncast(header); + node_ptr y = detail::uncast(header); node_ptr x = NodeTraits::get_parent(header); while(x){ @@ -803,7 +888,6 @@ class tree_algorithms //If the upper_key is less than x, the target //range is on the left part else if(comp(upper_key, x)){ - //y > upper_key y = x; x = NodeTraits::get_left(x); } @@ -842,6 +926,30 @@ class tree_algorithms //! ordering compatible with the strict weak ordering used to create the //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. //! + //! <b>Effects</b>: Returns the number of elements with a key equivalent to "key" + //! according to "comp". + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If "comp" throws. + template<class KeyType, class KeyNodePtrCompare> + static std::size_t count + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { + std::pair<node_ptr, node_ptr> ret = equal_range(header, key, comp); + std::size_t n = 0; + while(ret.first != ret.second){ + ++n; + ret.first = next_node(ret.first); + } + return n; + } + + //! <b>Requires</b>: "header" must be the header node of a tree. + //! KeyNodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. + //! //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing //! all elements that are equivalent to "key" according to "comp" or an //! empty range that indicates the position where those elements would be @@ -862,7 +970,32 @@ class tree_algorithms //! ordering compatible with the strict weak ordering used to create the //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is + //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing + //! the first element that is equivalent to "key" according to "comp" or an + //! empty range that indicates the position where that element would be + //! if there are no equivalent elements. + //! + //! <b>Complexity</b>: Logarithmic. + //! + //! <b>Throws</b>: If "comp" throws. + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, node_ptr> lower_bound_range + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { + node_ptr const lb(lower_bound(header, key, comp)); + std::pair<node_ptr, node_ptr> ret_ii(lb, lb); + if(lb != header && !comp(key, lb)){ + ret_ii.second = next_node(ret_ii.second); + } + return ret_ii; + } + + //! <b>Requires</b>: "header" must be the header node of a tree. + //! KeyNodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. + //! + //! <b>Effects</b>: Returns a node_ptr to the first element that is //! not less than "key" according to "comp" or "header" if that element does //! not exist. //! @@ -873,7 +1006,7 @@ class tree_algorithms static node_ptr lower_bound (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - return lower_bound_loop(NodeTraits::get_parent(header), uncast(header), key, comp); + return lower_bound_loop(NodeTraits::get_parent(header), detail::uncast(header), key, comp); } //! <b>Requires</b>: "header" must be the header node of a tree. @@ -881,7 +1014,7 @@ class tree_algorithms //! ordering compatible with the strict weak ordering used to create the //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater + //! <b>Effects</b>: Returns a node_ptr to the first element that is greater //! than "key" according to "comp" or "header" if that element does not exist. //! //! <b>Complexity</b>: Logarithmic. @@ -891,7 +1024,7 @@ class tree_algorithms static node_ptr upper_bound (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - return upper_bound_loop(NodeTraits::get_parent(header), uncast(header), key, comp); + return upper_bound_loop(NodeTraits::get_parent(header), detail::uncast(header), key, comp); } //! <b>Requires</b>: "header" must be the header node of a tree. @@ -915,32 +1048,6 @@ class tree_algorithms (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data) { return insert_commit(header, new_value, commit_data); } - static void insert_commit - (const node_ptr & header, const node_ptr & new_node, const insert_commit_data &commit_data) - { - //Check if commit_data has not been initialized by a insert_unique_check call. - BOOST_INTRUSIVE_INVARIANT_ASSERT(commit_data.node != node_ptr()); - node_ptr parent_node(commit_data.node); - if(parent_node == header){ - NodeTraits::set_parent(header, new_node); - NodeTraits::set_right(header, new_node); - NodeTraits::set_left(header, new_node); - } - else if(commit_data.link_left){ - NodeTraits::set_left(parent_node, new_node); - if(parent_node == NodeTraits::get_left(header)) - NodeTraits::set_left(header, new_node); - } - else{ - NodeTraits::set_right(parent_node, new_node); - if(parent_node == NodeTraits::get_right(header)) - NodeTraits::set_right(header, new_node); - } - NodeTraits::set_parent(new_node, parent_node); - NodeTraits::set_right(new_node, node_ptr()); - NodeTraits::set_left(new_node, node_ptr()); - } - //! <b>Requires</b>: "header" must be the header node of a tree. //! KeyNodePtrCompare is a function object that induces a strict weak //! ordering compatible with the strict weak ordering used to create the @@ -977,11 +1084,15 @@ class tree_algorithms //! if no more objects are inserted or erased from the set. template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check - (const const_node_ptr & header, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0) + (const const_node_ptr & header, const KeyType &key + ,KeyNodePtrCompare comp, insert_commit_data &commit_data + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { std::size_t depth = 0; - node_ptr h(uncast(header)); + node_ptr h(detail::uncast(header)); node_ptr y(h); node_ptr x(NodeTraits::get_parent(y)); node_ptr prev = node_ptr(); @@ -1001,28 +1112,67 @@ class tree_algorithms //Since we've found the upper bound there is no other value with the same key if: // - There is no previous node // - The previous node is less than the key - if(!prev || comp(prev, key)){ + const bool not_present = !prev || comp(prev, key); + if(not_present){ commit_data.link_left = left_child; commit_data.node = y; - return std::pair<node_ptr, bool>(node_ptr(), true); - } - //If the previous value was not less than key, it means that it's equal - //(because we've checked the upper bound) - else{ - return std::pair<node_ptr, bool>(prev, false); } + return std::pair<node_ptr, bool>(prev, not_present); } + //! <b>Requires</b>: "header" must be the header node of a tree. + //! KeyNodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. NodePtrCompare compares KeyType with a node_ptr. + //! "hint" is node from the "header"'s tree. + //! + //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the + //! tree according to "comp" using "hint" as a hint to where it should be + //! inserted and obtains the needed information to realize + //! a constant-time node insertion if there is no equivalent node. + //! If "hint" is the upper_bound the function has constant time + //! complexity (two comparisons in the worst case). + //! + //! <b>Returns</b>: If there is an equivalent value + //! returns a pair containing a node_ptr to the already present node + //! and false. If there is not equivalent key can be inserted returns true + //! in the returned pair's boolean and fills "commit_data" that is meant to + //! be used with the "insert_commit" function to achieve a constant-time + //! insertion function. + //! + //! <b>Complexity</b>: Average complexity is at most logarithmic, but it is + //! amortized constant time if new_node should be inserted immediately before "hint". + //! + //! <b>Throws</b>: If "comp" throws. + //! + //! <b>Notes</b>: This function is used to improve performance when constructing + //! a node is expensive and the user does not want to have two equivalent nodes + //! in the tree: if there is an equivalent value + //! the constructed object must be discarded. Many times, the part of the + //! node that is used to impose the order is much cheaper to construct + //! than the node and this function offers the possibility to use that part + //! to check if the insertion will be successful. + //! + //! If the check is successful, the user can construct the node and use + //! "insert_commit" to insert the node in constant-time. This gives a total + //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). + //! + //! "commit_data" remains valid for a subsequent "insert_unique_commit" only + //! if no more objects are inserted or erased from the set. template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const node_ptr &hint, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0) + ,KeyNodePtrCompare comp, insert_commit_data &commit_data + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { //hint must be bigger than the key if(hint == header || comp(key, hint)){ node_ptr prev(hint); //Previous value should be less than the key - if(hint == begin_node(header)|| comp((prev = prev_node(hint)), key)){ + if(hint == begin_node(header) || comp((prev = prev_node(hint)), key)){ commit_data.link_left = unique(header) || !NodeTraits::get_left(hint); commit_data.node = commit_data.link_left ? hint : prev; if(pdepth){ @@ -1035,44 +1185,27 @@ class tree_algorithms return insert_unique_check(header, key, comp, commit_data, pdepth); } - template<class NodePtrCompare> - static void insert_equal_check - (const node_ptr &header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp - , insert_commit_data &commit_data, std::size_t *pdepth = 0) - { - if(hint == header || !comp(hint, new_node)){ - node_ptr prev(hint); - if(hint == NodeTraits::get_left(header) || - !comp(new_node, (prev = prev_node(hint)))){ - bool link_left = unique(header) || !NodeTraits::get_left(hint); - commit_data.link_left = link_left; - commit_data.node = link_left ? hint : prev; - if(pdepth){ - *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1; - } - } - else{ - insert_equal_upper_bound_check(header, new_node, comp, commit_data, pdepth); - } - } - else{ - insert_equal_lower_bound_check(header, new_node, comp, commit_data, pdepth); - } - } - - template<class NodePtrCompare> - static void insert_equal_upper_bound_check - (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0) - { insert_equal_check_impl(true, h, new_node, comp, commit_data, pdepth); } - - template<class NodePtrCompare> - static void insert_equal_lower_bound_check - (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0) - { insert_equal_check_impl(false, h, new_node, comp, commit_data, pdepth); } - + //! <b>Requires</b>: "header" must be the header node of a tree. + //! NodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from + //! the "header"'s tree. + //! + //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to + //! where it will be inserted. If "hint" is the upper_bound + //! the insertion takes constant time (two comparisons in the worst case). + //! + //! <b>Complexity</b>: Logarithmic in general, but it is amortized + //! constant time if new_node is inserted immediately before "hint". + //! + //! <b>Throws</b>: If "comp" throws. template<class NodePtrCompare> static node_ptr insert_equal - (const node_ptr & h, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0) + (const node_ptr & h, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; insert_equal_check(h, hint, new_node, comp, commit_data, pdepth); @@ -1080,9 +1213,25 @@ class tree_algorithms return new_node; } + //! <b>Requires</b>: "h" must be the header node of a tree. + //! NodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. NodePtrCompare compares two node_ptrs. + //! + //! <b>Effects</b>: Inserts new_node into the tree before the upper bound + //! according to "comp". + //! + //! <b>Complexity</b>: Average complexity for insert element is at + //! most logarithmic. + //! + //! <b>Throws</b>: If "comp" throws. template<class NodePtrCompare> static node_ptr insert_equal_upper_bound - (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0) + (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; insert_equal_upper_bound_check(h, new_node, comp, commit_data, pdepth); @@ -1090,9 +1239,25 @@ class tree_algorithms return new_node; } + //! <b>Requires</b>: "h" must be the header node of a tree. + //! NodePtrCompare is a function object that induces a strict weak + //! ordering compatible with the strict weak ordering used to create the + //! the tree. NodePtrCompare compares two node_ptrs. + //! + //! <b>Effects</b>: Inserts new_node into the tree before the lower bound + //! according to "comp". + //! + //! <b>Complexity</b>: Average complexity for insert element is at + //! most logarithmic. + //! + //! <b>Throws</b>: If "comp" throws. template<class NodePtrCompare> static node_ptr insert_equal_lower_bound - (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, std::size_t *pdepth = 0) + (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; insert_equal_lower_bound_check(h, new_node, comp, commit_data, pdepth); @@ -1100,8 +1265,26 @@ class tree_algorithms return new_node; } + //! <b>Requires</b>: "header" must be the header node of a tree. + //! "pos" must be a valid iterator or header (end) node. + //! "pos" must be an iterator pointing to the successor to "new_node" + //! once inserted according to the order of already inserted nodes. This function does not + //! check "pos" and this precondition must be guaranteed by the caller. + //! + //! <b>Effects</b>: Inserts new_node into the tree before "pos". + //! + //! <b>Complexity</b>: Constant-time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node" + //! tree invariants might be broken. static node_ptr insert_before - (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node, std::size_t *pdepth = 0) + (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; insert_before_check(header, pos, commit_data, pdepth); @@ -1109,59 +1292,56 @@ class tree_algorithms return new_node; } - static void insert_before_check - (const node_ptr &header, const node_ptr & pos - , insert_commit_data &commit_data, std::size_t *pdepth = 0) - { - node_ptr prev(pos); - if(pos != NodeTraits::get_left(header)) - prev = prev_node(pos); - bool link_left = unique(header) || !NodeTraits::get_left(pos); - commit_data.link_left = link_left; - commit_data.node = link_left ? pos : prev; - if(pdepth){ - *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1; - } - } - + //! <b>Requires</b>: "header" must be the header node of a tree. + //! "new_node" must be, according to the used ordering no less than the + //! greatest inserted key. + //! + //! <b>Effects</b>: Inserts new_node into the tree before "pos". + //! + //! <b>Complexity</b>: Constant-time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: If "new_node" is less than the greatest inserted key + //! tree invariants are broken. This function is slightly faster than + //! using "insert_before". static void push_back - (const node_ptr & header, const node_ptr & new_node, std::size_t *pdepth = 0) + (const node_ptr & header, const node_ptr & new_node + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; push_back_check(header, commit_data, pdepth); insert_commit(header, new_node, commit_data); } - static void push_back_check - (const node_ptr & header, insert_commit_data &commit_data, std::size_t *pdepth = 0) - { - node_ptr prev(NodeTraits::get_right(header)); - if(pdepth){ - *pdepth = prev == header ? 0 : depth(prev) + 1; - } - commit_data.link_left = false; - commit_data.node = prev; - } - + //! <b>Requires</b>: "header" must be the header node of a tree. + //! "new_node" must be, according to the used ordering, no greater than the + //! lowest inserted key. + //! + //! <b>Effects</b>: Inserts new_node into the tree before "pos". + //! + //! <b>Complexity</b>: Constant-time. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Note</b>: If "new_node" is greater than the lowest inserted key + //! tree invariants are broken. This function is slightly faster than + //! using "insert_before". static void push_front - (const node_ptr & header, const node_ptr & new_node, std::size_t *pdepth = 0) + (const node_ptr & header, const node_ptr & new_node + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { insert_commit_data commit_data; push_front_check(header, commit_data, pdepth); insert_commit(header, new_node, commit_data); } - static void push_front_check - (const node_ptr & header, insert_commit_data &commit_data, std::size_t *pdepth = 0) - { - node_ptr pos(NodeTraits::get_left(header)); - if(pdepth){ - *pdepth = pos == header ? 0 : depth(pos) + 1; - } - commit_data.link_left = true; - commit_data.node = pos; - } - //! <b>Requires</b>: 'node' can't be a header node. //! //! <b>Effects</b>: Calculates the depth of a node: the depth of a @@ -1171,14 +1351,13 @@ class tree_algorithms //! <b>Complexity</b>: Logarithmic to the number of nodes in the tree. //! //! <b>Throws</b>: Nothing. - static std::size_t depth(const const_node_ptr & node) + static std::size_t depth(const_node_ptr node) { - const_node_ptr p(node); std::size_t depth = 0; node_ptr p_parent; - while(p != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(p))){ + while(node != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(node))){ ++depth; - p = p_parent; + node = p_parent; } return depth; } @@ -1218,101 +1397,259 @@ class tree_algorithms NodeTraits::set_right (target_header, rightmost); } - template <class Cloner, class Disposer> - static node_ptr clone_subtree - (const const_node_ptr &source_parent, const node_ptr &target_parent - , Cloner cloner, Disposer disposer - , node_ptr &leftmost_out, node_ptr &rightmost_out - ) + //! <b>Requires</b>: header must be the header of a tree, z a node + //! of that tree and z != header. + //! + //! <b>Effects</b>: Erases node "z" from the tree with header "header". + //! + //! <b>Complexity</b>: Amortized constant time. + //! + //! <b>Throws</b>: Nothing. + static void erase(const node_ptr & header, const node_ptr & z) { - node_ptr target_sub_root = target_parent; - node_ptr source_root = NodeTraits::get_parent(source_parent); - if(!source_root){ - leftmost_out = rightmost_out = source_root; + data_for_rebalance ignored; + erase(header, z, ignored); + } + + //! <b>Requires</b>: node is a tree node but not the header. + //! + //! <b>Effects</b>: Unlinks the node and rebalances the tree. + //! + //! <b>Complexity</b>: Average complexity is constant time. + //! + //! <b>Throws</b>: Nothing. + static void unlink(const node_ptr & node) + { + node_ptr x = NodeTraits::get_parent(node); + if(x){ + while(!is_header(x)) + x = NodeTraits::get_parent(x); + erase(x, node); + } + } + + //! <b>Requires</b>: header must be the header of a tree. + //! + //! <b>Effects</b>: Rebalances the tree. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Linear. + static void rebalance(const node_ptr & header) + { + node_ptr root = NodeTraits::get_parent(header); + if(root){ + rebalance_subtree(root); + } + } + + //! <b>Requires</b>: old_root is a node of a tree. It shall not be null. + //! + //! <b>Effects</b>: Rebalances the subtree rooted at old_root. + //! + //! <b>Returns</b>: The new root of the subtree. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Linear. + static node_ptr rebalance_subtree(const node_ptr & old_root) + { + //Taken from: + //"Tree rebalancing in optimal time and space" + //Quentin F. Stout and Bette L. Warren + + //To avoid irregularities in the algorithm (old_root can be a + //left or right child or even the root of the tree) just put the + //root as the right child of its parent. Before doing this backup + //information to restore the original relationship after + //the algorithm is applied. + node_ptr super_root = NodeTraits::get_parent(old_root); + BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root); + + //Get root info + node_ptr super_root_right_backup = NodeTraits::get_right(super_root); + bool super_root_is_header = NodeTraits::get_parent(super_root) == old_root; + bool old_root_is_right = is_right_child(old_root); + NodeTraits::set_right(super_root, old_root); + + std::size_t size; + subtree_to_vine(super_root, size); + vine_to_subtree(super_root, size); + node_ptr new_root = NodeTraits::get_right(super_root); + + //Recover root + if(super_root_is_header){ + NodeTraits::set_right(super_root, super_root_right_backup); + NodeTraits::set_parent(super_root, new_root); + } + else if(old_root_is_right){ + NodeTraits::set_right(super_root, new_root); } else{ - //We'll calculate leftmost and rightmost nodes while iterating - node_ptr current = source_root; - node_ptr insertion_point = target_sub_root = cloner(current); + NodeTraits::set_right(super_root, super_root_right_backup); + NodeTraits::set_left(super_root, new_root); + } + return new_root; + } - //We'll calculate leftmost and rightmost nodes while iterating - node_ptr leftmost = target_sub_root; - node_ptr rightmost = target_sub_root; + //! <b>Effects</b>: Asserts the integrity of the container with additional checks provided by the user. + //! + //! <b>Requires</b>: header must be the header of a tree. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Note</b>: The method might not have effect when asserts are turned off (e.g., with NDEBUG). + //! Experimental function, interface might change in future versions. + template<class Checker> + static void check(const const_node_ptr& header, Checker checker, typename Checker::return_type& checker_return) + { + const_node_ptr root_node_ptr = NodeTraits::get_parent(header); + if (!root_node_ptr) + { + // check left&right header pointers + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(header) == header); + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(header) == header); + } + else + { + // check parent pointer of root node + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_parent(root_node_ptr) == header); + // check subtree from root + check_subtree(root_node_ptr, checker, checker_return); + // check left&right header pointers + const_node_ptr p = root_node_ptr; + while (NodeTraits::get_left(p)) { p = NodeTraits::get_left(p); } + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(header) == p); + p = root_node_ptr; + while (NodeTraits::get_right(p)) { p = NodeTraits::get_right(p); } + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(header) == p); + } + } - //First set the subroot - NodeTraits::set_left(target_sub_root, node_ptr()); - NodeTraits::set_right(target_sub_root, node_ptr()); - NodeTraits::set_parent(target_sub_root, target_parent); + protected: + static void erase(const node_ptr & header, const node_ptr & z, data_for_rebalance &info) + { + node_ptr y(z); + node_ptr x; + const node_ptr z_left(NodeTraits::get_left(z)); + const node_ptr z_right(NodeTraits::get_right(z)); - dispose_subtree_disposer<Disposer> rollback(disposer, target_sub_root); - while(true) { - //First clone left nodes - if( NodeTraits::get_left(current) && - !NodeTraits::get_left(insertion_point)) { - current = NodeTraits::get_left(current); - node_ptr temp = insertion_point; - //Clone and mark as leaf - insertion_point = cloner(current); - NodeTraits::set_left (insertion_point, node_ptr()); - NodeTraits::set_right (insertion_point, node_ptr()); - //Insert left - NodeTraits::set_parent(insertion_point, temp); - NodeTraits::set_left (temp, insertion_point); - //Update leftmost - if(rightmost == target_sub_root) - leftmost = insertion_point; - } - //Then clone right nodes - else if( NodeTraits::get_right(current) && - !NodeTraits::get_right(insertion_point)){ - current = NodeTraits::get_right(current); - node_ptr temp = insertion_point; - //Clone and mark as leaf - insertion_point = cloner(current); - NodeTraits::set_left (insertion_point, node_ptr()); - NodeTraits::set_right (insertion_point, node_ptr()); - //Insert right - NodeTraits::set_parent(insertion_point, temp); - NodeTraits::set_right (temp, insertion_point); - //Update rightmost - rightmost = insertion_point; - } - //If not, go up - else if(current == source_root){ - break; - } - else{ - //Branch completed, go up searching more nodes to clone - current = NodeTraits::get_parent(current); - insertion_point = NodeTraits::get_parent(insertion_point); - } + if(!z_left){ + x = z_right; // x might be null. + } + else if(!z_right){ // z has exactly one non-null child. y == z. + x = z_left; // x is not null. + BOOST_ASSERT(x); + } + else{ //make y != z + // y = find z's successor + y = bstree_algorithms::minimum(z_right); + x = NodeTraits::get_right(y); // x might be null. + } + + node_ptr x_parent; + const node_ptr z_parent(NodeTraits::get_parent(z)); + const bool z_is_leftchild(NodeTraits::get_left(z_parent) == z); + + if(y != z){ //has two children and y is the minimum of z + //y is z's successor and it has a null left child. + //x is the right child of y (it can be null) + //Relink y in place of z and link x with y's old parent + NodeTraits::set_parent(z_left, y); + NodeTraits::set_left(y, z_left); + if(y != z_right){ + //Link y with the right tree of z + NodeTraits::set_right(y, z_right); + NodeTraits::set_parent(z_right, y); + //Link x with y's old parent (y must be a left child) + x_parent = NodeTraits::get_parent(y); + BOOST_ASSERT(NodeTraits::get_left(x_parent) == y); + if(x) + NodeTraits::set_parent(x, x_parent); + //Since y was the successor and not the right child of z, it must be a left child + NodeTraits::set_left(x_parent, x); } - rollback.release(); - leftmost_out = leftmost; - rightmost_out = rightmost; + else{ //y was the right child of y so no need to fix x's position + x_parent = y; + } + NodeTraits::set_parent(y, z_parent); + bstree_algorithms::set_child(header, y, z_parent, z_is_leftchild); } - return target_sub_root; + else { // z has zero or one child, x is one child (it can be null) + //Just link x to z's parent + x_parent = z_parent; + if(x) + NodeTraits::set_parent(x, z_parent); + bstree_algorithms::set_child(header, x, z_parent, z_is_leftchild); + + //Now update leftmost/rightmost in case z was one of them + if(NodeTraits::get_left(header) == z){ + //z_left must be null because z is the leftmost + BOOST_ASSERT(!z_left); + NodeTraits::set_left(header, !z_right ? + z_parent : // makes leftmost == header if z == root + bstree_algorithms::minimum(z_right)); + } + if(NodeTraits::get_right(header) == z){ + //z_right must be null because z is the rightmost + BOOST_ASSERT(!z_right); + NodeTraits::set_right(header, !z_left ? + z_parent : // makes rightmost == header if z == root + bstree_algorithms::maximum(z_left)); + } + } + + //If z had 0/1 child, y == z and one of its children (and maybe null) + //If z had 2 children, y is the successor of z and x is the right child of y + info.x = x; + info.y = y; + //If z had 0/1 child, x_parent is the new parent of the old right child of y (z's successor) + //If z had 2 children, x_parent is the new parent of y (z_parent) + BOOST_ASSERT(!x || NodeTraits::get_parent(x) == x_parent); + info.x_parent = x_parent; } - template<class Disposer> - static void dispose_subtree(const node_ptr & node, Disposer disposer) + //! <b>Requires</b>: node is a node of the tree but it's not the header. + //! + //! <b>Effects</b>: Returns the number of nodes of the subtree. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Throws</b>: Nothing. + static std::size_t subtree_size(const const_node_ptr & subtree) { - node_ptr save; - node_ptr x(node); - while (x){ - save = NodeTraits::get_left(x); - if (save) { - // Right rotation - NodeTraits::set_left(x, NodeTraits::get_right(save)); - NodeTraits::set_right(save, x); + std::size_t count = 0; + if (subtree){ + node_ptr n = detail::uncast(subtree); + node_ptr m = NodeTraits::get_left(n); + while(m){ + n = m; + m = NodeTraits::get_left(n); } - else { - save = NodeTraits::get_right(x); - init(x); - disposer(x); + + while(1){ + ++count; + node_ptr n_right(NodeTraits::get_right(n)); + if(n_right){ + n = n_right; + m = NodeTraits::get_left(n); + while(m){ + n = m; + m = NodeTraits::get_left(n); + } + } + else { + do{ + if (n == subtree){ + return count; + } + m = n; + n = NodeTraits::get_parent(n); + }while(NodeTraits::get_left(n) != m); + } } - x = save; } + return count; } //! <b>Requires</b>: p is a node of a tree. @@ -1335,258 +1672,265 @@ class tree_algorithms static bool is_right_child(const node_ptr & p) { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; } - //Fix header and own's parent data when replacing x with own, providing own's old data with parent - static void replace_own_impl(const node_ptr & own, const node_ptr & x, const node_ptr & header, const node_ptr & own_parent, bool own_was_left) + static void insert_before_check + (const node_ptr &header, const node_ptr & pos + , insert_commit_data &commit_data + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { - if(NodeTraits::get_parent(header) == own) - NodeTraits::set_parent(header, x); - else if(own_was_left) - NodeTraits::set_left(own_parent, x); - else - NodeTraits::set_right(own_parent, x); + node_ptr prev(pos); + if(pos != NodeTraits::get_left(header)) + prev = prev_node(pos); + bool link_left = unique(header) || !NodeTraits::get_left(pos); + commit_data.link_left = link_left; + commit_data.node = link_left ? pos : prev; + if(pdepth){ + *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1; + } } - //Fix header and own's parent data when replacing x with own, supposing own - //links with its parent are still ok - static void replace_own(const node_ptr & own, const node_ptr & x, const node_ptr & header) + static void push_back_check + (const node_ptr & header, insert_commit_data &commit_data + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { - node_ptr own_parent(NodeTraits::get_parent(own)); - bool own_is_left(NodeTraits::get_left(own_parent) == own); - replace_own_impl(own, x, header, own_parent, own_is_left); + node_ptr prev(NodeTraits::get_right(header)); + if(pdepth){ + *pdepth = prev == header ? 0 : depth(prev) + 1; + } + commit_data.link_left = false; + commit_data.node = prev; } - // rotate parent p to left (no header and p's parent fixup) - static node_ptr rotate_left(const node_ptr & p) + static void push_front_check + (const node_ptr & header, insert_commit_data &commit_data + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + , std::size_t *pdepth = 0 + #endif + ) { - node_ptr x(NodeTraits::get_right(p)); - node_ptr x_left(NodeTraits::get_left(x)); - NodeTraits::set_right(p, x_left); - if(x_left){ - NodeTraits::set_parent(x_left, p); + node_ptr pos(NodeTraits::get_left(header)); + if(pdepth){ + *pdepth = pos == header ? 0 : depth(pos) + 1; } - NodeTraits::set_left(x, p); - NodeTraits::set_parent(p, x); - return x; + commit_data.link_left = true; + commit_data.node = pos; } - // rotate parent p to left (with header and p's parent fixup) - static void rotate_left(const node_ptr & p, const node_ptr & header) + template<class NodePtrCompare> + static void insert_equal_check + (const node_ptr &header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp + , insert_commit_data &commit_data + /// @cond + , std::size_t *pdepth = 0 + /// @endcond + ) { - bool p_was_left(is_left_child(p)); - node_ptr p_old_parent(NodeTraits::get_parent(p)); - node_ptr x(rotate_left(p)); - NodeTraits::set_parent(x, p_old_parent); - replace_own_impl(p, x, header, p_old_parent, p_was_left); + if(hint == header || !comp(hint, new_node)){ + node_ptr prev(hint); + if(hint == NodeTraits::get_left(header) || + !comp(new_node, (prev = prev_node(hint)))){ + bool link_left = unique(header) || !NodeTraits::get_left(hint); + commit_data.link_left = link_left; + commit_data.node = link_left ? hint : prev; + if(pdepth){ + *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1; + } + } + else{ + insert_equal_upper_bound_check(header, new_node, comp, commit_data, pdepth); + } + } + else{ + insert_equal_lower_bound_check(header, new_node, comp, commit_data, pdepth); + } } - // rotate parent p to right (no header and p's parent fixup) - static node_ptr rotate_right(const node_ptr & p) + template<class NodePtrCompare> + static void insert_equal_upper_bound_check + (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0) { - node_ptr x(NodeTraits::get_left(p)); - node_ptr x_right(NodeTraits::get_right(x)); - NodeTraits::set_left(p, x_right); - if(x_right){ - NodeTraits::set_parent(x_right, p); + std::size_t depth = 0; + node_ptr y(h); + node_ptr x(NodeTraits::get_parent(y)); + + while(x){ + ++depth; + y = x; + x = comp(new_node, x) ? + NodeTraits::get_left(x) : NodeTraits::get_right(x); } - NodeTraits::set_right(x, p); - NodeTraits::set_parent(p, x); - return x; + if(pdepth) *pdepth = depth; + commit_data.link_left = (y == h) || comp(new_node, y); + commit_data.node = y; } - // rotate parent p to right (with header and p's parent fixup) - static void rotate_right(const node_ptr & p, const node_ptr & header) + template<class NodePtrCompare> + static void insert_equal_lower_bound_check + (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0) { - bool p_was_left(is_left_child(p)); - node_ptr p_old_parent(NodeTraits::get_parent(p)); - node_ptr x(rotate_right(p)); - NodeTraits::set_parent(x, p_old_parent); - replace_own_impl(p, x, header, p_old_parent, p_was_left); - } + std::size_t depth = 0; + node_ptr y(h); + node_ptr x(NodeTraits::get_parent(y)); - static void erase(const node_ptr & header, const node_ptr & z) - { - data_for_rebalance ignored; - erase_impl(header, z, ignored); + while(x){ + ++depth; + y = x; + x = !comp(x, new_node) ? + NodeTraits::get_left(x) : NodeTraits::get_right(x); + } + if(pdepth) *pdepth = depth; + commit_data.link_left = (y == h) || !comp(y, new_node); + commit_data.node = y; } - struct data_for_rebalance + static void insert_commit + (const node_ptr & header, const node_ptr & new_node, const insert_commit_data &commit_data) { - node_ptr x; - node_ptr x_parent; - node_ptr y; - }; + //Check if commit_data has not been initialized by a insert_unique_check call. + BOOST_INTRUSIVE_INVARIANT_ASSERT(commit_data.node != node_ptr()); + node_ptr parent_node(commit_data.node); + if(parent_node == header){ + NodeTraits::set_parent(header, new_node); + NodeTraits::set_right(header, new_node); + NodeTraits::set_left(header, new_node); + } + else if(commit_data.link_left){ + NodeTraits::set_left(parent_node, new_node); + if(parent_node == NodeTraits::get_left(header)) + NodeTraits::set_left(header, new_node); + } + else{ + NodeTraits::set_right(parent_node, new_node); + if(parent_node == NodeTraits::get_right(header)) + NodeTraits::set_right(header, new_node); + } + NodeTraits::set_parent(new_node, parent_node); + NodeTraits::set_right(new_node, node_ptr()); + NodeTraits::set_left(new_node, node_ptr()); + } - template<class F> - static void erase(const node_ptr & header, const node_ptr & z, F z_and_successor_fixup, data_for_rebalance &info) + //Fix header and own's parent data when replacing x with own, providing own's old data with parent + static void set_child(const node_ptr & header, const node_ptr & new_child, const node_ptr & new_parent, const bool link_left) { - erase_impl(header, z, info); - if(info.y != z){ - z_and_successor_fixup(z, info.y); - } + if(new_parent == header) + NodeTraits::set_parent(header, new_child); + else if(link_left) + NodeTraits::set_left(new_parent, new_child); + else + NodeTraits::set_right(new_parent, new_child); } - static void unlink(const node_ptr & node) + // rotate p to left (no header and p's parent fixup) + static void rotate_left_no_parent_fix(const node_ptr & p, const node_ptr &p_right) { - node_ptr x = NodeTraits::get_parent(node); - if(x){ - while(!is_header(x)) - x = NodeTraits::get_parent(x); - erase(x, node); + node_ptr p_right_left(NodeTraits::get_left(p_right)); + NodeTraits::set_right(p, p_right_left); + if(p_right_left){ + NodeTraits::set_parent(p_right_left, p); } + NodeTraits::set_left(p_right, p); + NodeTraits::set_parent(p, p_right); } - static void tree_to_vine(const node_ptr & header) - { subtree_to_vine(NodeTraits::get_parent(header)); } - - static void vine_to_tree(const node_ptr & header, std::size_t count) - { vine_to_subtree(NodeTraits::get_parent(header), count); } - - static void rebalance(const node_ptr & header) + // rotate p to left (with header and p's parent fixup) + static void rotate_left(const node_ptr & p, const node_ptr & p_right, const node_ptr & p_parent, const node_ptr & header) { - //Taken from: - //"Tree rebalancing in optimal time and space" - //Quentin F. Stout and Bette L. Warren - std::size_t len = 0; - subtree_to_vine(NodeTraits::get_parent(header), &len); - vine_to_subtree(NodeTraits::get_parent(header), len); + const bool p_was_left(NodeTraits::get_left(p_parent) == p); + rotate_left_no_parent_fix(p, p_right); + NodeTraits::set_parent(p_right, p_parent); + set_child(header, p_right, p_parent, p_was_left); } - static node_ptr rebalance_subtree(const node_ptr & old_root) + // rotate p to right (no header and p's parent fixup) + static void rotate_right_no_parent_fix(const node_ptr & p, const node_ptr &p_left) { - std::size_t len = 0; - node_ptr new_root = subtree_to_vine(old_root, &len); - return vine_to_subtree(new_root, len); + node_ptr p_left_right(NodeTraits::get_right(p_left)); + NodeTraits::set_left(p, p_left_right); + if(p_left_right){ + NodeTraits::set_parent(p_left_right, p); + } + NodeTraits::set_right(p_left, p); + NodeTraits::set_parent(p, p_left); } - static node_ptr subtree_to_vine(const node_ptr & old_root, std::size_t *plen = 0) + // rotate p to right (with header and p's parent fixup) + static void rotate_right(const node_ptr & p, const node_ptr & p_left, const node_ptr & p_parent, const node_ptr & header) { - std::size_t len; - len = 0; - if(!old_root) return node_ptr(); - - //To avoid irregularities in the algorithm (old_root can be a - //left or right child or even the root of the tree) just put the - //root as the right child of its parent. Before doing this backup - //information to restore the original relationship after - //the algorithm is applied. - node_ptr super_root = NodeTraits::get_parent(old_root); - BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root); + const bool p_was_left(NodeTraits::get_left(p_parent) == p); + rotate_right_no_parent_fix(p, p_left); + NodeTraits::set_parent(p_left, p_parent); + set_child(header, p_left, p_parent, p_was_left); + } - //Get info - node_ptr super_root_right_backup = NodeTraits::get_right(super_root); - bool super_root_is_header = is_header(super_root); - bool old_root_is_right = is_right_child(old_root); + private: - node_ptr x(old_root); - node_ptr new_root(x); - node_ptr save; - bool moved_to_right = false; - for( ; x; x = save){ - save = NodeTraits::get_left(x); - if(save){ - // Right rotation - node_ptr save_right = NodeTraits::get_right(save); - node_ptr x_parent = NodeTraits::get_parent(x); - NodeTraits::set_parent(save, x_parent); - NodeTraits::set_right (x_parent, save); - NodeTraits::set_parent(x, save); - NodeTraits::set_right (save, x); - NodeTraits::set_left(x, save_right); - if(save_right) - NodeTraits::set_parent(save_right, x); - if(!moved_to_right) - new_root = save; - } - else{ - moved_to_right = true; - save = NodeTraits::get_right(x); + static void subtree_to_vine(node_ptr vine_tail, std::size_t &size) + { + //Inspired by LibAVL: + //It uses a clever optimization for trees with parent pointers. + //No parent pointer is updated when transforming a tree to a vine as + //most of them will be overriten during compression rotations. + //A final pass must be made after the rebalancing to updated those + //pointers not updated by tree_to_vine + compression calls + std::size_t len = 0; + node_ptr remainder = NodeTraits::get_right(vine_tail); + while(remainder){ + node_ptr tempptr = NodeTraits::get_left(remainder); + if(!tempptr){ //move vine-tail down one + vine_tail = remainder; + remainder = NodeTraits::get_right(remainder); ++len; } + else{ //rotate + NodeTraits::set_left(remainder, NodeTraits::get_right(tempptr)); + NodeTraits::set_right(tempptr, remainder); + remainder = tempptr; + NodeTraits::set_right(vine_tail, tempptr); + } } + size = len; + } - if(super_root_is_header){ - NodeTraits::set_right(super_root, super_root_right_backup); - NodeTraits::set_parent(super_root, new_root); - } - else if(old_root_is_right){ - NodeTraits::set_right(super_root, new_root); - } - else{ - NodeTraits::set_right(super_root, super_root_right_backup); - NodeTraits::set_left(super_root, new_root); + static void compress_subtree(node_ptr scanner, std::size_t count) + { + while(count--){ //compress "count" spine nodes in the tree with pseudo-root scanner + node_ptr child = NodeTraits::get_right(scanner); + node_ptr child_right = NodeTraits::get_right(child); + NodeTraits::set_right(scanner, child_right); + //Avoid setting the parent of child_right + scanner = child_right; + node_ptr scanner_left = NodeTraits::get_left(scanner); + NodeTraits::set_right(child, scanner_left); + if(scanner_left) + NodeTraits::set_parent(scanner_left, child); + NodeTraits::set_left(scanner, child); + NodeTraits::set_parent(child, scanner); } - if(plen) *plen = len; - return new_root; } - static node_ptr vine_to_subtree(const node_ptr & old_root, std::size_t count) + static void vine_to_subtree(const node_ptr & super_root, std::size_t count) { - std::size_t leaf_nodes = count + 1 - ((std::size_t) 1 << floor_log2 (count + 1)); + const std::size_t one_szt = 1u; + std::size_t leaf_nodes = count + one_szt - std::size_t(one_szt << detail::floor_log2(count + one_szt)); + compress_subtree(super_root, leaf_nodes); //create deepest leaves std::size_t vine_nodes = count - leaf_nodes; - - node_ptr new_root = compress_subtree(old_root, leaf_nodes); while(vine_nodes > 1){ vine_nodes /= 2; - new_root = compress_subtree(new_root, vine_nodes); + compress_subtree(super_root, vine_nodes); } - return new_root; - } - - static node_ptr compress_subtree(const node_ptr & old_root, std::size_t count) - { - if(!old_root) return old_root; - - //To avoid irregularities in the algorithm (old_root can be - //left or right child or even the root of the tree) just put the - //root as the right child of its parent. First obtain - //information to restore the original relationship after - //the algorithm is applied. - node_ptr super_root = NodeTraits::get_parent(old_root); - BOOST_INTRUSIVE_INVARIANT_ASSERT(super_root); - //Get info - node_ptr super_root_right_backup = NodeTraits::get_right(super_root); - bool super_root_is_header = is_header(super_root); - bool old_root_is_right = is_right_child(old_root); - - //Put old_root as right child - NodeTraits::set_right(super_root, old_root); - - //Start the compression algorithm - node_ptr even_parent = super_root; - node_ptr new_root = old_root; - - while(count--){ - node_ptr even = NodeTraits::get_right(even_parent); - node_ptr odd = NodeTraits::get_right(even); - - if(new_root == old_root) - new_root = odd; - - node_ptr even_right = NodeTraits::get_left(odd); - NodeTraits::set_right(even, even_right); - if (even_right) - NodeTraits::set_parent(even_right, even); - - NodeTraits::set_right(even_parent, odd); - NodeTraits::set_parent(odd, even_parent); - NodeTraits::set_left(odd, even); - NodeTraits::set_parent(even, odd); - even_parent = odd; + //Update parents of nodes still in the in the original vine line + //as those have not been updated by subtree_to_vine or compress_subtree + for ( node_ptr q = super_root, p = NodeTraits::get_right(super_root) + ; p + ; q = p, p = NodeTraits::get_right(p)){ + NodeTraits::set_parent(p, q); } - - if(super_root_is_header){ - NodeTraits::set_parent(super_root, new_root); - NodeTraits::set_right(super_root, super_root_right_backup); - } - else if(old_root_is_right){ - NodeTraits::set_right(super_root, new_root); - } - else{ - NodeTraits::set_left(super_root, new_root); - NodeTraits::set_right(super_root, super_root_right_backup); - } - return new_root; } //! <b>Requires</b>: "n" must be a node inserted in a tree. @@ -1611,7 +1955,100 @@ class tree_algorithms } } - private: + template <class Cloner, class Disposer> + static node_ptr clone_subtree + (const const_node_ptr &source_parent, const node_ptr &target_parent + , Cloner cloner, Disposer disposer + , node_ptr &leftmost_out, node_ptr &rightmost_out + ) + { + node_ptr target_sub_root = target_parent; + node_ptr source_root = NodeTraits::get_parent(source_parent); + if(!source_root){ + leftmost_out = rightmost_out = source_root; + } + else{ + //We'll calculate leftmost and rightmost nodes while iterating + node_ptr current = source_root; + node_ptr insertion_point = target_sub_root = cloner(current); + + //We'll calculate leftmost and rightmost nodes while iterating + node_ptr leftmost = target_sub_root; + node_ptr rightmost = target_sub_root; + + //First set the subroot + NodeTraits::set_left(target_sub_root, node_ptr()); + NodeTraits::set_right(target_sub_root, node_ptr()); + NodeTraits::set_parent(target_sub_root, target_parent); + + dispose_subtree_disposer<Disposer> rollback(disposer, target_sub_root); + while(true) { + //First clone left nodes + if( NodeTraits::get_left(current) && + !NodeTraits::get_left(insertion_point)) { + current = NodeTraits::get_left(current); + node_ptr temp = insertion_point; + //Clone and mark as leaf + insertion_point = cloner(current); + NodeTraits::set_left (insertion_point, node_ptr()); + NodeTraits::set_right (insertion_point, node_ptr()); + //Insert left + NodeTraits::set_parent(insertion_point, temp); + NodeTraits::set_left (temp, insertion_point); + //Update leftmost + if(rightmost == target_sub_root) + leftmost = insertion_point; + } + //Then clone right nodes + else if( NodeTraits::get_right(current) && + !NodeTraits::get_right(insertion_point)){ + current = NodeTraits::get_right(current); + node_ptr temp = insertion_point; + //Clone and mark as leaf + insertion_point = cloner(current); + NodeTraits::set_left (insertion_point, node_ptr()); + NodeTraits::set_right (insertion_point, node_ptr()); + //Insert right + NodeTraits::set_parent(insertion_point, temp); + NodeTraits::set_right (temp, insertion_point); + //Update rightmost + rightmost = insertion_point; + } + //If not, go up + else if(current == source_root){ + break; + } + else{ + //Branch completed, go up searching more nodes to clone + current = NodeTraits::get_parent(current); + insertion_point = NodeTraits::get_parent(insertion_point); + } + } + rollback.release(); + leftmost_out = leftmost; + rightmost_out = rightmost; + } + return target_sub_root; + } + + template<class Disposer> + static void dispose_subtree(node_ptr x, Disposer disposer) + { + while (x){ + node_ptr save(NodeTraits::get_left(x)); + if (save) { + // Right rotation + NodeTraits::set_left(x, NodeTraits::get_right(save)); + NodeTraits::set_right(save, x); + } + else { + save = NodeTraits::get_right(x); + init(x); + disposer(x); + } + x = save; + } + } template<class KeyType, class KeyNodePtrCompare> static node_ptr lower_bound_loop @@ -1645,103 +2082,46 @@ class tree_algorithms return y; } - - template<class NodePtrCompare> - static void insert_equal_check_impl - (bool upper, const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0) + template<class Checker> + static void check_subtree(const const_node_ptr& node, Checker checker, typename Checker::return_type& check_return) { - std::size_t depth = 0; - node_ptr y(h); - node_ptr x(NodeTraits::get_parent(y)); - bool link_left; - - if(upper){ - while(x){ - ++depth; - y = x; - x = comp(new_node, x) ? - NodeTraits::get_left(x) : NodeTraits::get_right(x); - } - link_left = (y == h) || comp(new_node, y); + const_node_ptr left = NodeTraits::get_left(node); + const_node_ptr right = NodeTraits::get_right(node); + typename Checker::return_type check_return_left; + typename Checker::return_type check_return_right; + if (left) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_parent(left) == node); + check_subtree(left, checker, check_return_left); } - else{ - while(x){ - ++depth; - y = x; - x = !comp(x, new_node) ? - NodeTraits::get_left(x) : NodeTraits::get_right(x); - } - link_left = (y == h) || !comp(y, new_node); + if (right) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_parent(right) == node); + check_subtree(right, checker, check_return_right); } - - commit_data.link_left = link_left; - commit_data.node = y; - if(pdepth) *pdepth = depth; + checker(node, check_return_left, check_return_right, check_return); } +}; - static void erase_impl(const node_ptr & header, const node_ptr & z, data_for_rebalance &info) - { - node_ptr y(z); - node_ptr x; - node_ptr x_parent = node_ptr(); - node_ptr z_left(NodeTraits::get_left(z)); - node_ptr z_right(NodeTraits::get_right(z)); - if(!z_left){ - x = z_right; // x might be null. - } - else if(!z_right){ // z has exactly one non-null child. y == z. - x = z_left; // x is not null. - } - else{ - // find z's successor - y = tree_algorithms::minimum (z_right); - x = NodeTraits::get_right(y); // x might be null. - } +/// @cond - if(y != z){ - // relink y in place of z. y is z's successor - NodeTraits::set_parent(NodeTraits::get_left(z), y); - NodeTraits::set_left(y, NodeTraits::get_left(z)); - if(y != NodeTraits::get_right(z)){ - x_parent = NodeTraits::get_parent(y); - if(x) - NodeTraits::set_parent(x, x_parent); - NodeTraits::set_left(x_parent, x); // y must be a child of left_ - NodeTraits::set_right(y, NodeTraits::get_right(z)); - NodeTraits::set_parent(NodeTraits::get_right(z), y); - } - else - x_parent = y; - tree_algorithms::replace_own (z, y, header); - NodeTraits::set_parent(y, NodeTraits::get_parent(z)); - } - else { // y == z --> z has only one child, or none - x_parent = NodeTraits::get_parent(z); - if(x) - NodeTraits::set_parent(x, x_parent); - tree_algorithms::replace_own (z, x, header); - if(NodeTraits::get_left(header) == z){ - NodeTraits::set_left(header, !NodeTraits::get_right(z) ? // z->get_left() must be null also - NodeTraits::get_parent(z) : // makes leftmost == header if z == root - tree_algorithms::minimum (x)); - } - if(NodeTraits::get_right(header) == z){ - NodeTraits::set_right(header, !NodeTraits::get_left(z) ? // z->get_right() must be null also - NodeTraits::get_parent(z) : // makes rightmost == header if z == root - tree_algorithms::maximum(x)); - } - } +template<class NodeTraits> +struct get_algo<BsTreeAlgorithms, NodeTraits> +{ + typedef bstree_algorithms<NodeTraits> type; +}; - info.x = x; - info.x_parent = x_parent; - info.y = y; - } +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<BsTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; }; -} //namespace detail { +/// @endcond + } //namespace intrusive } //namespace boost #include <boost/intrusive/detail/config_end.hpp> -#endif //BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP +#endif //BOOST_INTRUSIVE_BSTREE_ALGORITHMS_HPP diff --git a/boost/intrusive/circular_list_algorithms.hpp b/boost/intrusive/circular_list_algorithms.hpp index 282f4741a1..1e888a1cae 100644 --- a/boost/intrusive/circular_list_algorithms.hpp +++ b/boost/intrusive/circular_list_algorithms.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,8 +14,14 @@ #ifndef BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP #define BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/core/no_exceptions_support.hpp> #include <cstddef> namespace boost { @@ -63,8 +69,9 @@ class circular_list_algorithms //! <b>Throws</b>: Nothing. static void init(const node_ptr &this_node) { - NodeTraits::set_next(this_node, node_ptr()); - NodeTraits::set_previous(this_node, node_ptr()); + const node_ptr null_node((node_ptr())); + NodeTraits::set_next(this_node, null_node); + NodeTraits::set_previous(this_node, null_node); } //! <b>Effects</b>: Returns true is "this_node" is in a non-used state @@ -134,15 +141,10 @@ class circular_list_algorithms static node_ptr unlink(const node_ptr &this_node) { node_ptr next(NodeTraits::get_next(this_node)); - if(next){ - node_ptr prev(NodeTraits::get_previous(this_node)); - NodeTraits::set_next(prev, next); - NodeTraits::set_previous(next, prev); - return next; - } - else{ - return this_node; - } + node_ptr prev(NodeTraits::get_previous(this_node)); + NodeTraits::set_next(prev, next); + NodeTraits::set_previous(next, prev); + return next; } //! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range. @@ -174,7 +176,7 @@ class circular_list_algorithms NodeTraits::set_previous(this_node, prev); NodeTraits::set_next(this_node, nxt_node); //nxt_node might be an alias for prev->next_ - //so use it before update it before NodeTraits::set_next(prev, ...) + //so use it before NodeTraits::set_next(prev, ...) //is called and the reference changes it's value NodeTraits::set_previous(nxt_node, this_node); NodeTraits::set_next(prev, this_node); @@ -403,8 +405,100 @@ class circular_list_algorithms } link_after(last, p); } + + //! <b>Requires</b>: f and l must be in a circular list. + //! + //! <b>Effects</b>: Returns the number of nodes in the range [f, l). + //! + //! <b>Complexity</b>: Linear + //! + //! <b>Throws</b>: Nothing. + static std::size_t distance(const const_node_ptr &f, const const_node_ptr &l) + { + const_node_ptr i(f); + std::size_t result = 0; + while(i != l){ + i = NodeTraits::get_next(i); + ++result; + } + return result; + } + + struct stable_partition_info + { + std::size_t num_1st_partition; + std::size_t num_2nd_partition; + node_ptr beg_2st_partition; + }; + + template<class Pred> + static void stable_partition(node_ptr beg, const node_ptr &end, Pred pred, stable_partition_info &info) + { + node_ptr bcur = node_traits::get_previous(beg); + node_ptr cur = beg; + node_ptr new_f = end; + + std::size_t num1 = 0, num2 = 0; + while(cur != end){ + if(pred(cur)){ + ++num1; + bcur = cur; + cur = node_traits::get_next(cur); + } + else{ + ++num2; + node_ptr last_to_remove = bcur; + new_f = cur; + bcur = cur; + cur = node_traits::get_next(cur); + BOOST_TRY{ + //Main loop + while(cur != end){ + if(pred(cur)){ //Might throw + ++num1; + //Process current node + node_traits::set_next (last_to_remove, cur); + node_traits::set_previous(cur, last_to_remove); + last_to_remove = cur; + node_ptr nxt = node_traits::get_next(cur); + node_traits::set_next (bcur, nxt); + node_traits::set_previous(nxt, bcur); + cur = nxt; + } + else{ + ++num2; + bcur = cur; + cur = node_traits::get_next(cur); + } + } + } + BOOST_CATCH(...){ + node_traits::set_next (last_to_remove, new_f); + node_traits::set_previous(new_f, last_to_remove); + throw; + } + BOOST_CATCH_END + node_traits::set_next(last_to_remove, new_f); + node_traits::set_previous(new_f, last_to_remove); + break; + } + } + info.num_1st_partition = num1; + info.num_2nd_partition = num2; + info.beg_2st_partition = new_f; + } }; +/// @cond + +template<class NodeTraits> +struct get_algo<CircularListAlgorithms, NodeTraits> +{ + typedef circular_list_algorithms<NodeTraits> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/circular_slist_algorithms.hpp b/boost/intrusive/circular_slist_algorithms.hpp index c39b3d0c5a..3dd561df50 100644 --- a/boost/intrusive/circular_slist_algorithms.hpp +++ b/boost/intrusive/circular_slist_algorithms.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,11 +14,16 @@ #ifndef BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP #define BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <cstddef> #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/common_slist_algorithms.hpp> -#include <boost/intrusive/detail/assert.hpp> -#include <cstddef> +#include <boost/intrusive/detail/algo_type.hpp> + namespace boost { namespace intrusive { @@ -172,18 +177,17 @@ class circular_slist_algorithms static node_ptr get_previous_previous_node(const node_ptr & this_node) { return get_previous_previous_node(this_node, this_node); } - //! <b>Requires</b>: this_node and prev_prev_init_node must be in the same circular list. + //! <b>Requires</b>: this_node and p must be in the same circular list. //! //! <b>Effects</b>: Returns the previous node of the previous node of this_node in the - //! circular list starting. the search from prev_init_node. The first node checked - //! for equality is NodeTraits::get_next((NodeTraits::get_next(prev_prev_init_node)). + //! circular list starting. the search from p. The first node checked + //! for equality is NodeTraits::get_next((NodeTraits::get_next(p)). //! //! <b>Complexity</b>: Linear to the number of elements in the circular list. //! //! <b>Throws</b>: Nothing. - static node_ptr get_previous_previous_node(const node_ptr & prev_prev_init_node, const node_ptr & this_node) + static node_ptr get_previous_previous_node(node_ptr p, const node_ptr & this_node) { - node_ptr p = prev_prev_init_node; node_ptr p_next = NodeTraits::get_next(p); node_ptr p_next_next = NodeTraits::get_next(p_next); while (this_node != p_next_next){ @@ -250,33 +254,21 @@ class circular_slist_algorithms { if (other_node == this_node) return; - bool this_inited = base_t::inited(this_node); - bool other_inited = base_t::inited(other_node); - if(this_inited){ - base_t::init_header(this_node); + const node_ptr this_next = NodeTraits::get_next(this_node); + const node_ptr other_next = NodeTraits::get_next(other_node); + const bool this_null = !this_next; + const bool other_null = !other_next; + const bool this_empty = this_next == this_node; + const bool other_empty = other_next == other_node; + + if(!(other_null || other_empty)){ + NodeTraits::set_next(this_next == other_node ? other_node : get_previous_node(other_node), this_node ); } - if(other_inited){ - base_t::init_header(other_node); - } - - bool empty1 = base_t::unique(this_node); - bool empty2 = base_t::unique(other_node); - node_ptr prev_this (get_previous_node(this_node)); - node_ptr prev_other(get_previous_node(other_node)); - - node_ptr this_next (NodeTraits::get_next(this_node)); - node_ptr other_next(NodeTraits::get_next(other_node)); - NodeTraits::set_next(this_node, other_next); - NodeTraits::set_next(other_node, this_next); - NodeTraits::set_next(empty1 ? other_node : prev_this, other_node); - NodeTraits::set_next(empty2 ? this_node : prev_other, this_node); - - if(this_inited){ - base_t::init(other_node); - } - if(other_inited){ - base_t::init(this_node); + if(!(this_null | this_empty)){ + NodeTraits::set_next(other_next == this_node ? this_node : get_previous_node(this_node), other_node ); } + NodeTraits::set_next(this_node, other_empty ? this_node : (other_next == this_node ? other_node : other_next) ); + NodeTraits::set_next(other_node, this_empty ? other_node : (this_next == other_node ? this_node : this_next ) ); } //! <b>Effects</b>: Reverses the order of elements in the list. @@ -397,6 +389,16 @@ class circular_slist_algorithms } }; +/// @cond + +template<class NodeTraits> +struct get_algo<CircularSListAlgorithms, NodeTraits> +{ + typedef circular_slist_algorithms<NodeTraits> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/derivation_value_traits.hpp b/boost/intrusive/derivation_value_traits.hpp index 0aae01b619..87bc489cf5 100644 --- a/boost/intrusive/derivation_value_traits.hpp +++ b/boost/intrusive/derivation_value_traits.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,10 +13,14 @@ #ifndef BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP #define BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/pointer_cast.hpp> -#include <boost/pointer_to_other.hpp> -#include <iterator> +#include <boost/intrusive/pointer_traits.hpp> namespace boost { namespace intrusive { @@ -24,7 +28,12 @@ namespace intrusive { //!This value traits template is used to create value traits //!from user defined node traits where value_traits::value_type will //!derive from node_traits::node -template<class T, class NodeTraits, link_mode_type LinkMode = safe_link> + +template<class T, class NodeTraits, link_mode_type LinkMode + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + = safe_link + #endif +> struct derivation_value_traits { public: @@ -33,8 +42,10 @@ struct derivation_value_traits typedef typename node_traits::node node; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; - typedef typename boost::pointer_to_other<node_ptr, T>::type pointer; - typedef typename boost::pointer_to_other<node_ptr, const T>::type const_pointer; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<value_type>::type pointer; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<const value_type>::type const_pointer; typedef typename boost::intrusive:: pointer_traits<pointer>::reference reference; typedef typename boost::intrusive:: @@ -49,22 +60,18 @@ struct derivation_value_traits static pointer to_value_ptr(const node_ptr &n) { -// This still fails in gcc < 4.4 so forget about it -// using ::boost::static_pointer_cast; -// return static_pointer_cast<value_type>(n)); - return pointer(&static_cast<value_type&>(*n)); + return pointer_traits<pointer>::pointer_to(static_cast<reference>(*n)); } static const_pointer to_value_ptr(const const_node_ptr &n) { -// This still fails in gcc < 4.4 so forget about it -// using ::boost::static_pointer_cast; -// return static_pointer_cast<const value_type>(n)); - return const_pointer(&static_cast<const value_type&>(*n)); + return pointer_traits<pointer>::pointer_to(static_cast<const_reference>(*n)); } }; } //namespace intrusive } //namespace boost +#include <boost/intrusive/detail/config_end.hpp> + #endif //BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP diff --git a/boost/intrusive/detail/algo_type.hpp b/boost/intrusive/detail/algo_type.hpp new file mode 100644 index 0000000000..e40cb43b4e --- /dev/null +++ b/boost/intrusive/detail/algo_type.hpp @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP +#define BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { + +enum algo_types +{ + CircularListAlgorithms, + CircularSListAlgorithms, + LinearSListAlgorithms, + CommonSListAlgorithms, + BsTreeAlgorithms, + RbTreeAlgorithms, + AvlTreeAlgorithms, + SgTreeAlgorithms, + SplayTreeAlgorithms, + TreapAlgorithms +}; + +template<algo_types AlgoType, class NodeTraits> +struct get_algo; + +template<algo_types AlgoType, class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker; + +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_DETAIL_ALGO_TYPE_HPP diff --git a/boost/intrusive/detail/any_node_and_algorithms.hpp b/boost/intrusive/detail/any_node_and_algorithms.hpp index b274135a90..5a0e8c27fe 100644 --- a/boost/intrusive/detail/any_node_and_algorithms.hpp +++ b/boost/intrusive/detail/any_node_and_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,13 +13,13 @@ #ifndef BOOST_INTRUSIVE_ANY_NODE_HPP #define BOOST_INTRUSIVE_ANY_NODE_HPP -#include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_rebind.hpp> #include <cstddef> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/pointer_cast.hpp> namespace boost { namespace intrusive { @@ -27,8 +27,9 @@ namespace intrusive { template<class VoidPointer> struct any_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<any_node>::type node_ptr; + typedef any_node node; + typedef typename pointer_rebind<VoidPointer, node>::type node_ptr; + typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr; node_ptr node_ptr_1; node_ptr node_ptr_2; node_ptr node_ptr_3; @@ -38,11 +39,9 @@ struct any_node template<class VoidPointer> struct any_list_node_traits { - typedef any_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; static const node_ptr &get_next(const const_node_ptr & n) { return n->node_ptr_1; } @@ -61,11 +60,9 @@ struct any_list_node_traits template<class VoidPointer> struct any_slist_node_traits { - typedef any_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; static const node_ptr &get_next(const const_node_ptr & n) { return n->node_ptr_1; } @@ -110,12 +107,9 @@ struct any_unordered_node_traits template<class VoidPointer> struct any_rbtree_node_traits { - typedef any_node<VoidPointer> node; - - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; typedef std::size_t color; @@ -154,12 +148,10 @@ struct any_rbtree_node_traits template<class VoidPointer> struct any_avltree_node_traits { - typedef any_node<VoidPointer> node; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; typedef std::size_t balance; static const node_ptr &get_parent(const const_node_ptr & n) @@ -200,12 +192,9 @@ struct any_avltree_node_traits template<class VoidPointer> struct any_tree_node_traits { - typedef any_node<VoidPointer> node; - - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; static const node_ptr &get_parent(const const_node_ptr & n) { return n->node_ptr_1; } @@ -231,10 +220,8 @@ class any_node_traits { public: typedef any_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; }; template<class VoidPointer> @@ -245,12 +232,10 @@ class any_algorithms {} public: - typedef any_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; - typedef any_node_traits<VoidPointer> node_traits; + typedef any_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; + typedef any_node_traits<VoidPointer> node_traits; //! <b>Requires</b>: node must not be part of any tree. //! @@ -281,7 +266,7 @@ class any_algorithms any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>(); } - static void swap_nodes(const node_ptr & l, const node_ptr & r) + static void swap_nodes(const node_ptr &, const node_ptr &) { //Any nodes have no swap_nodes capability because they don't know //what algorithm they must use to unlink the node from the container @@ -292,6 +277,4 @@ class any_algorithms } //namespace intrusive } //namespace boost -#include <boost/intrusive/detail/config_end.hpp> - #endif //BOOST_INTRUSIVE_ANY_NODE_HPP diff --git a/boost/intrusive/detail/array_initializer.hpp b/boost/intrusive/detail/array_initializer.hpp new file mode 100644 index 0000000000..b2072a872d --- /dev/null +++ b/boost/intrusive/detail/array_initializer.hpp @@ -0,0 +1,90 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP +#define BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/core/no_exceptions_support.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +//This is not standard, but should work with all compilers +union max_align +{ + char char_; + short short_; + int int_; + long long_; + #ifdef BOOST_HAS_LONG_LONG + long long long_long_; + #endif + float float_; + double double_; + long double long_double_; + void * void_ptr_; +}; + +template<class T, std::size_t N> +class array_initializer +{ + public: + template<class CommonInitializer> + array_initializer(const CommonInitializer &init) + { + char *init_buf = (char*)rawbuf; + std::size_t i = 0; + BOOST_TRY{ + for(; i != N; ++i){ + new(init_buf)T(init); + init_buf += sizeof(T); + } + } + BOOST_CATCH(...){ + while(i--){ + init_buf -= sizeof(T); + ((T*)init_buf)->~T(); + } + BOOST_RETHROW; + } + BOOST_CATCH_END + } + + operator T* () + { return (T*)(rawbuf); } + + operator const T*() const + { return (const T*)(rawbuf); } + + ~array_initializer() + { + char *init_buf = (char*)rawbuf + N*sizeof(T); + for(std::size_t i = 0; i != N; ++i){ + init_buf -= sizeof(T); + ((T*)init_buf)->~T(); + } + } + + private: + detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1]; +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_ARRAY_INITIALIZER_HPP diff --git a/boost/intrusive/detail/assert.hpp b/boost/intrusive/detail/assert.hpp index 33de97f701..d75d225ac4 100644 --- a/boost/intrusive/detail/assert.hpp +++ b/boost/intrusive/detail/assert.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,7 +13,7 @@ #ifndef BOOST_INTRUSIVE_DETAIL_ASSERT_HPP #define BOOST_INTRUSIVE_DETAIL_ASSERT_HPP -#if defined(_MSC_VER)&&(_MSC_VER>=1200) +#if defined(_MSC_VER) #pragma once #endif diff --git a/boost/intrusive/detail/avltree_node.hpp b/boost/intrusive/detail/avltree_node.hpp index aec0dabd4b..522806a89e 100644 --- a/boost/intrusive/detail/avltree_node.hpp +++ b/boost/intrusive/detail/avltree_node.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,9 +13,12 @@ #ifndef BOOST_INTRUSIVE_AVLTREE_NODE_HPP #define BOOST_INTRUSIVE_AVLTREE_NODE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/pointer_rebind.hpp> #include <boost/intrusive/avltree_algorithms.hpp> #include <boost/intrusive/pointer_plus_bits.hpp> #include <boost/intrusive/detail/mpl.hpp> @@ -33,9 +36,8 @@ namespace intrusive { template<class VoidPointer> struct compact_avltree_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <compact_avltree_node<VoidPointer> >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, compact_avltree_node<VoidPointer> >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, const compact_avltree_node<VoidPointer> >::type const_node_ptr; enum balance { negative_t, zero_t, positive_t }; node_ptr parent_, left_, right_; }; @@ -44,9 +46,8 @@ struct compact_avltree_node template<class VoidPointer> struct avltree_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <avltree_node<VoidPointer> >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, avltree_node<VoidPointer> >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, const avltree_node<VoidPointer> >::type const_node_ptr; enum balance { negative_t, zero_t, positive_t }; node_ptr parent_, left_, right_; balance balance_; @@ -58,29 +59,33 @@ template<class VoidPointer> struct default_avltree_node_traits_impl { typedef avltree_node<VoidPointer> node; - - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; typedef typename node::balance balance; - static const node_ptr & get_parent(const const_node_ptr & n) + static node_ptr get_parent(const const_node_ptr & n) + { return n->parent_; } + + static node_ptr get_parent(const node_ptr & n) { return n->parent_; } static void set_parent(const node_ptr & n, const node_ptr & p) { n->parent_ = p; } - static const node_ptr & get_left(const const_node_ptr & n) + static node_ptr get_left(const const_node_ptr & n) + { return n->left_; } + + static node_ptr get_left(const node_ptr & n) { return n->left_; } static void set_left(const node_ptr & n, const node_ptr & l) { n->left_ = l; } - static const node_ptr & get_right(const const_node_ptr & n) + static node_ptr get_right(const const_node_ptr & n) + { return n->right_; } + + static node_ptr get_right(const node_ptr & n) { return n->right_; } static void set_right(const node_ptr & n, const node_ptr & r) @@ -89,6 +94,9 @@ struct default_avltree_node_traits_impl static balance get_balance(const const_node_ptr & n) { return n->balance_; } + static balance get_balance(const node_ptr & n) + { return n->balance_; } + static void set_balance(const node_ptr & n, balance b) { n->balance_ = b; } @@ -108,13 +116,8 @@ template<class VoidPointer> struct compact_avltree_node_traits_impl { typedef compact_avltree_node<VoidPointer> node; - - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; typedef typename node::balance balance; typedef pointer_plus_bits<node_ptr, 2> ptr_bit; @@ -125,13 +128,13 @@ struct compact_avltree_node_traits_impl static void set_parent(const node_ptr & n, const node_ptr & p) { ptr_bit::set_pointer(n->parent_, p); } - static const node_ptr & get_left(const const_node_ptr & n) + static node_ptr get_left(const const_node_ptr & n) { return n->left_; } static void set_left(const node_ptr & n, const node_ptr & l) { n->left_ = l; } - static const node_ptr & get_right(const const_node_ptr & n) + static node_ptr get_right(const const_node_ptr & n) { return n->right_; } static void set_right(const node_ptr & n, const node_ptr & r) @@ -164,7 +167,7 @@ struct avltree_node_traits_dispatch<VoidPointer, true> : public compact_avltree_node_traits_impl<VoidPointer> {}; -//Inherit from the detail::link_dispatch depending on the embedding capabilities +//Inherit from rbtree_node_traits_dispatch depending on the embedding capabilities template<class VoidPointer, bool OptimizeSize = false> struct avltree_node_traits : public avltree_node_traits_dispatch diff --git a/boost/intrusive/detail/clear_on_destructor_base.hpp b/boost/intrusive/detail/clear_on_destructor_base.hpp deleted file mode 100644 index 1b5c27fff4..0000000000 --- a/boost/intrusive/detail/clear_on_destructor_base.hpp +++ /dev/null @@ -1,36 +0,0 @@ -//////} // /////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2008-2012. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/intrusive for documentation. -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP -#define BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP - -#include <boost/intrusive/detail/config_begin.hpp> - -namespace boost { -namespace intrusive { -namespace detail { - -template<class Derived> -class clear_on_destructor_base -{ - protected: - ~clear_on_destructor_base() - { - static_cast<Derived*>(this)->clear(); - } -}; - -} // namespace detail { -} // namespace intrusive { -} // namespace boost { - -#include <boost/intrusive/detail/config_end.hpp> - -#endif //#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP diff --git a/boost/intrusive/detail/common_slist_algorithms.hpp b/boost/intrusive/detail/common_slist_algorithms.hpp index 942b35a3f4..4c7f1a11e0 100644 --- a/boost/intrusive/detail/common_slist_algorithms.hpp +++ b/boost/intrusive/detail/common_slist_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,9 +13,14 @@ #ifndef BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP #define BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP -#include <boost/intrusive/detail/config_begin.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/assert.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/core/no_exceptions_support.hpp> #include <cstddef> namespace boost { @@ -31,9 +36,8 @@ class common_slist_algorithms typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; - static node_ptr get_previous_node(const node_ptr & prev_init_node, const node_ptr & this_node) + static node_ptr get_previous_node(node_ptr p, const node_ptr & this_node) { - node_ptr p = prev_init_node; for( node_ptr p_next ; this_node != (p_next = NodeTraits::get_next(p)) ; p = p_next){ @@ -44,9 +48,6 @@ class common_slist_algorithms return p; } - static void init_header(const node_ptr & this_node) - { NodeTraits::set_next(this_node, this_node); } - static void init(const node_ptr & this_node) { NodeTraits::set_next(this_node, node_ptr()); } @@ -92,12 +93,102 @@ class common_slist_algorithms NodeTraits::set_next(bp, next_b); } } + + struct stable_partition_info + { + std::size_t num_1st_partition; + std::size_t num_2nd_partition; + node_ptr beg_2st_partition; + node_ptr new_last_node; + }; + + template<class Pred> + static void stable_partition(node_ptr before_beg, const node_ptr &end, Pred pred, stable_partition_info &info) + { + node_ptr bcur = before_beg; + node_ptr cur = node_traits::get_next(bcur); + node_ptr new_f = end; + + std::size_t num1 = 0, num2 = 0; + while(cur != end){ + if(pred(cur)){ + ++num1; + bcur = cur; + cur = node_traits::get_next(cur); + } + else{ + ++num2; + node_ptr last_to_remove = bcur; + new_f = cur; + bcur = cur; + cur = node_traits::get_next(cur); + BOOST_TRY{ + //Main loop + while(cur != end){ + if(pred(cur)){ //Might throw + ++num1; + //Process current node + node_traits::set_next(last_to_remove, cur); + last_to_remove = cur; + node_ptr nxt = node_traits::get_next(cur); + node_traits::set_next(bcur, nxt); + cur = nxt; + } + else{ + ++num2; + bcur = cur; + cur = node_traits::get_next(cur); + } + } + } + BOOST_CATCH(...){ + node_traits::set_next(last_to_remove, new_f); + throw; + } + BOOST_CATCH_END + node_traits::set_next(last_to_remove, new_f); + break; + } + } + info.num_1st_partition = num1; + info.num_2nd_partition = num2; + info.beg_2st_partition = new_f; + info.new_last_node = bcur; + } + + //! <b>Requires</b>: f and l must be in a circular list. + //! + //! <b>Effects</b>: Returns the number of nodes in the range [f, l). + //! + //! <b>Complexity</b>: Linear + //! + //! <b>Throws</b>: Nothing. + static std::size_t distance(const const_node_ptr &f, const const_node_ptr &l) + { + const_node_ptr i(f); + std::size_t result = 0; + while(i != l){ + i = NodeTraits::get_next(i); + ++result; + } + return result; + } }; +/// @endcond + } //namespace detail + +/// @cond + +template<class NodeTraits> +struct get_algo<CommonSListAlgorithms, NodeTraits> +{ + typedef detail::common_slist_algorithms<NodeTraits> type; +}; + + } //namespace intrusive } //namespace boost -#include <boost/intrusive/detail/config_end.hpp> - #endif //BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP diff --git a/boost/intrusive/detail/config_begin.hpp b/boost/intrusive/detail/config_begin.hpp index 7d153368a5..36d605d072 100644 --- a/boost/intrusive/detail/config_begin.hpp +++ b/boost/intrusive/detail/config_begin.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -10,8 +10,7 @@ // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_CONFIG_INCLUDED -#define BOOST_INTRUSIVE_CONFIG_INCLUDED +#ifndef BOOST_CONFIG_HPP #include <boost/config.hpp> #endif diff --git a/boost/intrusive/detail/config_end.hpp b/boost/intrusive/detail/config_end.hpp index d653030daa..a081443e69 100644 --- a/boost/intrusive/detail/config_end.hpp +++ b/boost/intrusive/detail/config_end.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at diff --git a/boost/intrusive/detail/default_header_holder.hpp b/boost/intrusive/detail/default_header_holder.hpp new file mode 100644 index 0000000000..c471691640 --- /dev/null +++ b/boost/intrusive/detail/default_header_holder.hpp @@ -0,0 +1,65 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP +#define BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/to_raw_pointer.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +// trivial header node holder +template < typename NodeTraits > +struct default_header_holder : public NodeTraits::node +{ + typedef NodeTraits node_traits; + typedef typename node_traits::node node; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + + default_header_holder() : node() {} + + const_node_ptr get_node() const + { return pointer_traits< const_node_ptr >::pointer_to(*static_cast< const node* >(this)); } + + node_ptr get_node() + { return pointer_traits< node_ptr >::pointer_to(*static_cast< node* >(this)); } + + // (unsafe) downcast used to implement container-from-iterator + static default_header_holder* get_holder(const node_ptr &p) + { return static_cast< default_header_holder* >(boost::intrusive::detail::to_raw_pointer(p)); } +}; + +// type function producing the header node holder +template < typename Value_Traits, typename HeaderHolder > +struct get_header_holder_type +{ + typedef HeaderHolder type; +}; +template < typename Value_Traits > +struct get_header_holder_type< Value_Traits, void > +{ + typedef default_header_holder< typename Value_Traits::node_traits > type; +}; + +} //namespace detail +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP diff --git a/boost/intrusive/detail/ebo_functor_holder.hpp b/boost/intrusive/detail/ebo_functor_holder.hpp index 850d074326..d2e8107b67 100644 --- a/boost/intrusive/detail/ebo_functor_holder.hpp +++ b/boost/intrusive/detail/ebo_functor_holder.hpp @@ -1,6 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Joaquin M Lopez Munoz 2006-2012 +// (C) Copyright Joaquin M Lopez Munoz 2006-2013 +// (C) Copyright Ion Gaztanaga 2014-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,13 +14,145 @@ #ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP #define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP -#include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/detail/mpl.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/config.hpp> namespace boost { namespace intrusive { namespace detail { +#if defined(BOOST_MSVC) || defined(__BORLANDC_) +#define BOOST_INTRUSIVE_TT_DECL __cdecl +#else +#define BOOST_INTRUSIVE_TT_DECL +#endif + +#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(UNDER_CE) +#define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS +#endif + +template <typename T> +struct is_unary_or_binary_function_impl +{ static const bool value = false; }; + +// see boost ticket #4094 +// avoid duplicate definitions of is_unary_or_binary_function_impl +#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R> +struct is_unary_or_binary_function_impl<R (*)()> +{ static const bool value = true; }; + +template <typename R> +struct is_unary_or_binary_function_impl<R (*)(...)> +{ static const bool value = true; }; + +#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R> +struct is_unary_or_binary_function_impl<R (__stdcall*)()> +{ static const bool value = true; }; + +#ifndef _MANAGED + +template <typename R> +struct is_unary_or_binary_function_impl<R (__fastcall*)()> +{ static const bool value = true; }; + +#endif + +template <typename R> +struct is_unary_or_binary_function_impl<R (__cdecl*)()> +{ static const bool value = true; }; + +template <typename R> +struct is_unary_or_binary_function_impl<R (__cdecl*)(...)> +{ static const bool value = true; }; + +#endif + +// see boost ticket #4094 +// avoid duplicate definitions of is_unary_or_binary_function_impl +#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (*)(T0)> +{ static const bool value = true; }; + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (*)(T0...)> +{ static const bool value = true; }; + +#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)> +{ static const bool value = true; }; + +#ifndef _MANAGED + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)> +{ static const bool value = true; }; + +#endif + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)> +{ static const bool value = true; }; + +template <typename R, class T0> +struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)> +{ static const bool value = true; }; + +#endif + +// see boost ticket #4094 +// avoid duplicate definitions of is_unary_or_binary_function_impl +#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (*)(T0, T1)> +{ static const bool value = true; }; + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (*)(T0, T1...)> +{ static const bool value = true; }; + +#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)> +{ static const bool value = true; }; + +#ifndef _MANAGED + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)> +{ static const bool value = true; }; + +#endif + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)> +{ static const bool value = true; }; + +template <typename R, class T0, class T1> +struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)> +{ static const bool value = true; }; +#endif + +template <typename T> +struct is_unary_or_binary_function_impl<T&> +{ static const bool value = false; }; + +template<typename T> +struct is_unary_or_binary_function : is_unary_or_binary_function_impl<T> +{}; + template<typename T, bool IsEmpty = true> class ebo_functor_holder_impl { @@ -90,6 +223,4 @@ class ebo_functor_holder } //namespace intrusive { } //namespace boost { -#include <boost/intrusive/detail/config_end.hpp> - #endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP diff --git a/boost/intrusive/detail/empty_node_checker.hpp b/boost/intrusive/detail/empty_node_checker.hpp new file mode 100644 index 0000000000..33d78a34ba --- /dev/null +++ b/boost/intrusive/detail/empty_node_checker.hpp @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP +#define BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { +namespace detail { + +template<class ValueTraits> +struct empty_node_checker +{ + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::const_node_ptr const_node_ptr; + + struct return_type {}; + + void operator () (const const_node_ptr&, const return_type&, const return_type&, return_type&) {} +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_EMPTY_NODE_CHECKER_HPP diff --git a/boost/intrusive/detail/equal_to_value.hpp b/boost/intrusive/detail/equal_to_value.hpp new file mode 100644 index 0000000000..3ffd1c26cf --- /dev/null +++ b/boost/intrusive/detail/equal_to_value.hpp @@ -0,0 +1,44 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP +#define BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { +namespace detail { + +//This functor compares a stored value +//and the one passed as an argument +template<class ConstReference> +class equal_to_value +{ + ConstReference t_; + + public: + equal_to_value(ConstReference t) + : t_(t) + {} + + bool operator()(ConstReference t)const + { return t_ == t; } +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_EQUAL_TO_VALUE_HPP diff --git a/boost/intrusive/detail/exception_disposer.hpp b/boost/intrusive/detail/exception_disposer.hpp new file mode 100644 index 0000000000..1226f5e525 --- /dev/null +++ b/boost/intrusive/detail/exception_disposer.hpp @@ -0,0 +1,84 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP +#define BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { +namespace detail { + +template<class Container, class Disposer> +class exception_disposer +{ + Container *cont_; + Disposer &disp_; + + exception_disposer(const exception_disposer&); + exception_disposer &operator=(const exception_disposer&); + + public: + exception_disposer(Container &cont, Disposer &disp) + : cont_(&cont), disp_(disp) + {} + + void release() + { cont_ = 0; } + + ~exception_disposer() + { + if(cont_){ + cont_->clear_and_dispose(disp_); + } + } +}; + +template<class Container, class Disposer, class SizeType> +class exception_array_disposer +{ + Container *cont_; + Disposer &disp_; + SizeType &constructed_; + + exception_array_disposer(const exception_array_disposer&); + exception_array_disposer &operator=(const exception_array_disposer&); + + public: + + exception_array_disposer + (Container &cont, Disposer &disp, SizeType &constructed) + : cont_(&cont), disp_(disp), constructed_(constructed) + {} + + void release() + { cont_ = 0; } + + ~exception_array_disposer() + { + SizeType n = constructed_; + if(cont_){ + while(n--){ + cont_[n].clear_and_dispose(disp_); + } + } + } +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP diff --git a/boost/intrusive/detail/function_detector.hpp b/boost/intrusive/detail/function_detector.hpp index 08cee2d561..f72865df9b 100644 --- a/boost/intrusive/detail/function_detector.hpp +++ b/boost/intrusive/detail/function_detector.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2009-2012. +// (C) Copyright Ion Gaztanaga 2009-2013. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -22,7 +22,9 @@ #ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP #define BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP -#include <boost/intrusive/detail/config_begin.hpp> +#if defined(_MSC_VER) +# pragma once +#endif namespace boost { namespace intrusive { @@ -83,6 +85,4 @@ namespace function_detector { ReturnType (*)Params \ >::check -#include <boost/intrusive/detail/config_end.hpp> - #endif //@ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP diff --git a/boost/intrusive/detail/generic_hook.hpp b/boost/intrusive/detail/generic_hook.hpp index 5ddd52074e..c5af081d65 100644 --- a/boost/intrusive/detail/generic_hook.hpp +++ b/boost/intrusive/detail/generic_hook.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,139 +13,147 @@ #ifndef BOOST_INTRUSIVE_GENERIC_HOOK_HPP #define BOOST_INTRUSIVE_GENERIC_HOOK_HPP -#include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/pointer_traits.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/intrusive/detail/utilities.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/assert.hpp> +#include <boost/intrusive/detail/node_holder.hpp> #include <boost/static_assert.hpp> namespace boost { namespace intrusive { -namespace detail { /// @cond -enum -{ NoBaseHook -, ListBaseHook -, SlistBaseHook -, SetBaseHook -, UsetBaseHook -, SplaySetBaseHook -, AvlSetBaseHook -, BsSetBaseHook -, AnyBaseHook -}; - -struct no_default_definer{}; +namespace detail { -template <class Hook, unsigned int> -struct default_definer; +template <link_mode_type LinkMode> +struct link_dispatch +{}; + +template<class Hook> +void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>) +{ //If this assertion raises, you might have destroyed an object + //while it was still inserted in a container that is alive. + //If so, remove the object from the container before destroying it. + (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked()); +} + +template<class Hook> +void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>) +{ hook.unlink(); } + +template<class Hook> +void destructor_impl(Hook &, detail::link_dispatch<normal_link>) +{} + +} //namespace detail { + +enum base_hook_type +{ NoBaseHookId +, ListBaseHookId +, SlistBaseHookId +, RbTreeBaseHookId +, HashBaseHookId +, AvlTreeBaseHookId +, BsTreeBaseHookId +, TreapTreeBaseHookId +, AnyBaseHookId +}; -template <class Hook> -struct default_definer<Hook, ListBaseHook> -{ typedef Hook default_list_hook; }; -template <class Hook> -struct default_definer<Hook, SlistBaseHook> -{ typedef Hook default_slist_hook; }; +template <class HookTags, unsigned int> +struct hook_tags_definer{}; -template <class Hook> -struct default_definer<Hook, SetBaseHook> -{ typedef Hook default_set_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, ListBaseHookId> +{ typedef HookTags default_list_hook; }; -template <class Hook> -struct default_definer<Hook, UsetBaseHook> -{ typedef Hook default_uset_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, SlistBaseHookId> +{ typedef HookTags default_slist_hook; }; -template <class Hook> -struct default_definer<Hook, SplaySetBaseHook> -{ typedef Hook default_splay_set_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, RbTreeBaseHookId> +{ typedef HookTags default_rbtree_hook; }; -template <class Hook> -struct default_definer<Hook, AvlSetBaseHook> -{ typedef Hook default_avl_set_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, HashBaseHookId> +{ typedef HookTags default_hashtable_hook; }; -template <class Hook> -struct default_definer<Hook, BsSetBaseHook> -{ typedef Hook default_bs_set_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, AvlTreeBaseHookId> +{ typedef HookTags default_avltree_hook; }; -template <class Hook> -struct default_definer<Hook, AnyBaseHook> -{ typedef Hook default_any_hook; }; +template <class HookTags> +struct hook_tags_definer<HookTags, BsTreeBaseHookId> +{ typedef HookTags default_bstree_hook; }; -template <class Hook, unsigned int BaseHookType> -struct make_default_definer -{ - typedef typename detail::if_c - < BaseHookType != 0 - , default_definer<Hook, BaseHookType> - , no_default_definer>::type type; -}; +template <class HookTags> +struct hook_tags_definer<HookTags, AnyBaseHookId> +{ typedef HookTags default_any_hook; }; template - < class GetNodeAlgorithms + < class NodeTraits , class Tag , link_mode_type LinkMode - , int HookType + , base_hook_type BaseHookType > -struct make_node_holder +struct hooktags_impl { - typedef typename detail::if_c - <!detail::is_same<Tag, member_tag>::value - , detail::node_holder - < typename GetNodeAlgorithms::type::node - , Tag - , LinkMode - , HookType> - , typename GetNodeAlgorithms::type::node - >::type type; + static const link_mode_type link_mode = LinkMode; + typedef Tag tag; + typedef NodeTraits node_traits; + static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value; + static const bool safemode_or_autounlink = is_safe_autounlink<link_mode>::value; + static const unsigned int type = BaseHookType; }; /// @endcond template - < class GetNodeAlgorithms + < class NodeAlgorithms , class Tag , link_mode_type LinkMode - , int HookType + , base_hook_type BaseHookType > class generic_hook /// @cond - - //If the hook is a base hook, derive generic hook from detail::node_holder + //If the hook is a base hook, derive generic hook from node_holder //so that a unique base class is created to convert from the node - //to the type. This mechanism will be used by base_hook_traits. + //to the type. This mechanism will be used by bhtraits. // //If the hook is a member hook, generic hook will directly derive //from the hook. - : public make_default_definer - < generic_hook<GetNodeAlgorithms, Tag, LinkMode, HookType> - , detail::is_same<Tag, default_tag>::value*HookType + : public detail::if_c + < detail::is_same<Tag, member_tag>::value + , typename NodeAlgorithms::node + , node_holder<typename NodeAlgorithms::node, Tag, BaseHookType> >::type - , public make_node_holder<GetNodeAlgorithms, Tag, LinkMode, HookType>::type + //If this is the a default-tagged base hook derive from a class that + //will define an special internal typedef. Containers will be able to detect this + //special typedef and obtain generic_hook's internal types in order to deduce + //value_traits for this hook. + , public hook_tags_definer + < generic_hook<NodeAlgorithms, Tag, LinkMode, BaseHookType> + , detail::is_same<Tag, default_tag>::value*BaseHookType> /// @endcond { /// @cond - typedef typename GetNodeAlgorithms::type node_algorithms; + typedef NodeAlgorithms node_algorithms; typedef typename node_algorithms::node node; typedef typename node_algorithms::node_ptr node_ptr; typedef typename node_algorithms::const_node_ptr const_node_ptr; public: - struct boost_intrusive_tags - { - static const int hook_type = HookType; - static const link_mode_type link_mode = LinkMode; - typedef Tag tag; - typedef typename GetNodeAlgorithms::type::node_traits node_traits; - static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value; - static const bool safemode_or_autounlink = - (int)link_mode == (int)auto_unlink || (int)link_mode == (int)safe_link; - }; + + typedef hooktags_impl + < typename NodeAlgorithms::node_traits + , Tag, LinkMode, BaseHookType> hooktags; node_ptr this_ptr() { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*this)); } @@ -158,14 +166,14 @@ class generic_hook generic_hook() { - if(boost_intrusive_tags::safemode_or_autounlink){ + if(hooktags::safemode_or_autounlink){ node_algorithms::init(this->this_ptr()); } } generic_hook(const generic_hook& ) { - if(boost_intrusive_tags::safemode_or_autounlink){ + if(hooktags::safemode_or_autounlink){ node_algorithms::init(this->this_ptr()); } } @@ -176,7 +184,7 @@ class generic_hook ~generic_hook() { destructor_impl - (*this, detail::link_dispatch<boost_intrusive_tags::link_mode>()); + (*this, detail::link_dispatch<hooktags::link_mode>()); } void swap_nodes(generic_hook &other) @@ -188,22 +196,22 @@ class generic_hook bool is_linked() const { //is_linked() can be only used in safe-mode or auto-unlink - BOOST_STATIC_ASSERT(( boost_intrusive_tags::safemode_or_autounlink )); + BOOST_STATIC_ASSERT(( hooktags::safemode_or_autounlink )); return !node_algorithms::unique(this->this_ptr()); } void unlink() { - BOOST_STATIC_ASSERT(( (int)boost_intrusive_tags::link_mode == (int)auto_unlink )); - node_algorithms::unlink(this->this_ptr()); - node_algorithms::init(this->this_ptr()); + BOOST_STATIC_ASSERT(( (int)hooktags::link_mode == (int)auto_unlink )); + node_ptr n(this->this_ptr()); + if(!node_algorithms::inited(n)){ + node_algorithms::unlink(n); + node_algorithms::init(n); + } } }; -} //namespace detail } //namespace intrusive } //namespace boost -#include <boost/intrusive/detail/config_end.hpp> - #endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP diff --git a/boost/intrusive/detail/get_value_traits.hpp b/boost/intrusive/detail/get_value_traits.hpp new file mode 100644 index 0000000000..6f5a9e3f04 --- /dev/null +++ b/boost/intrusive/detail/get_value_traits.hpp @@ -0,0 +1,218 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP +#define BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/hook_traits.hpp> + +namespace boost { +namespace intrusive { + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +template<class SupposedValueTraits> +struct is_default_hook_tag +{ static const bool value = false; }; + +namespace detail{ + +template <class T, class BaseHook> +struct concrete_hook_base_value_traits +{ + typedef typename BaseHook::hooktags tags; + typedef bhtraits + < T + , typename tags::node_traits + , tags::link_mode + , typename tags::tag + , tags::type> type; +}; + +template <class BaseHook> +struct concrete_hook_base_value_traits<void, BaseHook> +{ + typedef typename BaseHook::hooktags type; +}; + +template <class T, class AnyToSomeHook_ProtoValueTraits> +struct any_hook_base_value_traits +{ + //AnyToSomeHook value_traits derive from a generic_hook + //The generic_hook is configured with any_node_traits + //and AnyToSomeHook::value_traits with the correct + //node traits for the container, so use node_traits + //from AnyToSomeHook_ProtoValueTraits and the rest of + //elements from the hooktags member of the generic_hook + + typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t; + typedef typename pointer_rebind + < typename basic_hook_t::hooktags::node_traits::node_ptr + , void>::type void_pointer; + typedef typename AnyToSomeHook_ProtoValueTraits::template + node_traits_from_voidptr<void_pointer>::type node_traits; + + typedef bhtraits + < T + , node_traits + , basic_hook_t::hooktags::link_mode + , typename basic_hook_t::hooktags::tag + , basic_hook_t::hooktags::type + > type; +}; + +template <class AnyToSomeHook_ProtoValueTraits> +struct any_hook_base_value_traits<void, AnyToSomeHook_ProtoValueTraits> +{ + typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t; + typedef typename pointer_rebind + < typename basic_hook_t::hooktags::node_traits::node_ptr + , void>::type void_pointer; + + struct type + { + typedef typename AnyToSomeHook_ProtoValueTraits::template + node_traits_from_voidptr<void_pointer>::type node_traits; + }; +}; + +template<class MemberHook> +struct get_member_value_traits +{ + typedef typename MemberHook::member_value_traits type; +}; + +BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(internal_any_hook, is_any_hook) +BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(internal_base_hook, hooktags::is_base_hook) + +template <class T> +struct internal_member_value_traits +{ + template <class U> static one test(...); + template <class U> static two test(typename U::member_value_traits* = 0); + static const bool value = sizeof(test<T>(0)) == sizeof(two); +}; + +template<class SupposedValueTraits, class T, bool = is_default_hook_tag<SupposedValueTraits>::value> +struct supposed_value_traits; + +template<class T, class BaseHook, bool = internal_any_hook_bool_is_true<BaseHook>::value> +struct get_base_value_traits; + +template<class SupposedValueTraits, class T, bool = internal_base_hook_bool_is_true<SupposedValueTraits>::value> +struct supposed_base_value_traits; + +template<class SupposedValueTraits, bool = internal_member_value_traits<SupposedValueTraits>::value> +struct supposed_member_value_traits; + +template<class SupposedValueTraits, bool = internal_any_hook_bool_is_true<SupposedValueTraits>::value> +struct any_or_concrete_value_traits; + +//Base any hook +template<class T, class BaseHook> +struct get_base_value_traits<T, BaseHook, true> + : any_hook_base_value_traits<T, BaseHook> +{}; + +//Non-any base hook +template<class T, class BaseHook> +struct get_base_value_traits<T, BaseHook, false> + : concrete_hook_base_value_traits<T, BaseHook> +{}; + +//...It's a default hook +template<class SupposedValueTraits, class T> +struct supposed_value_traits<SupposedValueTraits, T, true> +{ typedef typename SupposedValueTraits::template apply<T>::type type; }; + +//...Not a default hook +template<class SupposedValueTraits, class T> +struct supposed_value_traits<SupposedValueTraits, T, false> +{ typedef SupposedValueTraits type; }; + +//...It's a base hook +template<class BaseHook, class T> +struct supposed_base_value_traits<BaseHook, T, true> + : get_base_value_traits<T, BaseHook> +{}; + +//...Not a base hook, try if it's a member or value_traits +template<class SupposedValueTraits, class T> +struct supposed_base_value_traits<SupposedValueTraits, T, false> + : supposed_member_value_traits<SupposedValueTraits> +{}; + +//...It's a member hook +template<class MemberHook> +struct supposed_member_value_traits<MemberHook, true> + : get_member_value_traits<MemberHook> +{}; + +//...Not a member hook +template<class SupposedValueTraits> +struct supposed_member_value_traits<SupposedValueTraits, false> + : any_or_concrete_value_traits<SupposedValueTraits> +{}; + +template<class AnyToSomeHook_ProtoValueTraits> +struct any_or_concrete_value_traits<AnyToSomeHook_ProtoValueTraits, true> +{ + //A hook node (non-base, e.g.: member or other value traits + typedef typename AnyToSomeHook_ProtoValueTraits::basic_hook_t basic_hook_t; + typedef typename pointer_rebind + <typename basic_hook_t::node_ptr, void>::type void_pointer; + typedef typename AnyToSomeHook_ProtoValueTraits::template + node_traits_from_voidptr<void_pointer>::type any_node_traits; + + struct type : basic_hook_t + { + typedef any_node_traits node_traits; + }; +}; + +template<class SupposedValueTraits> +struct any_or_concrete_value_traits<SupposedValueTraits, false> +{ + typedef SupposedValueTraits type; +}; + +//////////////////////////////////////// +// get_value_traits / get_node_traits +//////////////////////////////////////// + +template<class T, class SupposedValueTraits> +struct get_value_traits + : supposed_base_value_traits<typename supposed_value_traits<SupposedValueTraits, T>::type, T> +{}; + +template<class SupposedValueTraits> +struct get_node_traits +{ + typedef typename get_value_traits<void, SupposedValueTraits>::type::node_traits type; +}; + +} //namespace detail{ + +#endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED + +} //namespace intrusive { +} //namespace boost { + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //#ifndef BOOST_INTRUSIVE_DETAIL_GET_VALUE_TRAITS_HPP diff --git a/boost/intrusive/detail/has_member_function_callable_with.hpp b/boost/intrusive/detail/has_member_function_callable_with.hpp index 6516e28067..ca96f15a19 100644 --- a/boost/intrusive/detail/has_member_function_callable_with.hpp +++ b/boost/intrusive/detail/has_member_function_callable_with.hpp @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2011-2014. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -15,11 +15,10 @@ #ifndef BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED #define BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED - #include <boost/intrusive/detail/config_begin.hpp> - #include <boost/intrusive/detail/workaround.hpp> #include <boost/intrusive/detail/preprocessor.hpp> - #include <boost/static_assert.hpp> - #include <boost/move/move.hpp> + #include <boost/intrusive/detail/mpl.hpp> + #include <boost/move/utility_core.hpp> + //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and //wrong SFINAE for GCC 4.2/4.3 @@ -36,6 +35,12 @@ dont_care(...); }; + template<class T> + struct make_dontcare + { + typedef boost_intrusive_has_member_function_callable_with::dont_care type; + }; + struct private_type { static private_type p; @@ -51,7 +56,9 @@ } //boost_intrusive_has_member_function_callable_with - #include <boost/intrusive/detail/config_end.hpp> + #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_SINGLE_ITERATION + #endif #endif //BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_DETAILS_INCLUDED @@ -69,11 +76,11 @@ #error "BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END not defined!" #endif - #if BOOST_PP_ITERATION_START() != 0 - #error "BOOST_PP_ITERATION_START() must be zero (0)" + #if BOOST_PP_ITERATION_START() > BOOST_PP_ITERATION_FINISH() + #error "BOOST_PP_ITERATION_START() must be <= BOOST_PP_ITERATION_FINISH()" #endif - #if BOOST_PP_ITERATION() == 0 + #if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_START() BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN @@ -85,7 +92,7 @@ void BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME(); }; - struct Base : public Type, public BaseMixin { Base(); }; + struct Base : public ::boost::intrusive::detail::remove_cv<Type>::type, public BaseMixin { Base(); }; template <typename T, T t> class Helper{}; template <typename U> @@ -98,7 +105,7 @@ sizeof(boost_intrusive_has_member_function_callable_with::yes_type) == sizeof(deduce((Base*)(0))); }; - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template<typename Fun, bool HasFunc BOOST_PP_ENUM_TRAILING(BOOST_PP_ITERATION_FINISH(), BOOST_INTRUSIVE_PP_TEMPLATE_PARAM_VOID_DEFAULT, _)> @@ -113,76 +120,7 @@ }; //! - #if !defined(_MSC_VER) || (_MSC_VER < 1600) - - #if defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - template<typename Fun> - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> - { - //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and - //wrong SFINAE for GCC 4.2/4.3 - static const bool value = true; - }; - - #else //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - //Special case for 0 args - template< class F - , std::size_t N = - sizeof((boost::move_detail::declval<F>(). - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) - { - boost_intrusive_has_member_function_callable_with::yes_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not - //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. - template<class F> - struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<F, 0> - { - boost_intrusive_has_member_function_callable_with::no_type dummy; - BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); - }; - - template<typename Fun> - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> - { - template<class U> - static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U> - Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*); - - template <class U> - static boost_intrusive_has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test< Fun >(0)) - == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); - }; - #endif //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) - - #else //#if !defined(_MSC_VER) || (_MSC_VER < 1600) - template<typename Fun> - struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) - <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> - { - template<class U> - static decltype( boost::move_detail::declval<Fun>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() - , boost_intrusive_has_member_function_callable_with::yes_type()) - Test(Fun*); - - template<class U> - static boost_intrusive_has_member_function_callable_with::no_type Test(...); - - static const bool value = sizeof(Test<Fun>(0)) - == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); - }; - #endif //#if !defined(_MSC_VER) || (_MSC_VER < 1600) - - #else //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #else //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template<typename Fun, bool HasFunc, class ...Args> struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl); @@ -194,6 +132,8 @@ static const bool value = false; }; + #ifdef BOOST_NO_CXX11_DECLTYPE + //Special case for 0 args template< class F , std::size_t N = @@ -214,14 +154,21 @@ BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); }; + #endif //#ifdef BOOST_NO_CXX11_DECLTYPE + template<typename Fun> struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) <Fun, true> { + #ifndef BOOST_NO_CXX11_DECLTYPE + template<class U, class V = decltype(boost::move_detail::declval<U>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME()) > + static boost_intrusive_has_member_function_callable_with::yes_type Test(U*); + #else template<class U> - static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) <U> Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*); - + #endif + template <class U> static boost_intrusive_has_member_function_callable_with::no_type Test(...); @@ -229,30 +176,23 @@ == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); }; - template<typename Fun, class ...DontCares> - struct BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) - : Fun - { - BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME )(); - using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; - - boost_intrusive_has_member_function_callable_with::private_type - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( DontCares...) const; - }; - template<typename Fun, class ...Args> struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME), _impl) <Fun, true , Args...> { - template<class T> - struct make_dontcare + + template<class ...DontCares> + struct FunWrapTmpl : Fun { - typedef boost_intrusive_has_member_function_callable_with::dont_care type; + FunWrapTmpl(); + using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; + + boost_intrusive_has_member_function_callable_with::private_type + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( DontCares...) const; }; - typedef BOOST_PP_CAT( funwrap_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME ) - <Fun, typename make_dontcare<Args>::type...> FunWrap; + typedef FunWrapTmpl<typename boost_intrusive_has_member_function_callable_with::make_dontcare<Args>::type...> FunWrap; static bool const value = (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == sizeof(boost_intrusive_has_member_function_callable_with::is_private_type @@ -274,32 +214,99 @@ , Args... > {}; - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #endif //defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END + + #endif //BOOST_PP_ITERATION() == BOOST_PP_ITERATION_START() + + #if BOOST_PP_ITERATION() == 0 + + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN + + #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + #if !defined(_MSC_VER) || (_MSC_VER < 1600) + + #if defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + template<typename Fun> + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> + { + //Mark that we don't support 0 arg calls due to compiler ICE in GCC 3.4/4.0/4.1 and + //wrong SFINAE for GCC 4.2/4.3 + static const bool value = true; + }; + + #else //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + //Special case for 0 args + template< class F + , std::size_t N = + sizeof((boost::move_detail::declval<F>(). + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME (), 0))> + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME) + { + boost_intrusive_has_member_function_callable_with::yes_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + //For buggy compilers like MSVC 7.1+ ((F*)0)->func() does not + //SFINAE-out the zeroarg_checker_ instantiation but sizeof yields to 0. + template<class F> + struct BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<F, 0> + { + boost_intrusive_has_member_function_callable_with::no_type dummy; + BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)(int); + }; + + template<typename Fun> + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> + { + template<class U> + static BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U> + Test(BOOST_PP_CAT(zeroarg_checker_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)<U>*); + + template <class U> + static boost_intrusive_has_member_function_callable_with::no_type Test(...); + + static const bool value = sizeof(Test< Fun >(0)) + == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); + }; + #endif //defined(BOOST_INTRUSIVE_DETAIL_HAS_MEMBER_FUNCTION_CALLABLE_WITH_0_ARGS_UNSUPPORTED) + + #else //#if !defined(_MSC_VER) || (_MSC_VER < 1600) + template<typename Fun> + struct BOOST_PP_CAT(BOOST_PP_CAT(has_member_function_callable_with_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) + <Fun, true BOOST_PP_ENUM_TRAILING(BOOST_PP_SUB(BOOST_PP_ITERATION_FINISH(), BOOST_PP_ITERATION()), BOOST_INTRUSIVE_PP_IDENTITY, void)> + { + template<class U> + static decltype( boost::move_detail::declval<U>().BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME() + , boost_intrusive_has_member_function_callable_with::yes_type()) + Test(U*); + + template<class U> + static boost_intrusive_has_member_function_callable_with::no_type Test(...); + + static const bool value = sizeof(Test<Fun>(0)) + == sizeof(boost_intrusive_has_member_function_callable_with::yes_type); + }; + #endif //#if !defined(_MSC_VER) || (_MSC_VER < 1600) + + #else //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + #endif //#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END #else //BOOST_PP_ITERATION() == 0 - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN - template<typename Fun> - struct BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME)) - : Fun - { - BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))(); - - using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; - boost_intrusive_has_member_function_callable_with::private_type - BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME - ( BOOST_PP_ENUM(BOOST_PP_ITERATION() - , BOOST_INTRUSIVE_PP_IDENTITY - , boost_intrusive_has_member_function_callable_with::dont_care)) const; - }; - template<typename Fun BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), class P)> struct BOOST_PP_CAT( BOOST_PP_CAT(has_member_function_callable_with_ , BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME),_impl) @@ -309,9 +316,18 @@ , BOOST_INTRUSIVE_PP_IDENTITY , void)> { - typedef BOOST_PP_CAT( BOOST_PP_CAT(funwrap, BOOST_PP_ITERATION()) - , BOOST_PP_CAT(_, BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME))<Fun> - FunWrap; + struct FunWrap : Fun + { + FunWrap(); + + using Fun::BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME; + boost_intrusive_has_member_function_callable_with::private_type + BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME + ( BOOST_PP_ENUM(BOOST_PP_ITERATION() + , BOOST_INTRUSIVE_PP_IDENTITY + , boost_intrusive_has_member_function_callable_with::dont_care)) const; + }; + static bool const value = (sizeof(boost_intrusive_has_member_function_callable_with::no_type) == sizeof(boost_intrusive_has_member_function_callable_with::is_private_type @@ -325,13 +341,13 @@ }; BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #endif //#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #endif //BOOST_PP_ITERATION() == 0 #if BOOST_PP_ITERATION() == BOOST_PP_ITERATION_FINISH() - #if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN @@ -345,7 +361,7 @@ BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END - #endif //#if !defined(BOOST_INTRUSIVE_PERFECT_FORWARDING) + #endif //#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME #undef BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN diff --git a/boost/intrusive/detail/hashtable_node.hpp b/boost/intrusive/detail/hashtable_node.hpp index 86e607460c..6449fa0dd2 100644 --- a/boost/intrusive/detail/hashtable_node.hpp +++ b/boost/intrusive/detail/hashtable_node.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,45 +13,24 @@ #ifndef BOOST_INTRUSIVE_HASHTABLE_NODE_HPP #define BOOST_INTRUSIVE_HASHTABLE_NODE_HPP -#include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/circular_list_algorithms.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/detail/utilities.hpp> -//#include <boost/intrusive/detail/slist_node.hpp> //remove-me -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/trivial_value_traits.hpp> +#include <boost/intrusive/slist.hpp> //make_slist #include <cstddef> -#include <boost/pointer_cast.hpp> -#include <boost/move/move.hpp> +#include <climits> +#include <boost/move/core.hpp> namespace boost { namespace intrusive { namespace detail { -template<int Dummy = 0> -struct prime_list_holder -{ - static const std::size_t prime_list[]; - static const std::size_t prime_list_size; -}; - -template<int Dummy> -const std::size_t prime_list_holder<Dummy>::prime_list[] = { - 3ul, 7ul, 11ul, 17ul, 29ul, - 53ul, 97ul, 193ul, 389ul, 769ul, - 1543ul, 3079ul, 6151ul, 12289ul, 24593ul, - 49157ul, 98317ul, 196613ul, 393241ul, 786433ul, - 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, - 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul, - 1610612741ul, 3221225473ul, 4294967291ul }; - -template<int Dummy> -const std::size_t prime_list_holder<Dummy>::prime_list_size - = sizeof(prime_list)/sizeof(std::size_t); - template <class Slist> struct bucket_impl : public Slist { @@ -89,6 +68,7 @@ struct bucket_traits_impl typedef typename pointer_traits <typename Slist::pointer>::template rebind_pointer < bucket_impl<Slist> >::type bucket_ptr; + typedef Slist slist; typedef typename Slist::size_type size_type; /// @endcond @@ -100,7 +80,6 @@ struct bucket_traits_impl : buckets_(x.buckets_), buckets_len_(x.buckets_len_) {} - bucket_traits_impl(BOOST_RV_REF(bucket_traits_impl) x) : buckets_(x.buckets_), buckets_len_(x.buckets_len_) { x.buckets_ = bucket_ptr(); x.buckets_len_ = 0; } @@ -127,57 +106,107 @@ struct bucket_traits_impl size_type buckets_len_; }; -template<class Container, bool IsConst> +template <class NodeTraits> +struct hash_reduced_slist_node_traits +{ + template <class U> static detail::one test(...); + template <class U> static detail::two test(typename U::reduced_slist_node_traits* = 0); + static const bool value = sizeof(test<NodeTraits>(0)) == sizeof(detail::two); +}; + +template <class NodeTraits> +struct apply_reduced_slist_node_traits +{ + typedef typename NodeTraits::reduced_slist_node_traits type; +}; + +template <class NodeTraits> +struct reduced_slist_node_traits +{ + typedef typename detail::eval_if_c + < hash_reduced_slist_node_traits<NodeTraits>::value + , apply_reduced_slist_node_traits<NodeTraits> + , detail::identity<NodeTraits> + >::type type; +}; + +template<class NodeTraits> +struct get_slist_impl +{ + typedef trivial_value_traits<NodeTraits, normal_link> trivial_traits; + + //Reducing symbol length + struct type : make_slist + < typename NodeTraits::node + , boost::intrusive::value_traits<trivial_traits> + , boost::intrusive::constant_time_size<false> + , boost::intrusive::size_type<std::size_t> + >::type + {}; +}; + +} //namespace detail { + +template<class BucketValueTraits, bool IsConst> class hashtable_iterator - : public std::iterator +{ + typedef boost::intrusive::iterator < std::forward_iterator_tag - , typename Container::value_type - , typename pointer_traits<typename Container::value_type*>::difference_type + , typename BucketValueTraits::value_traits::value_type + , typename pointer_traits<typename BucketValueTraits::value_traits::value_type*>::difference_type , typename detail::add_const_if_c - <typename Container::value_type, IsConst>::type * + <typename BucketValueTraits::value_traits::value_type, IsConst>::type * , typename detail::add_const_if_c - <typename Container::value_type, IsConst>::type & - > -{ - typedef typename Container::real_value_traits real_value_traits; - typedef typename Container::siterator siterator; - typedef typename Container::const_siterator const_siterator; - typedef typename Container::bucket_type bucket_type; + <typename BucketValueTraits::value_traits::value_type, IsConst>::type & + > iterator_traits; + + typedef typename BucketValueTraits::value_traits value_traits; + typedef typename BucketValueTraits::bucket_traits bucket_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename detail::get_slist_impl + <typename detail::reduced_slist_node_traits + <typename value_traits::node_traits>::type + >::type slist_impl; + typedef typename slist_impl::iterator siterator; + typedef typename slist_impl::const_iterator const_siterator; + typedef detail::bucket_impl<slist_impl> bucket_type; typedef typename pointer_traits - <typename Container::pointer>::template rebind_pointer - < const Container >::type const_cont_ptr; - typedef typename Container::size_type size_type; + <typename value_traits::pointer>::template rebind_pointer + < const BucketValueTraits >::type const_bucketvaltraits_ptr; + typedef typename slist_impl::size_type size_type; - static typename Container::node_ptr downcast_bucket(typename bucket_type::node_ptr p) + + static typename node_traits::node_ptr downcast_bucket(typename bucket_type::node_ptr p) { - return pointer_traits<typename Container::node_ptr>:: - pointer_to(static_cast<typename Container::node&>(*p)); + return pointer_traits<typename node_traits::node_ptr>:: + pointer_to(static_cast<typename node_traits::node&>(*p)); } public: - typedef typename Container::value_type value_type; - typedef typename detail::add_const_if_c - <typename Container::value_type, IsConst>::type *pointer; - typedef typename detail::add_const_if_c - <typename Container::value_type, IsConst>::type &reference; + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::pointer pointer; + typedef typename iterator_traits::reference reference; + typedef typename iterator_traits::iterator_category iterator_category; hashtable_iterator () + : slist_it_() //Value initialization to achieve "null iterators" (N3644) {} - explicit hashtable_iterator(siterator ptr, const Container *cont) - : slist_it_ (ptr), cont_ (cont ? pointer_traits<const_cont_ptr>::pointer_to(*cont) : const_cont_ptr() ) + explicit hashtable_iterator(siterator ptr, const BucketValueTraits *cont) + : slist_it_ (ptr), traitsptr_ (cont ? pointer_traits<const_bucketvaltraits_ptr>::pointer_to(*cont) : const_bucketvaltraits_ptr() ) {} - hashtable_iterator(const hashtable_iterator<Container, false> &other) - : slist_it_(other.slist_it()), cont_(other.get_container()) + hashtable_iterator(const hashtable_iterator<BucketValueTraits, false> &other) + : slist_it_(other.slist_it()), traitsptr_(other.get_bucket_value_traits()) {} const siterator &slist_it() const { return slist_it_; } - hashtable_iterator<Container, false> unconst() const - { return hashtable_iterator<Container, false>(this->slist_it(), this->get_container()); } + hashtable_iterator<BucketValueTraits, false> unconst() const + { return hashtable_iterator<BucketValueTraits, false>(this->slist_it(), this->get_bucket_value_traits()); } public: hashtable_iterator& operator++() @@ -201,48 +230,57 @@ class hashtable_iterator pointer operator->() const { - return boost::intrusive::detail::to_raw_pointer(this->get_real_value_traits()->to_value_ptr + return boost::intrusive::detail::to_raw_pointer(this->priv_value_traits().to_value_ptr (downcast_bucket(slist_it_.pointed_node()))); } - const const_cont_ptr &get_container() const - { return cont_; } + const const_bucketvaltraits_ptr &get_bucket_value_traits() const + { return traitsptr_; } + + const value_traits &priv_value_traits() const + { return traitsptr_->priv_value_traits(); } - const real_value_traits *get_real_value_traits() const - { return &this->get_container()->get_real_value_traits(); } + const bucket_traits &priv_bucket_traits() const + { return traitsptr_->priv_bucket_traits(); } private: void increment() { - const Container *cont = boost::intrusive::detail::to_raw_pointer(cont_); - bucket_type* buckets = boost::intrusive::detail::to_raw_pointer(cont->bucket_pointer()); - size_type buckets_len = cont->bucket_count(); + const bucket_traits &rbuck_traits = this->priv_bucket_traits(); + bucket_type* const buckets = boost::intrusive::detail::to_raw_pointer(rbuck_traits.bucket_begin()); + const size_type buckets_len = rbuck_traits.bucket_count(); ++slist_it_; - if(buckets[0].cend().pointed_node() <= slist_it_.pointed_node() && - slist_it_.pointed_node()<= buckets[buckets_len].cend().pointed_node() ){ - //Now get the bucket_impl from the iterator + const typename slist_impl::node_ptr n = slist_it_.pointed_node(); + const siterator first_bucket_bbegin = buckets->end(); + if(first_bucket_bbegin.pointed_node() <= n && n <= buckets[buckets_len-1].cend().pointed_node()){ + //If one-past the node is inside the bucket then look for the next non-empty bucket + //1. get the bucket_impl from the iterator const bucket_type &b = static_cast<const bucket_type&> (bucket_type::slist_type::container_from_end_iterator(slist_it_)); - //Now just calculate the index b has in the bucket array - size_type n_bucket = static_cast<size_type>(&b - &buckets[0]); + //2. Now just calculate the index b has in the bucket array + size_type n_bucket = static_cast<size_type>(&b - buckets); + + //3. Iterate until a non-empty bucket is found do{ - if (++n_bucket == buckets_len){ - slist_it_ = (&buckets[0] + buckets_len)->end(); - break; + if (++n_bucket >= buckets_len){ //bucket overflow, return end() iterator + slist_it_ = buckets->before_begin(); + return; } - slist_it_ = buckets[n_bucket].begin(); } - while (slist_it_ == buckets[n_bucket].end()); + while (buckets[n_bucket].empty()); + slist_it_ = buckets[n_bucket].begin(); + } + else{ + //++slist_it_ yield to a valid object } } - siterator slist_it_; - const_cont_ptr cont_; + siterator slist_it_; + const_bucketvaltraits_ptr traitsptr_; }; -} //namespace detail { } //namespace intrusive { } //namespace boost { diff --git a/boost/intrusive/detail/hook_traits.hpp b/boost/intrusive/detail/hook_traits.hpp new file mode 100644 index 0000000000..c9c115b1de --- /dev/null +++ b/boost/intrusive/detail/hook_traits.hpp @@ -0,0 +1,182 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP +#define BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/parent_from_member.hpp> +#include <boost/intrusive/link_mode.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/to_raw_pointer.hpp> +#include <boost/intrusive/detail/node_holder.hpp> + +namespace boost { +namespace intrusive { + +template<class T, class NodePtr, class Tag, unsigned int Type> +struct bhtraits_base +{ + public: + typedef NodePtr node_ptr; + typedef typename pointer_traits<node_ptr>::element_type node; + typedef node_holder<node, Tag, Type> node_holder_type; + typedef T value_type; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<const node>::type const_node_ptr; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<T>::type pointer; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<const T>::type const_pointer; + //typedef typename pointer_traits<pointer>::reference reference; + //typedef typename pointer_traits<const_pointer>::reference const_reference; + typedef T & reference; + typedef const T & const_reference; + typedef node_holder_type & node_holder_reference; + typedef const node_holder_type & const_node_holder_reference; + typedef node& node_reference; + typedef const node & const_node_reference; + + static pointer to_value_ptr(const node_ptr & n) + { + return pointer_traits<pointer>::pointer_to + (static_cast<reference>(static_cast<node_holder_reference>(*n))); + } + + static const_pointer to_value_ptr(const const_node_ptr & n) + { + return pointer_traits<const_pointer>::pointer_to + (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n))); + } + + static node_ptr to_node_ptr(reference value) + { + return pointer_traits<node_ptr>::pointer_to + (static_cast<node_reference>(static_cast<node_holder_reference>(value))); + } + + static const_node_ptr to_node_ptr(const_reference value) + { + return pointer_traits<const_node_ptr>::pointer_to + (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value))); + } +}; + +template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, unsigned int Type> +struct bhtraits + : public bhtraits_base<T, typename NodeTraits::node_ptr, Tag, Type> +{ + static const link_mode_type link_mode = LinkMode; + typedef NodeTraits node_traits; +}; + + +template<class T, class Hook, Hook T::* P> +struct mhtraits +{ + public: + typedef Hook hook_type; + typedef typename hook_type::hooktags::node_traits node_traits; + typedef typename node_traits::node node; + typedef T value_type; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<T>::type pointer; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<const T>::type const_pointer; + typedef T & reference; + typedef const T & const_reference; + typedef node& node_reference; + typedef const node & const_node_reference; + typedef hook_type& hook_reference; + typedef const hook_type & const_hook_reference; + + static const link_mode_type link_mode = Hook::hooktags::link_mode; + + static node_ptr to_node_ptr(reference value) + { + return pointer_traits<node_ptr>::pointer_to + (static_cast<node_reference>(static_cast<hook_reference>(value.*P))); + } + + static const_node_ptr to_node_ptr(const_reference value) + { + return pointer_traits<const_node_ptr>::pointer_to + (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P))); + } + + static pointer to_value_ptr(const node_ptr & n) + { + return pointer_traits<pointer>::pointer_to + (*detail::parent_from_member<T, Hook> + (static_cast<Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P)); + } + + static const_pointer to_value_ptr(const const_node_ptr & n) + { + return pointer_traits<const_pointer>::pointer_to + (*detail::parent_from_member<T, Hook> + (static_cast<const Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P)); + } +}; + + +template<class Functor> +struct fhtraits +{ + public: + typedef typename Functor::hook_type hook_type; + typedef typename Functor::hook_ptr hook_ptr; + typedef typename Functor::const_hook_ptr const_hook_ptr; + typedef typename hook_type::hooktags::node_traits node_traits; + typedef typename node_traits::node node; + typedef typename Functor::value_type value_type; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::const_node_ptr const_node_ptr; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<value_type>::type pointer; + typedef typename pointer_traits<node_ptr>:: + template rebind_pointer<const value_type>::type const_pointer; + typedef value_type & reference; + typedef const value_type & const_reference; + static const link_mode_type link_mode = hook_type::hooktags::link_mode; + + static node_ptr to_node_ptr(reference value) + { return static_cast<node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } + + static const_node_ptr to_node_ptr(const_reference value) + { return static_cast<const node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } + + static pointer to_value_ptr(const node_ptr & n) + { return Functor::to_value_ptr(to_hook_ptr(n)); } + + static const_pointer to_value_ptr(const const_node_ptr & n) + { return Functor::to_value_ptr(to_hook_ptr(n)); } + + private: + static hook_ptr to_hook_ptr(const node_ptr & n) + { return hook_ptr(&*static_cast<hook_type*>(&*n)); } + + static const_hook_ptr to_hook_ptr(const const_node_ptr & n) + { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); } +}; + + +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_DETAIL_HOOK_TRAITS_HPP diff --git a/boost/intrusive/detail/iiterator.hpp b/boost/intrusive/detail/iiterator.hpp new file mode 100644 index 0000000000..8378ead6ad --- /dev/null +++ b/boost/intrusive/detail/iiterator.hpp @@ -0,0 +1,227 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP +#define BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> +#include <boost/intrusive/detail/std_fwd.hpp> + +#include <cstddef> + + +namespace boost { +namespace intrusive { + +template<class Category, class T, class Distance, class Pointer, class Reference> +struct iterator +{ + typedef Category iterator_category; + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; +}; + +template<class Iterator> +struct iterator_traits +{ + typedef typename Iterator::difference_type difference_type; + typedef typename Iterator::value_type value_type; + typedef typename Iterator::pointer pointer; + typedef typename Iterator::reference reference; + typedef typename Iterator::iterator_category iterator_category; +}; + +template<class T> +struct iterator_traits<T*> +{ + typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef std::random_access_iterator_tag iterator_category; +}; + +template<class T> +struct iterator_traits<const T*> +{ + typedef std::ptrdiff_t difference_type; + typedef T value_type; + typedef const T* pointer; + typedef const T& reference; + typedef std::random_access_iterator_tag iterator_category; +}; + +template<class ValueTraits> +struct value_traits_pointers +{ + typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT + (boost::intrusive::detail:: + , ValueTraits, value_traits_ptr + , typename pointer_traits<typename ValueTraits::node_traits::node_ptr>::template + rebind_pointer<ValueTraits>::type) value_traits_ptr; + + typedef typename pointer_traits<value_traits_ptr>::template + rebind_pointer<ValueTraits const>::type const_value_traits_ptr; +}; + +template<class ValueTraits, bool IsConst, class Category> +struct iiterator +{ + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::node node; + typedef typename node_traits::node_ptr node_ptr; + typedef ::boost::intrusive::pointer_traits<node_ptr> nodepointer_traits_t; + typedef typename nodepointer_traits_t::template + rebind_pointer<void>::type void_pointer; + typedef typename ValueTraits::value_type value_type; + typedef typename ValueTraits::pointer nonconst_pointer; + typedef typename ValueTraits::const_pointer yesconst_pointer; + typedef typename ::boost::intrusive::pointer_traits + <nonconst_pointer>::reference nonconst_reference; + typedef typename ::boost::intrusive::pointer_traits + <yesconst_pointer>::reference yesconst_reference; + typedef typename nodepointer_traits_t::difference_type difference_type; + typedef typename detail::if_c + <IsConst, yesconst_pointer, nonconst_pointer>::type pointer; + typedef typename detail::if_c + <IsConst, yesconst_reference, nonconst_reference>::type reference; + typedef iterator + < Category + , value_type + , difference_type + , pointer + , reference + > iterator_traits; + typedef typename value_traits_pointers + <ValueTraits>::value_traits_ptr value_traits_ptr; + typedef typename value_traits_pointers + <ValueTraits>::const_value_traits_ptr const_value_traits_ptr; + static const bool stateful_value_traits = + detail::is_stateful_value_traits<value_traits>::value; +}; + +template<class NodePtr, class StoredPointer, bool StatefulValueTraits = true> +struct iiterator_members +{ + + iiterator_members() + : nodeptr_()//Value initialization to achieve "null iterators" (N3644) + {} + + iiterator_members(const NodePtr &n_ptr, const StoredPointer &data) + : nodeptr_(n_ptr), ptr_(data) + {} + + StoredPointer get_ptr() const + { return ptr_; } + + NodePtr nodeptr_; + StoredPointer ptr_; +}; + +template<class NodePtr, class StoredPointer> +struct iiterator_members<NodePtr, StoredPointer, false> +{ + iiterator_members() + : nodeptr_()//Value initialization to achieve "null iterators" (N3644) + {} + + iiterator_members(const NodePtr &n_ptr, const StoredPointer &) + : nodeptr_(n_ptr) + {} + + StoredPointer get_ptr() const + { return StoredPointer(); } + + NodePtr nodeptr_; +}; + +namespace detail { + +template<class InputIt, class Distance> inline +void advance_impl(InputIt& it, Distance n, const std::input_iterator_tag&) +{ + while(n--) + ++it; +} + +template<class InputIt, class Distance> inline +void advance_impl(InputIt& it, Distance n, std::forward_iterator_tag &) +{ + while(n--) + ++it; +} + +template<class InputIt, class Distance> inline +void advance_impl(InputIt& it, Distance n, std::bidirectional_iterator_tag &) +{ + for (; 0 < n; --n) + ++it; + for (; n < 0; ++n) + --it; +} + +template<class InputIt, class Distance> +inline void advance_impl(InputIt& it, Distance n, const std::random_access_iterator_tag &) +{ + it += n; +} + +} //namespace detail + +template<class InputIt, class Distance> +inline void iterator_advance(InputIt& it, Distance n) +{ // increment iterator by offset, arbitrary iterators + boost::intrusive::detail::advance_impl(it, n, boost::intrusive::iterator_traits<InputIt>::iterator_category()); +} + +namespace detail{ + +template<class InputIt, class Distance, class Category> +inline void distance_impl(InputIt first, InputIt last, Distance& off, const Category &) +{ + while(first != last){ + ++off; + ++first; + } +} + +template<class InputIt, class Distance> inline +void distance_impl(InputIt first, InputIt last, Distance& off, const std::random_access_iterator_tag&) +{ + off += last - first; +} + +} //namespace detail + +template<class InputIt> inline +typename iterator_traits<InputIt>::difference_type iterator_distance(InputIt first, InputIt last) +{ + typename iterator_traits<InputIt>::difference_type off = 0; + boost::intrusive::detail::distance_impl(first, last, off, boost::intrusive::iterator_traits<InputIt>::iterator_category()); + return off; +} + + +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_DETAIL_IITERATOR_HPP diff --git a/boost/intrusive/detail/is_stateful_value_traits.hpp b/boost/intrusive/detail/is_stateful_value_traits.hpp index 8677c666d4..da2260edf6 100644 --- a/boost/intrusive/detail/is_stateful_value_traits.hpp +++ b/boost/intrusive/detail/is_stateful_value_traits.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2009-2012. +// (C) Copyright Ion Gaztanaga 2009-2013. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,7 +13,9 @@ #ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP #define BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP -#include <boost/intrusive/detail/config_begin.hpp> +#if defined(_MSC_VER) +# pragma once +#endif #if defined(_MSC_VER) && (_MSC_VER <= 1310) @@ -72,6 +74,4 @@ struct is_stateful_value_traits #endif -#include <boost/intrusive/detail/config_end.hpp> - #endif //@ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP diff --git a/boost/intrusive/detail/key_nodeptr_comp.hpp b/boost/intrusive/detail/key_nodeptr_comp.hpp new file mode 100644 index 0000000000..dfee8b9bfc --- /dev/null +++ b/boost/intrusive/detail/key_nodeptr_comp.hpp @@ -0,0 +1,72 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP +#define BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/ebo_functor_holder.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template<class KeyValueCompare, class ValueTraits> +struct key_nodeptr_comp + : private ebo_functor_holder<KeyValueCompare> +{ + typedef ValueTraits value_traits; + typedef typename value_traits::value_type value_type; + typedef typename value_traits::node_ptr node_ptr; + typedef typename value_traits::const_node_ptr const_node_ptr; + typedef ebo_functor_holder<KeyValueCompare> base_t; + + key_nodeptr_comp(KeyValueCompare kcomp, const ValueTraits *traits) + : base_t(kcomp), traits_(traits) + {} + + template<class T> + struct is_node_ptr + { + static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value; + }; + + template<class T> + const value_type & key_forward + (const T &node, typename enable_if_c<is_node_ptr<T>::value>::type * = 0) const + { return *traits_->to_value_ptr(node); } + + template<class T> + const T & key_forward(const T &key, typename enable_if_c<!is_node_ptr<T>::value>::type* = 0) const + { return key; } + + + template<class KeyType, class KeyType2> + bool operator()(const KeyType &key1, const KeyType2 &key2) const + { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); } + + template<class KeyType> + bool operator()(const KeyType &key1) const + { return base_t::get()(this->key_forward(key1)); } + + const ValueTraits *const traits_; +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP diff --git a/boost/intrusive/detail/list_iterator.hpp b/boost/intrusive/detail/list_iterator.hpp new file mode 100644 index 0000000000..efddfba3f1 --- /dev/null +++ b/boost/intrusive/detail/list_iterator.hpp @@ -0,0 +1,129 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (C) Copyright Ion Gaztanaga 2006-2013 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_LIST_ITERATOR_HPP +#define BOOST_INTRUSIVE_LIST_ITERATOR_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/std_fwd.hpp> +#include <boost/intrusive/detail/iiterator.hpp> +#include <boost/intrusive/detail/mpl.hpp> + +namespace boost { +namespace intrusive { + +// list_iterator provides some basic functions for a +// node oriented bidirectional iterator: +template<class ValueTraits, bool IsConst> +class list_iterator +{ + protected: + typedef iiterator + <ValueTraits, IsConst, std::bidirectional_iterator_tag> types_t; + + static const bool stateful_value_traits = types_t::stateful_value_traits; + + typedef ValueTraits value_traits; + typedef typename types_t::node_traits node_traits; + + typedef typename types_t::node node; + typedef typename types_t::node_ptr node_ptr; + typedef typename types_t::const_value_traits_ptr const_value_traits_ptr; + + public: + typedef typename types_t::iterator_traits::difference_type difference_type; + typedef typename types_t::iterator_traits::value_type value_type; + typedef typename types_t::iterator_traits::pointer pointer; + typedef typename types_t::iterator_traits::reference reference; + typedef typename types_t::iterator_traits::iterator_category iterator_category; + + list_iterator() + {} + + explicit list_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr) + : members_(nodeptr, traits_ptr) + {} + + list_iterator(list_iterator<ValueTraits, false> const& other) + : members_(other.pointed_node(), other.get_value_traits()) + {} + + const node_ptr &pointed_node() const + { return members_.nodeptr_; } + + list_iterator &operator=(const node_ptr &node) + { members_.nodeptr_ = node; return static_cast<list_iterator&>(*this); } + + const_value_traits_ptr get_value_traits() const + { return members_.get_ptr(); } + + public: + list_iterator& operator++() + { + node_ptr p = node_traits::get_next(members_.nodeptr_); + members_.nodeptr_ = p; + return static_cast<list_iterator&> (*this); + } + + list_iterator operator++(int) + { + list_iterator result (*this); + members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); + return result; + } + + list_iterator& operator--() + { + members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_); + return static_cast<list_iterator&> (*this); + } + + list_iterator operator--(int) + { + list_iterator result (*this); + members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_); + return result; + } + + friend bool operator== (const list_iterator& l, const list_iterator& r) + { return l.pointed_node() == r.pointed_node(); } + + friend bool operator!= (const list_iterator& l, const list_iterator& r) + { return !(l == r); } + + reference operator*() const + { return *operator->(); } + + pointer operator->() const + { return this->operator_arrow(detail::bool_<stateful_value_traits>()); } + + list_iterator<ValueTraits, false> unconst() const + { return list_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); } + + private: + pointer operator_arrow(detail::false_) const + { return ValueTraits::to_value_ptr(members_.nodeptr_); } + + pointer operator_arrow(detail::true_) const + { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); } + + iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_; +}; + +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_LIST_ITERATOR_HPP diff --git a/boost/intrusive/detail/list_node.hpp b/boost/intrusive/detail/list_node.hpp index d406af60e4..ba97ece956 100644 --- a/boost/intrusive/detail/list_node.hpp +++ b/boost/intrusive/detail/list_node.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,10 +14,11 @@ #ifndef BOOST_INTRUSIVE_LIST_NODE_HPP #define BOOST_INTRUSIVE_LIST_NODE_HPP -#include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_rebind.hpp> namespace boost { namespace intrusive { @@ -29,8 +30,7 @@ namespace intrusive { template<class VoidPointer> struct list_node { - typedef typename pointer_traits - <VoidPointer>:: template rebind_pointer<list_node>::type node_ptr; + typedef typename pointer_rebind<VoidPointer, list_node>::type node_ptr; node_ptr next_; node_ptr prev_; }; @@ -38,153 +38,30 @@ struct list_node template<class VoidPointer> struct list_node_traits { - typedef list_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>:: template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>:: template rebind_pointer<const node>::type const_node_ptr; + typedef list_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr; + + static node_ptr get_previous(const const_node_ptr & n) + { return n->prev_; } - static const node_ptr &get_previous(const const_node_ptr & n) + static node_ptr get_previous(const node_ptr & n) { return n->prev_; } static void set_previous(const node_ptr & n, const node_ptr & prev) { n->prev_ = prev; } - static const node_ptr &get_next(const const_node_ptr & n) + static node_ptr get_next(const const_node_ptr & n) + { return n->next_; } + + static node_ptr get_next(const node_ptr & n) { return n->next_; } static void set_next(const node_ptr & n, const node_ptr & next) { n->next_ = next; } }; -// list_iterator provides some basic functions for a -// node oriented bidirectional iterator: -template<class Container, bool IsConst> -class list_iterator - : public std::iterator - < std::bidirectional_iterator_tag - , typename Container::value_type - , typename Container::difference_type - , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type - , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type - > -{ - protected: - typedef typename Container::real_value_traits real_value_traits; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename node_traits::node_ptr node_ptr; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<void>::type void_pointer; - static const bool store_container_ptr = - detail::store_cont_ptr_on_it<Container>::value; - - public: - typedef typename Container::value_type value_type; - typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer; - typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference; - - list_iterator() - : members_ (node_ptr(), 0) - {} - - explicit list_iterator(const node_ptr & node, const Container *cont_ptr) - : members_ (node, cont_ptr) - {} - - list_iterator(list_iterator<Container, false> const& other) - : members_(other.pointed_node(), other.get_container()) - {} - - const node_ptr &pointed_node() const - { return members_.nodeptr_; } - - list_iterator &operator=(const node_ptr &node) - { members_.nodeptr_ = node; return static_cast<list_iterator&>(*this); } - - public: - list_iterator& operator++() - { - node_ptr p = node_traits::get_next(members_.nodeptr_); - members_.nodeptr_ = p; - //members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); - return static_cast<list_iterator&> (*this); - } - - list_iterator operator++(int) - { - list_iterator result (*this); - members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); - return result; - } - - list_iterator& operator--() - { - members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_); - return static_cast<list_iterator&> (*this); - } - - list_iterator operator--(int) - { - list_iterator result (*this); - members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_); - return result; - } - - friend bool operator== (const list_iterator& l, const list_iterator& r) - { return l.pointed_node() == r.pointed_node(); } - - friend bool operator!= (const list_iterator& l, const list_iterator& r) - { return !(l == r); } - - reference operator*() const - { return *operator->(); } - - pointer operator->() const - { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); } - - const Container *get_container() const - { - if(store_container_ptr){ - const Container* c = static_cast<const Container*>(members_.get_ptr()); - BOOST_INTRUSIVE_INVARIANT_ASSERT(c != 0); - return c; - } - else{ - return 0; - } - } - - const real_value_traits *get_real_value_traits() const - { - if(store_container_ptr) - return &this->get_container()->get_real_value_traits(); - else - return 0; - } - - list_iterator<Container, false> unconst() const - { return list_iterator<Container, false>(this->pointed_node(), this->get_container()); } - - private: - struct members - : public detail::select_constptr - <void_pointer, store_container_ptr>::type - { - typedef typename detail::select_constptr - <void_pointer, store_container_ptr>::type Base; - - members(const node_ptr &n_ptr, const void *cont) - : Base(cont), nodeptr_(n_ptr) - {} - - node_ptr nodeptr_; - } members_; -}; - } //namespace intrusive } //namespace boost -#include <boost/intrusive/detail/config_end.hpp> - #endif //BOOST_INTRUSIVE_LIST_NODE_HPP diff --git a/boost/intrusive/detail/math.hpp b/boost/intrusive/detail/math.hpp new file mode 100644 index 0000000000..f212ae743f --- /dev/null +++ b/boost/intrusive/detail/math.hpp @@ -0,0 +1,271 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_MATH_HPP +#define BOOST_INTRUSIVE_DETAIL_MATH_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <cstddef> +#include <climits> + +namespace boost { +namespace intrusive { +namespace detail { + +/////////////////////////// +// floor_log2 Dispatcher +//////////////////////////// + +#if defined(_MSC_VER) && (_MSC_VER >= 1300) + + }}} //namespace boost::intrusive::detail + + //Use _BitScanReverseXX intrinsics + + #if defined(_M_X64) || defined(_M_AMD64) || defined(_M_IA64) //64 bit target + #define BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT + #endif + + #ifndef __INTRIN_H_ // Avoid including any windows system header + #ifdef __cplusplus + extern "C" { + #endif // __cplusplus + + #if defined(BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT) //64 bit target + unsigned char _BitScanReverse64(unsigned long *index, unsigned __int64 mask); + #pragma intrinsic(_BitScanReverse64) + #else //32 bit target + unsigned char _BitScanReverse(unsigned long *index, unsigned long mask); + #pragma intrinsic(_BitScanReverse) + #endif + + #ifdef __cplusplus + } + #endif // __cplusplus + #endif // __INTRIN_H_ + + #ifdef BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT + #define BOOST_INTRUSIVE_BSR_INTRINSIC _BitScanReverse64 + #undef BOOST_INTRUSIVE_BSR_INTRINSIC_64_BIT + #else + #define BOOST_INTRUSIVE_BSR_INTRINSIC _BitScanReverse + #endif + + namespace boost { + namespace intrusive { + namespace detail { + + inline std::size_t floor_log2 (std::size_t x) + { + unsigned long log2; + BOOST_INTRUSIVE_BSR_INTRINSIC( &log2, (unsigned long)x ); + return log2; + } + + #undef BOOST_INTRUSIVE_BSR_INTRINSIC + +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) //GCC >=3.4 + + //Compile-time error in case of missing specialization + template<class Uint> + struct builtin_clz_dispatch; + + #if defined(BOOST_HAS_LONG_LONG) + template<> + struct builtin_clz_dispatch<unsigned long long> + { + static unsigned long long call(unsigned long long n) + { return __builtin_clzll(n); } + }; + #endif + + template<> + struct builtin_clz_dispatch<unsigned long> + { + static unsigned long call(unsigned long n) + { return __builtin_clzl(n); } + }; + + template<> + struct builtin_clz_dispatch<unsigned int> + { + static unsigned int call(unsigned int n) + { return __builtin_clz(n); } + }; + + inline std::size_t floor_log2(std::size_t n) + { + return sizeof(std::size_t)*CHAR_BIT - std::size_t(1) - builtin_clz_dispatch<std::size_t>::call(n); + } + +#else //Portable methods + +//////////////////////////// +// Generic method +//////////////////////////// + + inline std::size_t floor_log2_get_shift(std::size_t n, true_ )//power of two size_t + { return n >> 1; } + + inline std::size_t floor_log2_get_shift(std::size_t n, false_ )//non-power of two size_t + { return (n >> 1) + ((n & 1u) & (n != 1)); } + + template<std::size_t N> + inline std::size_t floor_log2 (std::size_t x, integer<std::size_t, N>) + { + const std::size_t Bits = N; + const bool Size_t_Bits_Power_2= !(Bits & (Bits-1)); + + std::size_t n = x; + std::size_t log2 = 0; + + std::size_t remaining_bits = Bits; + std::size_t shift = floor_log2_get_shift(remaining_bits, bool_<Size_t_Bits_Power_2>()); + while(shift){ + std::size_t tmp = n >> shift; + if (tmp){ + log2 += shift, n = tmp; + } + shift = floor_log2_get_shift(shift, bool_<Size_t_Bits_Power_2>()); + } + + return log2; + } + + //////////////////////////// + // DeBruijn method + //////////////////////////// + + //Taken from: + //http://stackoverflow.com/questions/11376288/fast-computing-of-log2-for-64-bit-integers + //Thanks to Desmond Hume + + inline std::size_t floor_log2 (std::size_t v, integer<std::size_t, 32>) + { + static const int MultiplyDeBruijnBitPosition[32] = + { + 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, + 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 + }; + + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + + return MultiplyDeBruijnBitPosition[(std::size_t)(v * 0x07C4ACDDU) >> 27]; + } + + inline std::size_t floor_log2 (std::size_t v, integer<std::size_t, 64>) + { + static const std::size_t MultiplyDeBruijnBitPosition[64] = { + 63, 0, 58, 1, 59, 47, 53, 2, + 60, 39, 48, 27, 54, 33, 42, 3, + 61, 51, 37, 40, 49, 18, 28, 20, + 55, 30, 34, 11, 43, 14, 22, 4, + 62, 57, 46, 52, 38, 26, 32, 41, + 50, 36, 17, 19, 29, 10, 13, 21, + 56, 45, 25, 31, 35, 16, 9, 12, + 44, 24, 15, 8, 23, 7, 6, 5}; + + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + return MultiplyDeBruijnBitPosition[((std::size_t)((v - (v >> 1))*0x07EDD5E59A4E28C2ULL)) >> 58]; + } + + + inline std::size_t floor_log2 (std::size_t x) + { + const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT; + return floor_log2(x, integer<std::size_t, Bits>()); + } + +#endif + +//Thanks to Laurent de Soras in +//http://www.flipcode.com/archives/Fast_log_Function.shtml +inline float fast_log2 (float val) +{ + union caster_t + { + unsigned x; + float val; + } caster; + + caster.val = val; + unsigned x = caster.x; + const int log_2 = int((x >> 23) & 255) - 128; + x &= ~(unsigned(255u) << 23u); + x += unsigned(127) << 23u; + caster.x = x; + val = caster.val; + //1+log2(m), m ranging from 1 to 2 + //3rd degree polynomial keeping first derivate continuity. + //For less precision the line can be commented out + val = ((-1.f/3.f) * val + 2.f) * val - (2.f/3.f); + return val + static_cast<float>(log_2); +} + +inline std::size_t ceil_log2 (std::size_t x) +{ + return static_cast<std::size_t>((x & (x-1)) != 0) + floor_log2(x); +} + +template<class SizeType, std::size_t N> +struct numbits_eq +{ + static const bool value = sizeof(SizeType)*CHAR_BIT == N; +}; + +template<class SizeType, class Enabler = void > +struct sqrt2_pow_max; + +template <class SizeType> +struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 32> >::type> +{ + static const SizeType value = 0xb504f334; + static const std::size_t pow = 31; +}; + +#ifndef BOOST_NO_INT64_T + +template <class SizeType> +struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 64> >::type> +{ + static const SizeType value = 0xb504f333f9de6484ull; + static const std::size_t pow = 63; +}; + +#endif //BOOST_NO_INT64_T + +// Returns floor(pow(sqrt(2), x * 2 + 1)). +// Defined for X from 0 up to the number of bits in size_t minus 1. +inline std::size_t sqrt2_pow_2xplus1 (std::size_t x) +{ + const std::size_t value = (std::size_t)sqrt2_pow_max<std::size_t>::value; + const std::size_t pow = (std::size_t)sqrt2_pow_max<std::size_t>::pow; + return (value >> (pow - x)) + 1; +} + +} //namespace detail +} //namespace intrusive +} //namespace boost + +#endif //BOOST_INTRUSIVE_DETAIL_MATH_HPP diff --git a/boost/intrusive/detail/memory_util.hpp b/boost/intrusive/detail/memory_util.hpp index 1a6431b078..18a5d3e7e2 100644 --- a/boost/intrusive/detail/memory_util.hpp +++ b/boost/intrusive/detail/memory_util.hpp @@ -6,7 +6,7 @@ // ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2011-2014. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -17,14 +17,14 @@ #ifndef BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP #define BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP -#if (defined _MSC_VER) && (_MSC_VER >= 1200) +#if defined(_MSC_VER) # pragma once #endif -#include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/detail/workaround.hpp> #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/detail/preprocessor.hpp> +#include <boost/preprocessor/iteration/iterate.hpp> namespace boost { namespace intrusive { @@ -41,10 +41,6 @@ inline T* addressof(T& obj) ); } -template <typename T> struct unvoid { typedef T type; }; -template <> struct unvoid<void> { struct type { }; }; -template <> struct unvoid<const void> { struct type { }; }; - template <typename T> struct LowPriorityConversion { @@ -52,61 +48,6 @@ struct LowPriorityConversion LowPriorityConversion(const T&) { } }; -// Infrastructure for providing a default type for T::TNAME if absent. -#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \ - template <typename T, typename DefaultType> \ - struct boost_intrusive_default_type_ ## TNAME \ - { \ - template <typename X> \ - static char test(int, typename X::TNAME*); \ - \ - template <typename X> \ - static int test(boost::intrusive::detail:: \ - LowPriorityConversion<int>, void*); \ - \ - struct DefaultWrap { typedef DefaultType TNAME; }; \ - \ - static const bool value = (1 == sizeof(test<T>(0, 0))); \ - \ - typedef typename \ - ::boost::intrusive::detail::if_c \ - <value, T, DefaultWrap>::type::TNAME type; \ - }; \ - \ - template <typename T, typename DefaultType> \ - struct boost_intrusive_eval_default_type_ ## TNAME \ - { \ - template <typename X> \ - static char test(int, typename X::TNAME*); \ - \ - template <typename X> \ - static int test(boost::intrusive::detail:: \ - LowPriorityConversion<int>, void*); \ - \ - struct DefaultWrap \ - { typedef typename DefaultType::type TNAME; }; \ - \ - static const bool value = (1 == sizeof(test<T>(0, 0))); \ - \ - typedef typename \ - ::boost::intrusive::detail::eval_if_c \ - < value \ - , ::boost::intrusive::detail::identity<T> \ - , ::boost::intrusive::detail::identity<DefaultWrap> \ - >::type::TNAME type; \ - }; \ -// - -#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ - typename INSTANTIATION_NS_PREFIX \ - boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \ -// - -#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ - typename INSTANTIATION_NS_PREFIX \ - boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \ -// - }}} //namespace boost::intrusive::detail #include <boost/intrusive/detail/has_member_function_callable_with.hpp> @@ -114,25 +55,25 @@ struct LowPriorityConversion #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME pointer_to #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) +#define BOOST_PP_ITERATION_PARAMS_1 (3, (1, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) #include BOOST_PP_ITERATE() #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME static_cast_from #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) +#define BOOST_PP_ITERATION_PARAMS_1 (3, (1, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) #include BOOST_PP_ITERATE() #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME const_cast_from #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) +#define BOOST_PP_ITERATION_PARAMS_1 (3, (1, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) #include BOOST_PP_ITERATE() #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_FUNCNAME dynamic_cast_from #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_BEGIN namespace boost { namespace intrusive { namespace detail { #define BOOST_INTRUSIVE_HAS_MEMBER_FUNCTION_CALLABLE_WITH_NS_END }}} -#define BOOST_PP_ITERATION_PARAMS_1 (3, (0, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) +#define BOOST_PP_ITERATION_PARAMS_1 (3, (1, 1, <boost/intrusive/detail/has_member_function_callable_with.hpp>)) #include BOOST_PP_ITERATE() namespace boost { @@ -141,148 +82,11 @@ namespace detail { BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(element_type) BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(difference_type) - -////////////////////// -//struct first_param -////////////////////// - -template <typename T> struct first_param -{ typedef void type; }; - -#if !defined(BOOST_NO_VARIADIC_TEMPLATES) - - template <template <typename, typename...> class TemplateClass, typename T, typename... Args> - struct first_param< TemplateClass<T, Args...> > - { - typedef T type; - }; - -#else //C++03 compilers - - #define BOOST_PP_LOCAL_MACRO(n) \ - template < template <typename \ - BOOST_PP_ENUM_TRAILING(n, BOOST_INTRUSIVE_PP_IDENTITY, typename) > \ - class TemplateClass \ - , typename T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)> \ - struct first_param \ - < TemplateClass<T BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> > \ - { \ - typedef T type; \ - }; \ - // - #define BOOST_PP_LOCAL_LIMITS (0, BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS) - #include BOOST_PP_LOCAL_ITERATE() - -#endif //!defined(BOOST_NO_VARIADIC_TEMPLATES) - -/////////////////////////// -//struct type_rebind_mode -/////////////////////////// -template <typename Ptr, typename T> -struct type_has_rebind -{ - template <typename X> - #if !defined (__SUNPRO_CC) - static char test(int, typename X::template rebind<T>*); - #else - static char test(int, typename X::rebind<T>*); - #endif - - template <typename X> - static int test(boost::intrusive::detail::LowPriorityConversion<int>, void*); - - static const bool value = (1 == sizeof(test<Ptr>(0, 0))); -}; - -template <typename Ptr, typename T> -struct type_has_rebind_other -{ - template <typename X> - #if !defined (__SUNPRO_CC) - static char test(int, typename X::template rebind<T>::other*); - #else - static char test(int, typename X::rebind<T>::other*); - #endif - - template <typename X> - static int test(boost::intrusive::detail::LowPriorityConversion<int>, void*); - - static const bool value = (1 == sizeof(test<Ptr>(0, 0))); -}; - -template <typename Ptr, typename T> -struct type_rebind_mode -{ - static const unsigned int rebind = (unsigned int)type_has_rebind<Ptr, T>::value; - static const unsigned int rebind_other = (unsigned int)type_has_rebind_other<Ptr, T>::value; - static const unsigned int mode = rebind + rebind*rebind_other; -}; - -//////////////////////// -//struct type_rebinder -//////////////////////// -template <typename Ptr, typename U, unsigned int RebindMode = type_rebind_mode<Ptr, U>::mode> -struct type_rebinder; - -// Implementation of pointer_traits<Ptr>::rebind if Ptr has -// its own rebind::other type (C++03) -template <typename Ptr, typename U> -struct type_rebinder< Ptr, U, 2u > -{ - typedef typename Ptr::template rebind<U>::other type; -}; - -// Implementation of pointer_traits<Ptr>::rebind if Ptr has -// its own rebind template. -template <typename Ptr, typename U> -struct type_rebinder< Ptr, U, 1u > -{ - typedef typename Ptr::template rebind<U> type; -}; - -// Specialization of pointer_traits<Ptr>::rebind if Ptr does not -// have its own rebind template but has a the form Ptr<class T, -// OtherArgs>, where OtherArgs comprises zero or more type parameters. -// Many pointers fit this form, hence many pointers will get a -// reasonable default for rebind. -#if !defined(BOOST_NO_VARIADIC_TEMPLATES) - -template <template <class, class...> class Ptr, typename T, class... Tn, class U> -struct type_rebinder<Ptr<T, Tn...>, U, 0u > -{ - typedef Ptr<U, Tn...> type; -}; - -//Needed for non-conforming compilers like GCC 4.3 -template <template <class> class Ptr, typename T, class U> -struct type_rebinder<Ptr<T>, U, 0u > -{ - typedef Ptr<U> type; -}; - -#else //C++03 compilers - -#define BOOST_PP_LOCAL_MACRO(n) \ -template < template <typename \ - BOOST_PP_ENUM_TRAILING(n, BOOST_INTRUSIVE_PP_IDENTITY, typename) > \ - class Ptr \ - , typename T BOOST_PP_ENUM_TRAILING_PARAMS(n, class P) \ - , class U> \ -struct type_rebinder \ - < Ptr<T BOOST_PP_ENUM_TRAILING_PARAMS(n, P)>, U, 0u > \ -{ \ - typedef Ptr<U BOOST_PP_ENUM_TRAILING_PARAMS(n, P)> type; \ -}; \ -// -#define BOOST_PP_LOCAL_LIMITS (0, BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS) -#include BOOST_PP_LOCAL_ITERATE() - -#endif //!defined(BOOST_NO_VARIADIC_TEMPLATES) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(reference) +BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(value_traits_ptr) } //namespace detail { } //namespace intrusive { } //namespace boost { -#include <boost/intrusive/detail/config_end.hpp> - #endif // ! defined(BOOST_INTRUSIVE_ALLOCATOR_MEMORY_UTIL_HPP) diff --git a/boost/intrusive/detail/mpl.hpp b/boost/intrusive/detail/mpl.hpp index 02b1361d2a..9b2c9f114c 100644 --- a/boost/intrusive/detail/mpl.hpp +++ b/boost/intrusive/detail/mpl.hpp @@ -1,6 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 +// (C) Copyright Microsoft Corporation 2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,6 +14,10 @@ #ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP #define BOOST_INTRUSIVE_DETAIL_MPL_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <cstddef> @@ -20,6 +25,76 @@ namespace boost { namespace intrusive { namespace detail { +template <typename T, typename U> +struct is_same +{ + static const bool value = false; +}; + +template <typename T> +struct is_same<T, T> +{ + static const bool value = true; +}; + +template<typename T> +struct add_const +{ typedef const T type; }; + +template<typename T> +struct remove_const +{ typedef T type; }; + +template<typename T> +struct remove_const<const T> +{ typedef T type; }; + +template<typename T> +struct remove_cv +{ typedef T type; }; + +template<typename T> +struct remove_cv<const T> +{ typedef T type; }; + +template<typename T> +struct remove_cv<const volatile T> +{ typedef T type; }; + +template<typename T> +struct remove_cv<volatile T> +{ typedef T type; }; + +template<class T> +struct remove_reference +{ + typedef T type; +}; + +template<class T> +struct remove_reference<T&> +{ + typedef T type; +}; + +template<class T> +struct remove_pointer +{ + typedef T type; +}; + +template<class T> +struct remove_pointer<T*> +{ + typedef T type; +}; + +template<class T> +struct add_pointer +{ + typedef T *type; +}; + typedef char one; struct two {one _[2];}; @@ -29,6 +104,12 @@ struct bool_ static const bool value = C_; }; +template< class Integer, Integer Value > +struct integer +{ + static const Integer value = Value; +}; + typedef bool_<true> true_; typedef bool_<false> false_; @@ -58,18 +139,32 @@ struct apply typedef typename F::template apply<Param>::type type; }; +#if defined(_MSC_VER) && (_MSC_VER >= 1400) + +template <class T, class U> +struct is_convertible +{ + static const bool value = __is_convertible_to(T, U); +}; + +#else + template <class T, class U> class is_convertible { typedef char true_t; class false_t { char dummy[2]; }; - static true_t dispatch(U); + //use any_conversion as first parameter since in MSVC + //overaligned types can't go through ellipsis static false_t dispatch(...); - static const T &trigger(); + static true_t dispatch(U); + static typename remove_reference<T>::type &trigger(); public: static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t); }; +#endif + template< bool C , typename T1 @@ -124,134 +219,16 @@ struct identity typedef T type; }; -#if defined(BOOST_MSVC) || defined(__BORLANDC_) -#define BOOST_INTRUSIVE_TT_DECL __cdecl -#else -#define BOOST_INTRUSIVE_TT_DECL -#endif - -#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(UNDER_CE) -#define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS -#endif - -template <typename T> -struct is_unary_or_binary_function_impl -{ static const bool value = false; }; - -// see boost ticket #4094 -// avoid duplicate definitions of is_unary_or_binary_function_impl -#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R> -struct is_unary_or_binary_function_impl<R (*)()> -{ static const bool value = true; }; - -template <typename R> -struct is_unary_or_binary_function_impl<R (*)(...)> -{ static const bool value = true; }; - -#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R> -struct is_unary_or_binary_function_impl<R (__stdcall*)()> -{ static const bool value = true; }; - -#ifndef _MANAGED - -template <typename R> -struct is_unary_or_binary_function_impl<R (__fastcall*)()> -{ static const bool value = true; }; - -#endif - -template <typename R> -struct is_unary_or_binary_function_impl<R (__cdecl*)()> -{ static const bool value = true; }; - -template <typename R> -struct is_unary_or_binary_function_impl<R (__cdecl*)(...)> -{ static const bool value = true; }; - -#endif - -// see boost ticket #4094 -// avoid duplicate definitions of is_unary_or_binary_function_impl -#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (*)(T0)> -{ static const bool value = true; }; - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (*)(T0...)> -{ static const bool value = true; }; - -#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)> -{ static const bool value = true; }; - -#ifndef _MANAGED - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)> -{ static const bool value = true; }; - -#endif - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)> -{ static const bool value = true; }; - -template <typename R, class T0> -struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)> -{ static const bool value = true; }; - -#endif - -// see boost ticket #4094 -// avoid duplicate definitions of is_unary_or_binary_function_impl -#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (*)(T0, T1)> -{ static const bool value = true; }; - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (*)(T0, T1...)> -{ static const bool value = true; }; - -#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)> -{ static const bool value = true; }; - -#ifndef _MANAGED - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)> -{ static const bool value = true; }; - -#endif - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)> -{ static const bool value = true; }; - -template <typename R, class T0, class T1> -struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)> -{ static const bool value = true; }; -#endif - -template <typename T> -struct is_unary_or_binary_function_impl<T&> -{ static const bool value = false; }; +template<class T, bool Add> +struct add_const_if_c +{ + typedef typename if_c + < Add + , typename add_const<T>::type + , T + >::type type; +}; -template<typename T> -struct is_unary_or_binary_function -{ static const bool value = is_unary_or_binary_function_impl<T>::value; }; //boost::alignment_of yields to 10K lines of preprocessed code, so we //need an alternative @@ -280,49 +257,6 @@ struct alignment_of >::value; }; -template <typename T, typename U> -struct is_same -{ - typedef char yes_type; - struct no_type - { - char padding[8]; - }; - - template <typename V> - static yes_type is_same_tester(V*, V*); - static no_type is_same_tester(...); - - static T *t; - static U *u; - - static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u)); -}; - -template<typename T> -struct add_const -{ typedef const T type; }; - -template<typename T> -struct remove_const -{ typedef T type; }; - -template<typename T> -struct remove_const<const T> -{ typedef T type; }; - -template<class T> -struct remove_reference -{ - typedef T type; -}; - -template<class T> -struct remove_reference<T&> -{ - typedef T type; -}; - template<class Class> class is_empty_class { @@ -358,6 +292,81 @@ struct ls_zeros<1> static const std::size_t value = 0; }; +template <typename T> struct unvoid_ref { typedef T &type; }; +template <> struct unvoid_ref<void> { struct type_impl { }; typedef type_impl & type; }; +template <> struct unvoid_ref<const void> { struct type_impl { }; typedef type_impl & type; }; + +// Infrastructure for providing a default type for T::TNAME if absent. +#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \ + template <typename T, typename DefaultType> \ + struct boost_intrusive_default_type_ ## TNAME \ + { \ + template <typename X> \ + static char test(int, typename X::TNAME*); \ + \ + template <typename X> \ + static int test(...); \ + \ + struct DefaultWrap { typedef DefaultType TNAME; }; \ + \ + static const bool value = (1 == sizeof(test<T>(0, 0))); \ + \ + typedef typename \ + ::boost::intrusive::detail::if_c \ + <value, T, DefaultWrap>::type::TNAME type; \ + }; \ + \ + template <typename T, typename DefaultType> \ + struct boost_intrusive_eval_default_type_ ## TNAME \ + { \ + template <typename X> \ + static char test(int, typename X::TNAME*); \ + \ + template <typename X> \ + static int test(...); \ + \ + struct DefaultWrap \ + { typedef typename DefaultType::type TNAME; }; \ + \ + static const bool value = (1 == sizeof(test<T>(0, 0))); \ + \ + typedef typename \ + ::boost::intrusive::detail::eval_if_c \ + < value \ + , ::boost::intrusive::detail::identity<T> \ + , ::boost::intrusive::detail::identity<DefaultWrap> \ + >::type::TNAME type; \ + }; \ +// + +#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ + typename INSTANTIATION_NS_PREFIX \ + boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \ +// + +#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \ + typename INSTANTIATION_NS_PREFIX \ + boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \ +// + +#define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \ +template <class T>\ +struct TRAITS_PREFIX##_bool\ +{\ + template<bool Add>\ + struct two_or_three {one _[2 + Add];};\ + template <class U> static one test(...);\ + template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\ + static const std::size_t value = sizeof(test<T>(0));\ +};\ +\ +template <class T>\ +struct TRAITS_PREFIX##_bool_is_true\ +{\ + static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(one)*2;\ +};\ +// + } //namespace detail } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/detail/node_cloner_disposer.hpp b/boost/intrusive/detail/node_cloner_disposer.hpp new file mode 100644 index 0000000000..2a18100205 --- /dev/null +++ b/boost/intrusive/detail/node_cloner_disposer.hpp @@ -0,0 +1,109 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP +#define BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/link_mode.hpp> +#include <boost/intrusive/detail/ebo_functor_holder.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/detail/assert.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template<class F, class ValueTraits, algo_types AlgoType> +struct node_cloner + : private ebo_functor_holder<F> +{ + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::node_ptr node_ptr; + typedef ebo_functor_holder<F> base_t; + typedef typename get_algo< AlgoType + , node_traits>::type node_algorithms; + static const bool safemode_or_autounlink = + is_safe_autounlink<value_traits::link_mode>::value; + typedef typename value_traits::value_type value_type; + typedef typename value_traits::pointer pointer; + typedef typename node_traits::node node; + typedef typename value_traits::const_node_ptr const_node_ptr; + typedef typename value_traits::reference reference; + typedef typename value_traits::const_reference const_reference; + + node_cloner(F f, const ValueTraits *traits) + : base_t(f), traits_(traits) + {} + + // tree-based containers use this method, which is proxy-reference friendly + node_ptr operator()(const node_ptr & p) + { + const_reference v = *traits_->to_value_ptr(p); + node_ptr n = traits_->to_node_ptr(*base_t::get()(v)); + //Cloned node must be in default mode if the linking mode requires it + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); + return n; + } + + // hashtables use this method, which is proxy-reference unfriendly + node_ptr operator()(const node &to_clone) + { + const value_type &v = + *traits_->to_value_ptr + (pointer_traits<const_node_ptr>::pointer_to(to_clone)); + node_ptr n = traits_->to_node_ptr(*base_t::get()(v)); + //Cloned node must be in default mode if the linking mode requires it + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); + return n; + } + + const ValueTraits * const traits_; +}; + +template<class F, class ValueTraits, algo_types AlgoType> +struct node_disposer + : private ebo_functor_holder<F> +{ + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::node_ptr node_ptr; + typedef ebo_functor_holder<F> base_t; + typedef typename get_algo< AlgoType + , node_traits>::type node_algorithms; + static const bool safemode_or_autounlink = + is_safe_autounlink<value_traits::link_mode>::value; + + node_disposer(F f, const ValueTraits *cont) + : base_t(f), traits_(cont) + {} + + void operator()(const node_ptr & p) + { + if(safemode_or_autounlink) + node_algorithms::init(p); + base_t::get()(traits_->to_value_ptr(p)); + } + const ValueTraits * const traits_; +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_NODE_CLONER_DISPOSER_HPP diff --git a/boost/intrusive/detail/node_holder.hpp b/boost/intrusive/detail/node_holder.hpp new file mode 100644 index 0000000000..12732a87a7 --- /dev/null +++ b/boost/intrusive/detail/node_holder.hpp @@ -0,0 +1,31 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP +#define BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { + +template<class Node, class Tag, unsigned int> +struct node_holder + : public Node +{}; + +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_NODE_HOLDER_HPP diff --git a/boost/intrusive/detail/node_to_value.hpp b/boost/intrusive/detail/node_to_value.hpp new file mode 100644 index 0000000000..6ec3971239 --- /dev/null +++ b/boost/intrusive/detail/node_to_value.hpp @@ -0,0 +1,126 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP +#define BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template<class VoidPointer> +struct dummy_constptr +{ + typedef typename boost::intrusive::pointer_traits<VoidPointer>:: + template rebind_pointer<const void>::type ConstVoidPtr; + + explicit dummy_constptr(ConstVoidPtr) + {} + + dummy_constptr() + {} + + ConstVoidPtr get_ptr() const + { return ConstVoidPtr(); } +}; + +template<class VoidPointer> +struct constptr +{ + typedef typename boost::intrusive::pointer_traits<VoidPointer>:: + template rebind_pointer<const void>::type ConstVoidPtr; + + constptr() + {} + + explicit constptr(const ConstVoidPtr &ptr) + : const_void_ptr_(ptr) + {} + + const void *get_ptr() const + { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); } + + ConstVoidPtr const_void_ptr_; +}; + +template <class VoidPointer, bool store_ptr> +struct select_constptr +{ + typedef typename if_c + < store_ptr + , constptr<VoidPointer> + , dummy_constptr<VoidPointer> + >::type type; +}; + + +template<class ValueTraits, bool IsConst> +struct node_to_value + : public select_constptr + < typename pointer_traits + <typename ValueTraits::pointer>::template rebind_pointer<void>::type + , is_stateful_value_traits<ValueTraits>::value + >::type +{ + static const bool stateful_value_traits = is_stateful_value_traits<ValueTraits>::value; + typedef typename select_constptr + < typename pointer_traits + <typename ValueTraits::pointer>:: + template rebind_pointer<void>::type + , stateful_value_traits >::type Base; + + typedef ValueTraits value_traits; + typedef typename value_traits::value_type value_type; + typedef typename value_traits::node_traits::node node; + typedef typename add_const_if_c + <value_type, IsConst>::type vtype; + typedef typename add_const_if_c + <node, IsConst>::type ntype; + typedef typename pointer_traits + <typename ValueTraits::pointer>:: + template rebind_pointer<ntype>::type npointer; + typedef typename pointer_traits<npointer>:: + template rebind_pointer<const ValueTraits>::type const_value_traits_ptr; + + node_to_value(const const_value_traits_ptr &ptr) + : Base(ptr) + {} + + typedef vtype & result_type; + typedef ntype & first_argument_type; + + const_value_traits_ptr get_value_traits() const + { return pointer_traits<const_value_traits_ptr>::static_cast_from(Base::get_ptr()); } + + result_type to_value(first_argument_type arg, false_) const + { return *(value_traits::to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); } + + result_type to_value(first_argument_type arg, true_) const + { return *(this->get_value_traits()->to_value_ptr(pointer_traits<npointer>::pointer_to(arg))); } + + result_type operator()(first_argument_type arg) const + { return this->to_value(arg, bool_<stateful_value_traits>()); } +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_NODE_TO_VALUE_HPP diff --git a/boost/intrusive/detail/parent_from_member.hpp b/boost/intrusive/detail/parent_from_member.hpp index 2afffb47bc..3dfe8d6461 100644 --- a/boost/intrusive/detail/parent_from_member.hpp +++ b/boost/intrusive/detail/parent_from_member.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,13 +12,16 @@ #ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP #define BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <cstddef> #if defined(BOOST_MSVC) || ((defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && defined(BOOST_INTEL)) - -#define BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER -#include <boost/cstdint.hpp> + #define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER + #include <boost/static_assert.hpp> #endif namespace boost { @@ -29,15 +32,39 @@ template<class Parent, class Member> inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member) { //The implementation of a pointer to member is compiler dependent. - #if defined(BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER) - //msvc compliant compilers use their the first 32 bits as offset (even in 64 bit mode) + #if defined(BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER) + + //MSVC compliant compilers use their the first 32 bits as offset (even in 64 bit mode) union caster_union { const Member Parent::* ptr_to_member; - boost::int32_t offset; + int offset; } caster; + + //MSVC ABI can use up to 3 int32 to represent pointer to member data + //with virtual base classes, in those cases there is no simple to + //obtain the address of the parent. So static assert to avoid runtime errors + BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(int) ); + caster.ptr_to_member = ptr_to_member; return std::ptrdiff_t(caster.offset); + //Additional info on MSVC behaviour for the future. For 2/3 int ptr-to-member + //types dereference seems to be: + // + // vboffset = [compile_time_offset if 2-int ptr2memb] / + // [ptr2memb.i32[2] if 3-int ptr2memb]. + // vbtable = *(this + vboffset); + // adj = vbtable[ptr2memb.i32[1]]; + // var = adj + (this + vboffset) + ptr2memb.i32[0]; + // + //To reverse the operation we need to + // - obtain vboffset (in 2-int ptr2memb implementation only) + // - Go to Parent's vbtable and obtain adjustment at index ptr2memb.i32[1] + // - parent = member - adj - vboffset - ptr2memb.i32[0] + // + //Even accessing to RTTI we might not be able to obtain this information + //so anyone who thinks it's possible, please send a patch. + //This works with gcc, msvc, ac++, ibmcpp #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \ defined(__IBMCPP__) || defined(__DECCXX) @@ -84,8 +111,8 @@ inline const Parent *parent_from_member(const Member *member, const Member Paren } //namespace intrusive { } //namespace boost { -#ifdef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER -#undef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER +#ifdef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER +#undef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER #endif #include <boost/intrusive/detail/config_end.hpp> diff --git a/boost/intrusive/detail/pointer_element.hpp b/boost/intrusive/detail/pointer_element.hpp new file mode 100644 index 0000000000..1c17f419ec --- /dev/null +++ b/boost/intrusive/detail/pointer_element.hpp @@ -0,0 +1,170 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_POINTER_ELEMENT_HPP +#define BOOST_INTRUSIVE_DETAIL_POINTER_ELEMENT_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/workaround.hpp> + +namespace boost { +namespace intrusive { +namespace detail{ + +////////////////////// +//struct first_param +////////////////////// + +template <typename T> struct first_param +{ typedef void type; }; + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + + template <template <typename, typename...> class TemplateClass, typename T, typename... Args> + struct first_param< TemplateClass<T, Args...> > + { + typedef T type; + }; + +#else //C++03 compilers + + template < template //0arg + <class + > class TemplateClass, class T + > + struct first_param + < TemplateClass<T> > + { typedef T type; }; + + template < template //1arg + <class,class + > class TemplateClass, class T + , class P0> + struct first_param + < TemplateClass<T, P0> > + { typedef T type; }; + + template < template //2arg + <class,class,class + > class TemplateClass, class T + , class P0, class P1> + struct first_param + < TemplateClass<T, P0, P1> > + { typedef T type; }; + + template < template //3arg + <class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2> + struct first_param + < TemplateClass<T, P0, P1, P2> > + { typedef T type; }; + + template < template //4arg + <class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3> + struct first_param + < TemplateClass<T, P0, P1, P2, P3> > + { typedef T type; }; + + template < template //5arg + <class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4> > + { typedef T type; }; + + template < template //6arg + <class,class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4, class P5> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4, P5> > + { typedef T type; }; + + template < template //7arg + <class,class,class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4, class P5, class P6> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4, P5, P6> > + { typedef T type; }; + + template < template //8arg + <class,class,class,class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4, P5, P6, P7> > + { typedef T type; }; + + template < template //9arg + <class,class,class,class,class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4, P5, P6, P7, P8> > + { typedef T type; }; + + template < template //10arg + <class,class,class,class,class,class,class,class,class,class,class + > class TemplateClass, class T + , class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9> + struct first_param + < TemplateClass<T, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> > + { typedef T type; }; + +#endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +template <typename T> +struct has_internal_pointer_element +{ + template <typename X> + static char test(int, typename X::element_type*); + + template <typename X> + static int test(...); + + static const bool value = (1 == sizeof(test<T>(0, 0))); +}; + +template<class Ptr, bool = has_internal_pointer_element<Ptr>::value> +struct pointer_element_impl +{ + typedef typename Ptr::element_type type; +}; + +template<class Ptr> +struct pointer_element_impl<Ptr, false> +{ + typedef typename boost::intrusive::detail::first_param<Ptr>::type type; +}; + +} //namespace detail{ + +template <typename Ptr> +struct pointer_element +{ + typedef typename ::boost::intrusive::detail::pointer_element_impl<Ptr>::type type; +}; + +template <typename T> +struct pointer_element<T*> +{ typedef T type; }; + +} //namespace container { +} //namespace boost { + +#endif // defined(BOOST_INTRUSIVE_DETAIL_POINTER_ELEMENT_HPP) diff --git a/boost/intrusive/detail/preprocessor.hpp b/boost/intrusive/detail/preprocessor.hpp index 348b104bb0..cdbc8a1d39 100644 --- a/boost/intrusive/detail/preprocessor.hpp +++ b/boost/intrusive/detail/preprocessor.hpp @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2008-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2008-2014. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -11,29 +11,19 @@ #ifndef BOOST_INTRUSIVE_DETAIL_PREPROCESSOR_HPP #define BOOST_INTRUSIVE_DETAIL_PREPROCESSOR_HPP -#if (defined _MSC_VER) && (_MSC_VER >= 1200) +#if defined(_MSC_VER) # pragma once #endif #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/detail/workaround.hpp> -#include <boost/preprocessor/iteration/local.hpp> -#include <boost/preprocessor/punctuation/paren_if.hpp> -#include <boost/preprocessor/punctuation/comma_if.hpp> -#include <boost/preprocessor/control/expr_if.hpp> #include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/repetition/enum.hpp> -#include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_trailing_params.hpp> #include <boost/preprocessor/repetition/enum_trailing.hpp> -#include <boost/preprocessor/repetition/enum_shifted_params.hpp> -#include <boost/preprocessor/repetition/enum_shifted.hpp> -#include <boost/preprocessor/repetition/repeat.hpp> -#include <boost/preprocessor/logical/not.hpp> #include <boost/preprocessor/arithmetic/sub.hpp> -#include <boost/preprocessor/arithmetic/add.hpp> -#include <boost/preprocessor/iteration/iterate.hpp> + #define BOOST_INTRUSIVE_MAX_CONSTRUCTOR_PARAMETERS 10 diff --git a/boost/intrusive/detail/rbtree_node.hpp b/boost/intrusive/detail/rbtree_node.hpp index b76582bb61..ab50509c25 100644 --- a/boost/intrusive/detail/rbtree_node.hpp +++ b/boost/intrusive/detail/rbtree_node.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012. +// (C) Copyright Ion Gaztanaga 2006-2013. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,12 +14,16 @@ #ifndef BOOST_INTRUSIVE_RBTREE_NODE_HPP #define BOOST_INTRUSIVE_RBTREE_NODE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/pointer_rebind.hpp> #include <boost/intrusive/rbtree_algorithms.hpp> #include <boost/intrusive/pointer_plus_bits.hpp> #include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/tree_node.hpp> namespace boost { namespace intrusive { @@ -34,9 +38,9 @@ namespace intrusive { template<class VoidPointer> struct compact_rbtree_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <compact_rbtree_node<VoidPointer> >::type node_ptr; + typedef compact_rbtree_node<VoidPointer> node; + typedef typename pointer_rebind<VoidPointer, node >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr; enum color { red_t, black_t }; node_ptr parent_, left_, right_; }; @@ -45,9 +49,9 @@ struct compact_rbtree_node template<class VoidPointer> struct rbtree_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <rbtree_node<VoidPointer> >::type node_ptr; + typedef rbtree_node<VoidPointer> node; + typedef typename pointer_rebind<VoidPointer, node >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr; enum color { red_t, black_t }; node_ptr parent_, left_, right_; @@ -60,27 +64,33 @@ template<class VoidPointer> struct default_rbtree_node_traits_impl { typedef rbtree_node<VoidPointer> node; - - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; typedef typename node::color color; - static const node_ptr & get_parent(const const_node_ptr & n) + static node_ptr get_parent(const const_node_ptr & n) + { return n->parent_; } + + static node_ptr get_parent(const node_ptr & n) { return n->parent_; } static void set_parent(const node_ptr & n, const node_ptr & p) { n->parent_ = p; } - static const node_ptr & get_left(const const_node_ptr & n) + static node_ptr get_left(const const_node_ptr & n) + { return n->left_; } + + static node_ptr get_left(const node_ptr & n) { return n->left_; } static void set_left(const node_ptr & n, const node_ptr & l) { n->left_ = l; } - static const node_ptr & get_right(const const_node_ptr & n) + static node_ptr get_right(const const_node_ptr & n) + { return n->right_; } + + static node_ptr get_right(const node_ptr & n) { return n->right_; } static void set_right(const node_ptr & n, const node_ptr & r) @@ -89,6 +99,9 @@ struct default_rbtree_node_traits_impl static color get_color(const const_node_ptr & n) { return n->color_; } + static color get_color(const node_ptr & n) + { return n->color_; } + static void set_color(const node_ptr & n, color c) { n->color_ = c; } @@ -105,10 +118,8 @@ template<class VoidPointer> struct compact_rbtree_node_traits_impl { typedef compact_rbtree_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename node::const_node_ptr const_node_ptr; typedef pointer_plus_bits<node_ptr, 1> ptr_bit; @@ -117,16 +128,25 @@ struct compact_rbtree_node_traits_impl static node_ptr get_parent(const const_node_ptr & n) { return ptr_bit::get_pointer(n->parent_); } + static node_ptr get_parent(const node_ptr & n) + { return ptr_bit::get_pointer(n->parent_); } + static void set_parent(const node_ptr & n, const node_ptr & p) { ptr_bit::set_pointer(n->parent_, p); } - static const node_ptr & get_left(const const_node_ptr & n) + static node_ptr get_left(const const_node_ptr & n) + { return n->left_; } + + static node_ptr get_left(const node_ptr & n) { return n->left_; } static void set_left(const node_ptr & n, const node_ptr & l) { n->left_ = l; } - static const node_ptr & get_right(const const_node_ptr & n) + static node_ptr get_right(const const_node_ptr & n) + { return n->right_; } + + static node_ptr get_right(const node_ptr & n) { return n->right_; } static void set_right(const node_ptr & n, const node_ptr & r) @@ -135,6 +155,9 @@ struct compact_rbtree_node_traits_impl static color get_color(const const_node_ptr & n) { return (color)ptr_bit::get_bits(n->parent_); } + static color get_color(const node_ptr & n) + { return (color)ptr_bit::get_bits(n->parent_); } + static void set_color(const node_ptr & n, color c) { ptr_bit::set_bits(n->parent_, c != 0); } @@ -156,7 +179,7 @@ struct rbtree_node_traits_dispatch<VoidPointer, true> : public compact_rbtree_node_traits_impl<VoidPointer> {}; -//Inherit from the detail::link_dispatch depending on the embedding capabilities +//Inherit from rbtree_node_traits_dispatch depending on the embedding capabilities template<class VoidPointer, bool OptimizeSize = false> struct rbtree_node_traits : public rbtree_node_traits_dispatch diff --git a/boost/intrusive/detail/reverse_iterator.hpp b/boost/intrusive/detail/reverse_iterator.hpp new file mode 100644 index 0000000000..9f443ab4b2 --- /dev/null +++ b/boost/intrusive/detail/reverse_iterator.hpp @@ -0,0 +1,139 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP +#define BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/detail/iiterator.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template<class It> +class reverse_iterator +{ + public: + typedef typename boost::intrusive::iterator_traits<It>::pointer pointer; + typedef typename boost::intrusive::iterator_traits<It>::reference reference; + typedef typename boost::intrusive::iterator_traits<It>::difference_type difference_type; + typedef typename boost::intrusive::iterator_traits<It>::iterator_category iterator_category; + typedef typename boost::intrusive::iterator_traits<It>::value_type value_type; + + + typedef It iterator_type; + + reverse_iterator() + : m_current() //Value initialization to achieve "null iterators" (N3644) + {} + + explicit reverse_iterator(It r) + : m_current(r) + {} + + template<class OtherIt> + reverse_iterator(const reverse_iterator<OtherIt>& r) + : m_current(r.base()) + {} + + It base() const + { return m_current; } + + reference operator*() const + { It temp(m_current); --temp; return *temp; } + + pointer operator->() const + { It temp(m_current); --temp; return temp.operator->(); } + + reference operator[](difference_type off) const + { return this->m_current[-off]; } + + reverse_iterator& operator++() + { --m_current; return *this; } + + reverse_iterator operator++(int) + { + reverse_iterator temp = *this; + --m_current; + return temp; + } + + reverse_iterator& operator--() + { + ++m_current; + return *this; + } + + reverse_iterator operator--(int) + { + reverse_iterator temp(*this); + ++m_current; + return temp; + } + + friend bool operator==(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current == r.m_current; } + + friend bool operator!=(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current != r.m_current; } + + friend bool operator<(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current > r.m_current; } + + friend bool operator<=(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current >= r.m_current; } + + friend bool operator>(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current < r.m_current; } + + friend bool operator>=(const reverse_iterator& l, const reverse_iterator& r) + { return l.m_current <= r.m_current; } + + reverse_iterator& operator+=(difference_type off) + { m_current -= off; return *this; } + + friend reverse_iterator operator+(const reverse_iterator & l, difference_type off) + { + reverse_iterator tmp(l.m_current); + tmp.m_current -= off; + return tmp; + } + + reverse_iterator& operator-=(difference_type off) + { m_current += off; return *this; } + + friend reverse_iterator operator-(const reverse_iterator & l, difference_type off) + { + reverse_iterator tmp(l.m_current); + tmp.m_current += off; + return tmp; + } + + friend difference_type operator-(const reverse_iterator& l, const reverse_iterator& r) + { return r.m_current - l.m_current; } + + private: + It m_current; // the wrapped iterator +}; + +} //namespace detail +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_DETAIL_ITERATOR_HPP diff --git a/boost/intrusive/detail/simple_disposers.hpp b/boost/intrusive/detail/simple_disposers.hpp new file mode 100644 index 0000000000..af597722fa --- /dev/null +++ b/boost/intrusive/detail/simple_disposers.hpp @@ -0,0 +1,46 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_SIMPLE_DISPOSERS_HPP +#define BOOST_INTRUSIVE_DETAIL_SIMPLE_DISPOSERS_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { +namespace detail { + +class null_disposer +{ + public: + template <class Pointer> + void operator()(Pointer) + {} +}; + +template<class NodeAlgorithms> +class init_disposer +{ + typedef typename NodeAlgorithms::node_ptr node_ptr; + + public: + void operator()(const node_ptr & p) + { NodeAlgorithms::init(p); } +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_SIMPLE_DISPOSERS_HPP diff --git a/boost/intrusive/detail/size_holder.hpp b/boost/intrusive/detail/size_holder.hpp new file mode 100644 index 0000000000..a733187733 --- /dev/null +++ b/boost/intrusive/detail/size_holder.hpp @@ -0,0 +1,80 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP +#define BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { +namespace detail { + +template<bool ConstantSize, class SizeType, class Tag = void> +struct size_holder +{ + static const bool constant_time_size = ConstantSize; + typedef SizeType size_type; + + SizeType get_size() const + { return size_; } + + void set_size(SizeType size) + { size_ = size; } + + void decrement() + { --size_; } + + void increment() + { ++size_; } + + void increase(SizeType n) + { size_ += n; } + + void decrease(SizeType n) + { size_ -= n; } + + SizeType size_; +}; + +template<class SizeType, class Tag> +struct size_holder<false, SizeType, Tag> +{ + static const bool constant_time_size = false; + typedef SizeType size_type; + + size_type get_size() const + { return 0; } + + void set_size(size_type) + {} + + void decrement() + {} + + void increment() + {} + + void increase(SizeType) + {} + + void decrease(SizeType) + {} +}; + +} //namespace detail{ +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_SIZE_HOLDER_HPP diff --git a/boost/intrusive/detail/slist_iterator.hpp b/boost/intrusive/detail/slist_iterator.hpp new file mode 100644 index 0000000000..579c660f57 --- /dev/null +++ b/boost/intrusive/detail/slist_iterator.hpp @@ -0,0 +1,120 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Olaf Krzikalla 2004-2006. +// (C) Copyright Ion Gaztanaga 2006-2013 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_SLIST_ITERATOR_HPP +#define BOOST_INTRUSIVE_SLIST_ITERATOR_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/detail/std_fwd.hpp> +#include <boost/intrusive/detail/iiterator.hpp> +#include <boost/intrusive/detail/mpl.hpp> + +namespace boost { +namespace intrusive { + + +// slist_iterator provides some basic functions for a +// node oriented bidirectional iterator: +template<class ValueTraits, bool IsConst> +class slist_iterator +{ + protected: + typedef iiterator + <ValueTraits, IsConst, std::forward_iterator_tag> types_t; + + static const bool stateful_value_traits = types_t::stateful_value_traits; + + typedef ValueTraits value_traits; + typedef typename types_t::node_traits node_traits; + + typedef typename types_t::node node; + typedef typename types_t::node_ptr node_ptr; + typedef typename types_t::const_value_traits_ptr const_value_traits_ptr; + + public: + typedef typename types_t::iterator_traits::difference_type difference_type; + typedef typename types_t::iterator_traits::value_type value_type; + typedef typename types_t::iterator_traits::pointer pointer; + typedef typename types_t::iterator_traits::reference reference; + typedef typename types_t::iterator_traits::iterator_category iterator_category; + + slist_iterator() + {} + + explicit slist_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr) + : members_(nodeptr, traits_ptr) + {} + + slist_iterator(slist_iterator<ValueTraits, false> const& other) + : members_(other.pointed_node(), other.get_value_traits()) + {} + + const node_ptr &pointed_node() const + { return members_.nodeptr_; } + + slist_iterator &operator=(const node_ptr &node) + { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); } + + const_value_traits_ptr get_value_traits() const + { return members_.get_ptr(); } + + public: + slist_iterator& operator++() + { + members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); + return static_cast<slist_iterator&> (*this); + } + + slist_iterator operator++(int) + { + slist_iterator result (*this); + members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); + return result; + } + + friend bool operator== (const slist_iterator& l, const slist_iterator& r) + { return l.pointed_node() == r.pointed_node(); } + + friend bool operator!= (const slist_iterator& l, const slist_iterator& r) + { return !(l == r); } + + reference operator*() const + { return *operator->(); } + + pointer operator->() const + { return this->operator_arrow(detail::bool_<stateful_value_traits>()); } + + slist_iterator<ValueTraits, false> unconst() const + { return slist_iterator<ValueTraits, false>(this->pointed_node(), this->get_value_traits()); } + + private: + + pointer operator_arrow(detail::false_) const + { return ValueTraits::to_value_ptr(members_.nodeptr_); } + + pointer operator_arrow(detail::true_) const + { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); } + + iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_; +}; + +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_SLIST_ITERATOR_HPP diff --git a/boost/intrusive/detail/slist_node.hpp b/boost/intrusive/detail/slist_node.hpp index 0eddbcd69a..437190e6c0 100644 --- a/boost/intrusive/detail/slist_node.hpp +++ b/boost/intrusive/detail/slist_node.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,10 +14,12 @@ #ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP #define BOOST_INTRUSIVE_SLIST_NODE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/pointer_rebind.hpp> namespace boost { namespace intrusive { @@ -25,8 +27,7 @@ namespace intrusive { template<class VoidPointer> struct slist_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<slist_node>::type node_ptr; + typedef typename pointer_rebind<VoidPointer, slist_node>::type node_ptr; node_ptr next_; }; @@ -36,125 +37,20 @@ struct slist_node template<class VoidPointer> struct slist_node_traits { - typedef slist_node<VoidPointer> node; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr; + typedef slist_node<VoidPointer> node; + typedef typename node::node_ptr node_ptr; + typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr; + + static node_ptr get_next(const const_node_ptr & n) + { return n->next_; } - static const node_ptr &get_next(const const_node_ptr & n) + static node_ptr get_next(const node_ptr & n) { return n->next_; } static void set_next(const node_ptr & n, const node_ptr & next) { n->next_ = next; } }; -// slist_iterator provides some basic functions for a -// node oriented bidirectional iterator: -template<class Container, bool IsConst> -class slist_iterator - : public std::iterator - < std::forward_iterator_tag - , typename Container::value_type - , typename Container::difference_type - , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type - , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type - > -{ - protected: - typedef typename Container::real_value_traits real_value_traits; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename node_traits::node_ptr node_ptr; - typedef typename pointer_traits - <node_ptr>::template rebind_pointer <void>::type void_pointer; - static const bool store_container_ptr = - detail::store_cont_ptr_on_it<Container>::value; - - public: - typedef typename Container::value_type value_type; - typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer; - typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference; - - slist_iterator() - : members_ (node_ptr(), 0) - {} - - explicit slist_iterator(const node_ptr & node, const Container *cont_ptr) - : members_ (node, cont_ptr) - {} - - slist_iterator(slist_iterator<Container, false> const& other) - : members_(other.pointed_node(), other.get_container()) - {} - - const node_ptr &pointed_node() const - { return members_.nodeptr_; } - - slist_iterator &operator=(const node_ptr &node) - { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); } - - public: - slist_iterator& operator++() - { - members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); - return static_cast<slist_iterator&> (*this); - } - - slist_iterator operator++(int) - { - slist_iterator result (*this); - members_.nodeptr_ = node_traits::get_next(members_.nodeptr_); - return result; - } - - friend bool operator== (const slist_iterator& l, const slist_iterator& r) - { return l.pointed_node() == r.pointed_node(); } - - friend bool operator!= (const slist_iterator& l, const slist_iterator& r) - { return !(l == r); } - - reference operator*() const - { return *operator->(); } - - pointer operator->() const - { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); } - - const Container *get_container() const - { - if(store_container_ptr) - return static_cast<const Container*>(members_.get_ptr()); - else - return 0; - } - - slist_iterator<Container, false> unconst() const - { return slist_iterator<Container, false>(this->pointed_node(), this->get_container()); } - - const real_value_traits *get_real_value_traits() const - { - if(store_container_ptr) - return &this->get_container()->get_real_value_traits(); - else - return 0; - } - - private: - struct members - : public detail::select_constptr - <void_pointer, store_container_ptr>::type - { - typedef typename detail::select_constptr - <void_pointer, store_container_ptr>::type Base; - - members(const node_ptr &n_ptr, const void *cont) - : Base(cont), nodeptr_(n_ptr) - {} - - node_ptr nodeptr_; - } members_; -}; - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/detail/std_fwd.hpp b/boost/intrusive/detail/std_fwd.hpp new file mode 100644 index 0000000000..b657c4acfe --- /dev/null +++ b/boost/intrusive/detail/std_fwd.hpp @@ -0,0 +1,54 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/container for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_STD_FWD_HPP +#define BOOST_INTRUSIVE_DETAIL_STD_FWD_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +////////////////////////////////////////////////////////////////////////////// +// Standard predeclarations +////////////////////////////////////////////////////////////////////////////// + +#if defined(__clang__) && defined(_LIBCPP_VERSION) + #define BOOST_INTRUSIVE_CLANG_INLINE_STD_NS + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wc++11-extensions" + #define BOOST_INTRUSIVE_STD_NS_BEG _LIBCPP_BEGIN_NAMESPACE_STD + #define BOOST_INTRUSIVE_STD_NS_END _LIBCPP_END_NAMESPACE_STD +#else + #define BOOST_INTRUSIVE_STD_NS_BEG namespace std{ + #define BOOST_INTRUSIVE_STD_NS_END } +#endif + +BOOST_INTRUSIVE_STD_NS_BEG + +template<class T> +struct less; + +template<class T> +struct equal_to; + +struct input_iterator_tag; +struct forward_iterator_tag; +struct bidirectional_iterator_tag; +struct random_access_iterator_tag; + +BOOST_INTRUSIVE_STD_NS_END + +#ifdef BOOST_INTRUSIVE_CLANG_INLINE_STD_NS + #pragma GCC diagnostic pop + #undef BOOST_INTRUSIVE_CLANG_INLINE_STD_NS +#endif //BOOST_INTRUSIVE_CLANG_INLINE_STD_NS + +#endif //#ifndef BOOST_INTRUSIVE_DETAIL_STD_FWD_HPP + diff --git a/boost/intrusive/detail/to_raw_pointer.hpp b/boost/intrusive/detail/to_raw_pointer.hpp new file mode 100644 index 0000000000..e7ebff9e5d --- /dev/null +++ b/boost/intrusive/detail/to_raw_pointer.hpp @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_TO_RAW_POINTER_HPP +#define BOOST_INTRUSIVE_DETAIL_TO_RAW_POINTER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/detail/pointer_element.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template <class T> +inline T* to_raw_pointer(T* p) +{ return p; } + +template <class Pointer> +inline typename boost::intrusive::pointer_element<Pointer>::type* +to_raw_pointer(const Pointer &p) +{ return boost::intrusive::detail::to_raw_pointer(p.operator->()); } + +} //namespace detail +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP diff --git a/boost/intrusive/detail/transform_iterator.hpp b/boost/intrusive/detail/transform_iterator.hpp index 488db9ade8..698318be9b 100644 --- a/boost/intrusive/detail/transform_iterator.hpp +++ b/boost/intrusive/detail/transform_iterator.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,8 +13,11 @@ #ifndef BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP #define BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> #include <boost/intrusive/detail/mpl.hpp> namespace boost { @@ -51,7 +54,7 @@ struct operator_arrow_proxy<T&> template <class Iterator, class UnaryFunction> class transform_iterator - : public std::iterator + : public boost::intrusive::iterator < typename Iterator::iterator_category , typename detail::remove_reference<typename UnaryFunction::result_type>::type , typename Iterator::difference_type @@ -158,10 +161,10 @@ class transform_iterator { return members_(*members_.m_it); } void advance(typename Iterator::difference_type n) - { std::advance(members_.m_it, n); } + { boost::intrusive::iterator_advance(members_.m_it, n); } typename Iterator::difference_type distance_to(const transform_iterator &other)const - { return std::distance(other.members_.m_it, members_.m_it); } + { return boost::intrusive::iterator_distance(other.members_.m_it, members_.m_it); } }; } //namespace detail diff --git a/boost/intrusive/detail/tree_iterator.hpp b/boost/intrusive/detail/tree_iterator.hpp new file mode 100644 index 0000000000..c3b599d190 --- /dev/null +++ b/boost/intrusive/detail/tree_iterator.hpp @@ -0,0 +1,141 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2007-2013 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_TREE_ITERATOR_HPP +#define BOOST_INTRUSIVE_TREE_ITERATOR_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/detail/std_fwd.hpp> +#include <boost/intrusive/detail/iiterator.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> + +namespace boost { +namespace intrusive { + +///////////////////////////////////////////////////////////////////////////// +// // +// Implementation of the tree iterator // +// // +///////////////////////////////////////////////////////////////////////////// + +// tree_iterator provides some basic functions for a +// node oriented bidirectional iterator: +template<class ValueTraits, bool IsConst> +class tree_iterator +{ + protected: + typedef iiterator< ValueTraits, IsConst + , std::bidirectional_iterator_tag> types_t; + + typedef ValueTraits value_traits; + typedef typename types_t::node_traits node_traits; + + typedef typename types_t::node node; + typedef typename types_t::node_ptr node_ptr; + typedef typename types_t::const_value_traits_ptr const_value_traits_ptr; + static const bool stateful_value_traits = types_t::stateful_value_traits; + typedef bstree_algorithms<node_traits> node_algorithms; + + public: + typedef typename types_t::iterator_traits::difference_type difference_type; + typedef typename types_t::iterator_traits::value_type value_type; + typedef typename types_t::iterator_traits::pointer pointer; + typedef typename types_t::iterator_traits::reference reference; + typedef typename types_t::iterator_traits::iterator_category iterator_category; + + tree_iterator() + {} + + explicit tree_iterator(const node_ptr & nodeptr, const const_value_traits_ptr &traits_ptr) + : members_(nodeptr, traits_ptr) + {} + + tree_iterator(tree_iterator<value_traits, false> const& other) + : members_(other.pointed_node(), other.get_value_traits()) + {} + + const node_ptr &pointed_node() const + { return members_.nodeptr_; } + + tree_iterator &operator=(const node_ptr &nodeptr) + { members_.nodeptr_ = nodeptr; return static_cast<tree_iterator&>(*this); } + + public: + tree_iterator& operator++() + { + members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_); + return static_cast<tree_iterator&> (*this); + } + + tree_iterator operator++(int) + { + tree_iterator result (*this); + members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_); + return result; + } + + tree_iterator& operator--() + { + members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_); + return static_cast<tree_iterator&> (*this); + } + + tree_iterator operator--(int) + { + tree_iterator result (*this); + members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_); + return result; + } + + friend bool operator== (const tree_iterator& l, const tree_iterator& r) + { return l.pointed_node() == r.pointed_node(); } + + friend bool operator!= (const tree_iterator& l, const tree_iterator& r) + { return !(l == r); } + + reference operator*() const + { return *operator->(); } + + pointer operator->() const + { return this->operator_arrow(detail::bool_<stateful_value_traits>()); } + + const_value_traits_ptr get_value_traits() const + { return members_.get_ptr(); } + + tree_iterator end_iterator_from_it() const + { + return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_value_traits()); + } + + tree_iterator<value_traits, false> unconst() const + { return tree_iterator<value_traits, false>(this->pointed_node(), this->get_value_traits()); } + + private: + pointer operator_arrow(detail::false_) const + { return ValueTraits::to_value_ptr(members_.nodeptr_); } + + pointer operator_arrow(detail::true_) const + { return this->get_value_traits()->to_value_ptr(members_.nodeptr_); } + + iiterator_members<node_ptr, const_value_traits_ptr, stateful_value_traits> members_; +}; + +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_TREE_ITERATOR_HPP diff --git a/boost/intrusive/detail/tree_node.hpp b/boost/intrusive/detail/tree_node.hpp index 09fa7a4562..653d6fcf07 100644 --- a/boost/intrusive/detail/tree_node.hpp +++ b/boost/intrusive/detail/tree_node.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,10 +13,12 @@ #ifndef BOOST_INTRUSIVE_TREE_NODE_HPP #define BOOST_INTRUSIVE_TREE_NODE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <iterator> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/pointer_rebind.hpp> namespace boost { namespace intrusive { @@ -24,9 +26,7 @@ namespace intrusive { template<class VoidPointer> struct tree_node { - typedef typename pointer_traits - <VoidPointer>::template rebind_pointer - <tree_node<VoidPointer> >::type node_ptr; + typedef typename pointer_rebind<VoidPointer, tree_node>::type node_ptr; node_ptr parent_, left_, right_; }; @@ -36,152 +36,37 @@ struct tree_node_traits { typedef tree_node<VoidPointer> node; - typedef typename pointer_traits<VoidPointer>::template - rebind_pointer<node>::type node_ptr; - typedef typename pointer_traits<VoidPointer>::template - rebind_pointer<const node>::type const_node_ptr; + typedef typename node::node_ptr node_ptr; + typedef typename pointer_rebind<VoidPointer, const node>::type const_node_ptr; + + static node_ptr get_parent(const const_node_ptr & n) + { return n->parent_; } - static const node_ptr & get_parent(const const_node_ptr & n) + static node_ptr get_parent(const node_ptr & n) { return n->parent_; } static void set_parent(const node_ptr & n, const node_ptr & p) { n->parent_ = p; } - static const node_ptr & get_left(const const_node_ptr & n) + static node_ptr get_left(const const_node_ptr & n) + { return n->left_; } + + static node_ptr get_left(const node_ptr & n) { return n->left_; } static void set_left(const node_ptr & n, const node_ptr & l) { n->left_ = l; } - static const node_ptr & get_right(const const_node_ptr & n) + static node_ptr get_right(const const_node_ptr & n) + { return n->right_; } + + static node_ptr get_right(const node_ptr & n) { return n->right_; } static void set_right(const node_ptr & n, const node_ptr & r) { n->right_ = r; } }; -///////////////////////////////////////////////////////////////////////////// -// // -// Implementation of the tree iterator // -// // -///////////////////////////////////////////////////////////////////////////// - -// tree_iterator provides some basic functions for a -// node oriented bidirectional iterator: -template<class Container, bool IsConst> -class tree_iterator - : public std::iterator - < std::bidirectional_iterator_tag - , typename Container::value_type - , typename Container::difference_type - , typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type - , typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type - > -{ - protected: - typedef typename Container::real_value_traits real_value_traits; - typedef typename Container::node_algorithms node_algorithms; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename node_traits::node_ptr node_ptr; - typedef typename pointer_traits<node_ptr>::template - rebind_pointer<void>::type void_pointer; - static const bool store_container_ptr = - detail::store_cont_ptr_on_it<Container>::value; - - public: - typedef typename Container::value_type value_type; - typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer; - typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference; - - - tree_iterator() - : members_ (node_ptr(), (const void *)0) - {} - - explicit tree_iterator(const node_ptr & nodeptr, const Container *cont_ptr) - : members_ (nodeptr, cont_ptr) - {} - - tree_iterator(tree_iterator<Container, false> const& other) - : members_(other.pointed_node(), other.get_container()) - {} - - const node_ptr &pointed_node() const - { return members_.nodeptr_; } - - tree_iterator &operator=(const node_ptr &nodeptr) - { members_.nodeptr_ = nodeptr; return static_cast<tree_iterator&>(*this); } - - public: - tree_iterator& operator++() - { - members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_); - return static_cast<tree_iterator&> (*this); - } - - tree_iterator operator++(int) - { - tree_iterator result (*this); - members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_); - return result; - } - - tree_iterator& operator--() - { - members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_); - return static_cast<tree_iterator&> (*this); - } - - tree_iterator operator--(int) - { - tree_iterator result (*this); - members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_); - return result; - } - - friend bool operator== (const tree_iterator& l, const tree_iterator& r) - { return l.pointed_node() == r.pointed_node(); } - - friend bool operator!= (const tree_iterator& l, const tree_iterator& r) - { return !(l == r); } - - reference operator*() const - { return *operator->(); } - - pointer operator->() const - { return this->get_real_value_traits()->to_value_ptr(members_.nodeptr_); } - - const Container *get_container() const - { return static_cast<const Container*>(members_.get_ptr()); } - - const real_value_traits *get_real_value_traits() const - { return &this->get_container()->get_real_value_traits(); } - - tree_iterator end_iterator_from_it() const - { - return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_container()); - } - - tree_iterator<Container, false> unconst() const - { return tree_iterator<Container, false>(this->pointed_node(), this->get_container()); } - - private: - struct members - : public detail::select_constptr - <void_pointer, store_container_ptr>::type - { - typedef typename detail::select_constptr - <void_pointer, store_container_ptr>::type Base; - - members(const node_ptr &n_ptr, const void *cont) - : Base(cont), nodeptr_(n_ptr) - {} - - node_ptr nodeptr_; - } members_; -}; - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/detail/uncast.hpp b/boost/intrusive/detail/uncast.hpp new file mode 100644 index 0000000000..944b6cd617 --- /dev/null +++ b/boost/intrusive/detail/uncast.hpp @@ -0,0 +1,51 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2006-2014 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_UNCAST_HPP +#define BOOST_INTRUSIVE_DETAIL_UNCAST_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/mpl.hpp> + +namespace boost { +namespace intrusive { +namespace detail { + +template<class ConstNodePtr> +struct uncast_types +{ + typedef typename pointer_traits<ConstNodePtr>::element_type element_type; + typedef typename remove_const<element_type>::type non_const_type; + typedef typename pointer_traits<ConstNodePtr>:: + template rebind_pointer<non_const_type>::type non_const_pointer; + typedef pointer_traits<non_const_pointer> non_const_traits; +}; + +template<class ConstNodePtr> +static typename uncast_types<ConstNodePtr>::non_const_pointer + uncast(const ConstNodePtr & ptr) +{ + return uncast_types<ConstNodePtr>::non_const_traits::const_cast_from(ptr); +} + +} //namespace detail { +} //namespace intrusive +} //namespace boost + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP diff --git a/boost/intrusive/detail/utilities.hpp b/boost/intrusive/detail/utilities.hpp deleted file mode 100644 index c6bc798994..0000000000 --- a/boost/intrusive/detail/utilities.hpp +++ /dev/null @@ -1,879 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Ion Gaztanaga 2006-2012 -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/intrusive for documentation. -// -///////////////////////////////////////////////////////////////////////////// - -#ifndef BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP -#define BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP - -#include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/parent_from_member.hpp> -#include <boost/intrusive/detail/ebo_functor_holder.hpp> -#include <boost/intrusive/link_mode.hpp> -#include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/detail/is_stateful_value_traits.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/cstdint.hpp> -#include <cstddef> -#include <climits> -#include <iterator> -#include <boost/cstdint.hpp> -#include <boost/static_assert.hpp> - -namespace boost { -namespace intrusive { -namespace detail { - -template <class T> -struct internal_member_value_traits -{ - template <class U> static detail::one test(...); - template <class U> static detail::two test(typename U::member_value_traits* = 0); - static const bool value = sizeof(test<T>(0)) == sizeof(detail::two); -}; - -template <class T> -struct internal_base_hook_bool -{ - template<bool Add> - struct two_or_three {one _[2 + Add];}; - template <class U> static one test(...); - template <class U> static two_or_three<U::boost_intrusive_tags::is_base_hook> test (int); - static const std::size_t value = sizeof(test<T>(0)); -}; - -template <class T> -struct internal_base_hook_bool_is_true -{ - static const bool value = internal_base_hook_bool<T>::value > sizeof(one)*2; -}; - -template <class T> -struct internal_any_hook_bool -{ - template<bool Add> - struct two_or_three {one _[2 + Add];}; - template <class U> static one test(...); - template <class U> static two_or_three<U::is_any_hook> test (int); - static const std::size_t value = sizeof(test<T>(0)); -}; - -template <class T> -struct internal_any_hook_bool_is_true -{ - static const bool value = internal_any_hook_bool<T>::value > sizeof(one)*2; -}; - - -template <class T> -struct external_value_traits_bool -{ - template<bool Add> - struct two_or_three {one _[2 + Add];}; - template <class U> static one test(...); - template <class U> static two_or_three<U::external_value_traits> test (int); - static const std::size_t value = sizeof(test<T>(0)); -}; - -template <class T> -struct external_bucket_traits_bool -{ - template<bool Add> - struct two_or_three {one _[2 + Add];}; - template <class U> static one test(...); - template <class U> static two_or_three<U::external_bucket_traits> test (int); - static const std::size_t value = sizeof(test<T>(0)); -}; - -template <class T> -struct external_value_traits_is_true -{ - static const bool value = external_value_traits_bool<T>::value > sizeof(one)*2; -}; - -template<class Node, class Tag, link_mode_type LinkMode, int> -struct node_holder - : public Node -{}; - -template <class T> -inline T* to_raw_pointer(T* p) -{ return p; } - -template <class Pointer> -inline typename boost::intrusive::pointer_traits<Pointer>::element_type* -to_raw_pointer(const Pointer &p) -{ return boost::intrusive::detail::to_raw_pointer(p.operator->()); } - -//This functor compares a stored value -//and the one passed as an argument -template<class ConstReference> -class equal_to_value -{ - ConstReference t_; - - public: - equal_to_value(ConstReference t) - : t_(t) - {} - - bool operator()(ConstReference t)const - { return t_ == t; } -}; - -class null_disposer -{ - public: - template <class Pointer> - void operator()(Pointer) - {} -}; - -template<class NodeAlgorithms> -class init_disposer -{ - typedef typename NodeAlgorithms::node_ptr node_ptr; - - public: - void operator()(const node_ptr & p) - { NodeAlgorithms::init(p); } -}; - -template<bool ConstantSize, class SizeType> -struct size_holder -{ - static const bool constant_time_size = ConstantSize; - typedef SizeType size_type; - - SizeType get_size() const - { return size_; } - - void set_size(SizeType size) - { size_ = size; } - - void decrement() - { --size_; } - - void increment() - { ++size_; } - - SizeType size_; -}; - -template<class SizeType> -struct size_holder<false, SizeType> -{ - static const bool constant_time_size = false; - typedef SizeType size_type; - - size_type get_size() const - { return 0; } - - void set_size(size_type) - {} - - void decrement() - {} - - void increment() - {} -}; - -template<class KeyValueCompare, class Container> -struct key_nodeptr_comp - : private detail::ebo_functor_holder<KeyValueCompare> -{ - typedef typename Container::real_value_traits real_value_traits; - typedef typename Container::value_type value_type; - typedef typename real_value_traits::node_ptr node_ptr; - typedef typename real_value_traits::const_node_ptr const_node_ptr; - typedef detail::ebo_functor_holder<KeyValueCompare> base_t; - key_nodeptr_comp(KeyValueCompare kcomp, const Container *cont) - : base_t(kcomp), cont_(cont) - {} - - template<class T> - struct is_node_ptr - { - static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value; - }; - - template<class T> - const value_type & key_forward - (const T &node, typename enable_if_c<is_node_ptr<T>::value>::type * = 0) const - { return *cont_->get_real_value_traits().to_value_ptr(node); } - - template<class T> - const T & key_forward(const T &key, typename enable_if_c<!is_node_ptr<T>::value>::type* = 0) const - { return key; } - - - template<class KeyType, class KeyType2> - bool operator()(const KeyType &key1, const KeyType2 &key2) const - { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); } - - const Container *cont_; -}; - -template<class F, class Container> -struct node_cloner - : private detail::ebo_functor_holder<F> -{ - typedef typename Container::real_value_traits real_value_traits; - typedef typename Container::node_algorithms node_algorithms; - typedef typename real_value_traits::value_type value_type; - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::node_traits::node node; - typedef typename real_value_traits::node_ptr node_ptr; - typedef typename real_value_traits::const_node_ptr const_node_ptr; - typedef detail::ebo_functor_holder<F> base_t; - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; - - node_cloner(F f, const Container *cont) - : base_t(f), cont_(cont) - {} - - node_ptr operator()(const node_ptr & p) - { return this->operator()(*p); } - - node_ptr operator()(const node &to_clone) - { - const value_type &v = - *cont_->get_real_value_traits().to_value_ptr - (pointer_traits<const_node_ptr>::pointer_to(to_clone)); - node_ptr n = cont_->get_real_value_traits().to_node_ptr(*base_t::get()(v)); - //Cloned node must be in default mode if the linking mode requires it - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); - return n; - } - - const Container *cont_; -}; - -template<class F, class Container> -struct node_disposer - : private detail::ebo_functor_holder<F> -{ - typedef typename Container::real_value_traits real_value_traits; - typedef typename real_value_traits::node_ptr node_ptr; - typedef detail::ebo_functor_holder<F> base_t; - typedef typename Container::node_algorithms node_algorithms; - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; - - node_disposer(F f, const Container *cont) - : base_t(f), cont_(cont) - {} - - void operator()(const node_ptr & p) - { - if(safemode_or_autounlink) - node_algorithms::init(p); - base_t::get()(cont_->get_real_value_traits().to_value_ptr(p)); - } - const Container *cont_; -}; - -struct dummy_constptr -{ - dummy_constptr(const void *) - {} - - const void *get_ptr() const - { return 0; } -}; - -template<class VoidPointer> -struct constptr -{ - typedef typename boost::intrusive::pointer_traits<VoidPointer>:: - template rebind_pointer<const void>::type ConstVoidPtr; - - constptr(const void *ptr) - : const_void_ptr_(ptr) - {} - - const void *get_ptr() const - { return boost::intrusive::detail::to_raw_pointer(const_void_ptr_); } - - ConstVoidPtr const_void_ptr_; -}; - -template <class VoidPointer, bool store_ptr> -struct select_constptr -{ - typedef typename detail::if_c - < store_ptr - , constptr<VoidPointer> - , dummy_constptr - >::type type; -}; - -template<class T, bool Add> -struct add_const_if_c -{ - typedef typename detail::if_c - < Add - , typename detail::add_const<T>::type - , T - >::type type; -}; - -template <link_mode_type LinkMode> -struct link_dispatch -{}; - -template<class Hook> -void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>) -{ //If this assertion raises, you might have destroyed an object - //while it was still inserted in a container that is alive. - //If so, remove the object from the container before destroying it. - (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked()); -} - -template<class Hook> -void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>) -{ hook.unlink(); } - -template<class Hook> -void destructor_impl(Hook &, detail::link_dispatch<normal_link>) -{} - -template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, int HookType> -struct base_hook_traits -{ - public: - typedef detail::node_holder - <typename NodeTraits::node, Tag, LinkMode, HookType> node_holder; - typedef typename NodeTraits::node node; - typedef NodeTraits node_traits; - typedef T value_type; - typedef typename node_traits::node_ptr node_ptr; - typedef typename node_traits::const_node_ptr const_node_ptr; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<T>::type pointer; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<const T>::type const_pointer; - //typedef typename pointer_traits<pointer>::reference reference; - //typedef typename pointer_traits<const_pointer>::reference const_reference; - typedef T & reference; - typedef const T & const_reference; - typedef node_holder & node_holder_reference; - typedef const node_holder & const_node_holder_reference; - typedef node& node_reference; - typedef const node & const_node_reference; - - static const link_mode_type link_mode = LinkMode; - - static pointer to_value_ptr(const node_ptr & n) - { - return pointer_traits<pointer>::pointer_to - (static_cast<reference>(static_cast<node_holder_reference>(*n))); - } - - static const_pointer to_value_ptr(const const_node_ptr & n) - { - return pointer_traits<const_pointer>::pointer_to - (static_cast<const_reference>(static_cast<const_node_holder_reference>(*n))); - } - - static node_ptr to_node_ptr(reference value) - { - return pointer_traits<node_ptr>::pointer_to - (static_cast<node_reference>(static_cast<node_holder_reference>(value))); - } - - static const_node_ptr to_node_ptr(const_reference value) - { - return pointer_traits<const_node_ptr>::pointer_to - (static_cast<const_node_reference>(static_cast<const_node_holder_reference>(value))); - } -}; - -template<class T, class Hook, Hook T::* P> -struct member_hook_traits -{ - public: - typedef Hook hook_type; - typedef typename hook_type::boost_intrusive_tags::node_traits node_traits; - typedef typename node_traits::node node; - typedef T value_type; - typedef typename node_traits::node_ptr node_ptr; - typedef typename node_traits::const_node_ptr const_node_ptr; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<T>::type pointer; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<const T>::type const_pointer; - typedef T & reference; - typedef const T & const_reference; - typedef node& node_reference; - typedef const node & const_node_reference; - typedef hook_type& hook_reference; - typedef const hook_type & const_hook_reference; - - static const link_mode_type link_mode = Hook::boost_intrusive_tags::link_mode; - - static node_ptr to_node_ptr(reference value) - { - return pointer_traits<node_ptr>::pointer_to - (static_cast<node_reference>(static_cast<hook_reference>(value.*P))); - } - - static const_node_ptr to_node_ptr(const_reference value) - { - return pointer_traits<const_node_ptr>::pointer_to - (static_cast<const_node_reference>(static_cast<const_hook_reference>(value.*P))); - } - - static pointer to_value_ptr(const node_ptr & n) - { - return pointer_traits<pointer>::pointer_to - (*detail::parent_from_member<T, Hook> - (static_cast<Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P)); - } - - static const_pointer to_value_ptr(const const_node_ptr & n) - { - return pointer_traits<const_pointer>::pointer_to - (*detail::parent_from_member<T, Hook> - (static_cast<const Hook*>(boost::intrusive::detail::to_raw_pointer(n)), P)); - } -}; - -template<class Functor> -struct function_hook_traits -{ - public: - typedef typename Functor::hook_type hook_type; - typedef typename Functor::hook_ptr hook_ptr; - typedef typename Functor::const_hook_ptr const_hook_ptr; - typedef typename hook_type::boost_intrusive_tags::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename Functor::value_type value_type; - typedef typename node_traits::node_ptr node_ptr; - typedef typename node_traits::const_node_ptr const_node_ptr; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<value_type>::type pointer; - typedef typename pointer_traits<node_ptr>:: - template rebind_pointer<const value_type>::type const_pointer; - typedef value_type & reference; - typedef const value_type & const_reference; - static const link_mode_type link_mode = hook_type::boost_intrusive_tags::link_mode; - - static node_ptr to_node_ptr(reference value) - { return static_cast<node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } - - static const_node_ptr to_node_ptr(const_reference value) - { return static_cast<const node*>(boost::intrusive::detail::to_raw_pointer(Functor::to_hook_ptr(value))); } - - static pointer to_value_ptr(const node_ptr & n) - { return Functor::to_value_ptr(to_hook_ptr(n)); } - - static const_pointer to_value_ptr(const const_node_ptr & n) - { return Functor::to_value_ptr(to_hook_ptr(n)); } - - private: - static hook_ptr to_hook_ptr(const node_ptr & n) - { return hook_ptr(&*static_cast<hook_type*>(&*n)); } - - static const_hook_ptr to_hook_ptr(const const_node_ptr & n) - { return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); } -}; - - -//This function uses binary search to discover the -//highest set bit of the integer -inline std::size_t floor_log2 (std::size_t x) -{ - const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT; - const bool Size_t_Bits_Power_2= !(Bits & (Bits-1)); - BOOST_STATIC_ASSERT(Size_t_Bits_Power_2); - - std::size_t n = x; - std::size_t log2 = 0; - - for(std::size_t shift = Bits >> 1; shift; shift >>= 1){ - std::size_t tmp = n >> shift; - if (tmp) - log2 += shift, n = tmp; - } - - return log2; -} - -inline float fast_log2 (float val) -{ - union caster_t - { - boost::uint32_t x; - float val; - } caster; - - caster.val = val; - boost::uint32_t x = caster.x; - const int log_2 = (int)(((x >> 23) & 255) - 128); - x &= ~(255 << 23); - x += 127 << 23; - caster.x = x; - val = caster.val; - val = ((-1.0f/3.f) * val + 2.f) * val - (2.0f/3.f); - - return (val + log_2); -} - -inline std::size_t ceil_log2 (std::size_t x) -{ - return ((x & (x-1))!= 0) + floor_log2(x); -} - -template<class SizeType, std::size_t N> -struct numbits_eq -{ - static const bool value = sizeof(SizeType)*CHAR_BIT == N; -}; - -template<class SizeType, class Enabler = void > -struct sqrt2_pow_max; - -template <class SizeType> -struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 32> >::type> -{ - static const boost::uint32_t value = 0xb504f334; - static const std::size_t pow = 31; -}; - -template <class SizeType> -struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 64> >::type> -{ - static const boost::uint64_t value = 0xb504f333f9de6484ull; - static const std::size_t pow = 63; -}; - -// Returns floor(pow(sqrt(2), x * 2 + 1)). -// Defined for X from 0 up to the number of bits in size_t minus 1. -inline std::size_t sqrt2_pow_2xplus1 (std::size_t x) -{ - const std::size_t value = (std::size_t)sqrt2_pow_max<std::size_t>::value; - const std::size_t pow = (std::size_t)sqrt2_pow_max<std::size_t>::pow; - return (value >> (pow - x)) + 1; -} - -template<class Container, class Disposer> -class exception_disposer -{ - Container *cont_; - Disposer &disp_; - - exception_disposer(const exception_disposer&); - exception_disposer &operator=(const exception_disposer&); - - public: - exception_disposer(Container &cont, Disposer &disp) - : cont_(&cont), disp_(disp) - {} - - void release() - { cont_ = 0; } - - ~exception_disposer() - { - if(cont_){ - cont_->clear_and_dispose(disp_); - } - } -}; - -template<class Container, class Disposer, class SizeType> -class exception_array_disposer -{ - Container *cont_; - Disposer &disp_; - SizeType &constructed_; - - exception_array_disposer(const exception_array_disposer&); - exception_array_disposer &operator=(const exception_array_disposer&); - - public: - - exception_array_disposer - (Container &cont, Disposer &disp, SizeType &constructed) - : cont_(&cont), disp_(disp), constructed_(constructed) - {} - - void release() - { cont_ = 0; } - - ~exception_array_disposer() - { - SizeType n = constructed_; - if(cont_){ - while(n--){ - cont_[n].clear_and_dispose(disp_); - } - } - } -}; - -template<class ValueTraits, bool ExternalValueTraits> -struct store_cont_ptr_on_it_impl -{ - static const bool value = is_stateful_value_traits<ValueTraits>::value; -}; - -template<class ValueTraits> -struct store_cont_ptr_on_it_impl<ValueTraits, true> -{ - static const bool value = true; -}; - -template <class Container> -struct store_cont_ptr_on_it -{ - typedef typename Container::value_traits value_traits; - static const bool value = store_cont_ptr_on_it_impl - <value_traits, external_value_traits_is_true<value_traits>::value>::value; -}; - -template<class Container, bool IsConst> -struct node_to_value - : public detail::select_constptr - < typename pointer_traits - <typename Container::pointer>::template rebind_pointer<void>::type - , detail::store_cont_ptr_on_it<Container>::value - >::type -{ - static const bool store_container_ptr = - detail::store_cont_ptr_on_it<Container>::value; - - typedef typename Container::real_value_traits real_value_traits; - typedef typename real_value_traits::value_type value_type; - typedef typename detail::select_constptr - < typename pointer_traits - <typename Container::pointer>::template rebind_pointer<void>::type - , store_container_ptr >::type Base; - typedef typename real_value_traits::node_traits::node node; - typedef typename detail::add_const_if_c - <value_type, IsConst>::type vtype; - typedef typename detail::add_const_if_c - <node, IsConst>::type ntype; - typedef typename pointer_traits - <typename Container::pointer>::template rebind_pointer<ntype>::type npointer; - - node_to_value(const Container *cont) - : Base(cont) - {} - - typedef vtype & result_type; - typedef ntype & first_argument_type; - - const Container *get_container() const - { - if(store_container_ptr) - return static_cast<const Container*>(Base::get_ptr()); - else - return 0; - } - - const real_value_traits *get_real_value_traits() const - { - if(store_container_ptr) - return &this->get_container()->get_real_value_traits(); - else - return 0; - } - - result_type operator()(first_argument_type arg) const - { - return *(this->get_real_value_traits()->to_value_ptr - (pointer_traits<npointer>::pointer_to(arg))); - } -}; - -//This is not standard, but should work with all compilers -union max_align -{ - char char_; - short short_; - int int_; - long long_; - #ifdef BOOST_HAS_LONG_LONG - long long long_long_; - #endif - float float_; - double double_; - long double long_double_; - void * void_ptr_; -}; - -template<class T, std::size_t N> -class array_initializer -{ - public: - template<class CommonInitializer> - array_initializer(const CommonInitializer &init) - { - char *init_buf = (char*)rawbuf; - std::size_t i = 0; - try{ - for(; i != N; ++i){ - new(init_buf)T(init); - init_buf += sizeof(T); - } - } - catch(...){ - while(i--){ - init_buf -= sizeof(T); - ((T*)init_buf)->~T(); - } - throw; - } - } - - operator T* () - { return (T*)(rawbuf); } - - operator const T*() const - { return (const T*)(rawbuf); } - - ~array_initializer() - { - char *init_buf = (char*)rawbuf + N*sizeof(T); - for(std::size_t i = 0; i != N; ++i){ - init_buf -= sizeof(T); - ((T*)init_buf)->~T(); - } - } - - private: - detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1]; -}; - - - - -template<class It> -class reverse_iterator - : public std::iterator< - typename std::iterator_traits<It>::iterator_category, - typename std::iterator_traits<It>::value_type, - typename std::iterator_traits<It>::difference_type, - typename std::iterator_traits<It>::pointer, - typename std::iterator_traits<It>::reference> -{ - public: - typedef typename std::iterator_traits<It>::pointer pointer; - typedef typename std::iterator_traits<It>::reference reference; - typedef typename std::iterator_traits<It>::difference_type difference_type; - typedef It iterator_type; - - reverse_iterator(){} - - explicit reverse_iterator(It r) - : m_current(r) - {} - - template<class OtherIt> - reverse_iterator(const reverse_iterator<OtherIt>& r) - : m_current(r.base()) - {} - - It base() const - { return m_current; } - - reference operator*() const - { It temp(m_current); --temp; return *temp; } - - pointer operator->() const - { It temp(m_current); --temp; return temp.operator->(); } - - reference operator[](difference_type off) const - { return this->m_current[-off]; } - - reverse_iterator& operator++() - { --m_current; return *this; } - - reverse_iterator operator++(int) - { - reverse_iterator temp = *this; - --m_current; - return temp; - } - - reverse_iterator& operator--() - { - ++m_current; - return *this; - } - - reverse_iterator operator--(int) - { - reverse_iterator temp(*this); - ++m_current; - return temp; - } - - friend bool operator==(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current == r.m_current; } - - friend bool operator!=(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current != r.m_current; } - - friend bool operator<(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current < r.m_current; } - - friend bool operator<=(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current <= r.m_current; } - - friend bool operator>(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current > r.m_current; } - - friend bool operator>=(const reverse_iterator& l, const reverse_iterator& r) - { return l.m_current >= r.m_current; } - - reverse_iterator& operator+=(difference_type off) - { m_current -= off; return *this; } - - friend reverse_iterator operator+(const reverse_iterator & l, difference_type off) - { - reverse_iterator tmp(l.m_current); - tmp.m_current -= off; - return tmp; - } - - reverse_iterator& operator-=(difference_type off) - { m_current += off; return *this; } - - friend reverse_iterator operator-(const reverse_iterator & l, difference_type off) - { - reverse_iterator tmp(l.m_current); - tmp.m_current += off; - return tmp; - } - - friend difference_type operator-(const reverse_iterator& l, const reverse_iterator& r) - { return r.m_current - l.m_current; } - - private: - It m_current; // the wrapped iterator -}; - -} //namespace detail -} //namespace intrusive -} //namespace boost - -#include <boost/intrusive/detail/config_end.hpp> - -#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP diff --git a/boost/intrusive/detail/workaround.hpp b/boost/intrusive/detail/workaround.hpp index 87cab4befc..ad00691f25 100644 --- a/boost/intrusive/detail/workaround.hpp +++ b/boost/intrusive/detail/workaround.hpp @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -11,12 +11,20 @@ #ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP #define BOOST_INTRUSIVE_DETAIL_WRKRND_HPP -#include <boost/intrusive/detail/config_begin.hpp> +#if defined(_MSC_VER) +# pragma once +#endif + +#ifndef BOOST_CONFIG_HPP +#include <boost/config.hpp> +#endif -#if !defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_NO_VARIADIC_TEMPLATES) +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #define BOOST_INTRUSIVE_PERFECT_FORWARDING #endif -#include <boost/intrusive/detail/config_end.hpp> +//Macros for documentation purposes. For code, expands to the argument +#define BOOST_INTRUSIVE_IMPDEF(TYPE) TYPE +#define BOOST_INTRUSIVE_SEEDOC(TYPE) TYPE #endif //#ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP diff --git a/boost/intrusive/hashtable.hpp b/boost/intrusive/hashtable.hpp index 2435a083c3..af73f70629 100644 --- a/boost/intrusive/hashtable.hpp +++ b/boost/intrusive/hashtable.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,7 +12,12 @@ #ifndef BOOST_INTRUSIVE_HASHTABLE_HPP #define BOOST_INTRUSIVE_HASHTABLE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> //std C++ #include <functional> //std::equal_to #include <utility> //std::pair @@ -22,30 +27,94 @@ #include <boost/intrusive/detail/assert.hpp> #include <boost/static_assert.hpp> #include <boost/functional/hash.hpp> -#include <boost/pointer_cast.hpp> //General intrusive utilities -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/hashtable_node.hpp> #include <boost/intrusive/detail/transform_iterator.hpp> #include <boost/intrusive/link_mode.hpp> #include <boost/intrusive/detail/ebo_functor_holder.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> -#include <boost/intrusive/detail/utilities.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> +#include <boost/intrusive/detail/node_to_value.hpp> +#include <boost/intrusive/detail/exception_disposer.hpp> +#include <boost/intrusive/detail/node_cloner_disposer.hpp> +#include <boost/intrusive/detail/simple_disposers.hpp> +#include <boost/intrusive/detail/size_holder.hpp> + //Implementation utilities -#include <boost/intrusive/trivial_value_traits.hpp> #include <boost/intrusive/unordered_set_hook.hpp> #include <boost/intrusive/slist.hpp> #include <boost/intrusive/pointer_traits.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/type_traits.hpp> -#include <boost/move/move.hpp> +#include <boost/move/utility_core.hpp> namespace boost { namespace intrusive { /// @cond -namespace detail { +template<int Dummy = 0> +struct prime_list_holder +{ + static const std::size_t prime_list[]; + static const std::size_t prime_list_size; +}; + +//We only support LLP64(Win64) or LP64(most Unix) data models +#ifdef _WIN64 //In 64 bit windows sizeof(size_t) == sizeof(unsigned long long) + #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##ULL + #define BOOST_INTRUSIVE_64_BIT_SIZE_T 1 +#else //In 32 bit windows and 32/64 bit unixes sizeof(size_t) == sizeof(unsigned long) + #define BOOST_INTRUSIVE_PRIME_C(NUMBER) NUMBER##UL + #define BOOST_INTRUSIVE_64_BIT_SIZE_T (((((ULONG_MAX>>16)>>16)>>16)>>15) != 0) +#endif + +template<int Dummy> +const std::size_t prime_list_holder<Dummy>::prime_list[] = { + BOOST_INTRUSIVE_PRIME_C(3), BOOST_INTRUSIVE_PRIME_C(7), + BOOST_INTRUSIVE_PRIME_C(11), BOOST_INTRUSIVE_PRIME_C(17), + BOOST_INTRUSIVE_PRIME_C(29), BOOST_INTRUSIVE_PRIME_C(53), + BOOST_INTRUSIVE_PRIME_C(97), BOOST_INTRUSIVE_PRIME_C(193), + BOOST_INTRUSIVE_PRIME_C(389), BOOST_INTRUSIVE_PRIME_C(769), + BOOST_INTRUSIVE_PRIME_C(1543), BOOST_INTRUSIVE_PRIME_C(3079), + BOOST_INTRUSIVE_PRIME_C(6151), BOOST_INTRUSIVE_PRIME_C(12289), + BOOST_INTRUSIVE_PRIME_C(24593), BOOST_INTRUSIVE_PRIME_C(49157), + BOOST_INTRUSIVE_PRIME_C(98317), BOOST_INTRUSIVE_PRIME_C(196613), + BOOST_INTRUSIVE_PRIME_C(393241), BOOST_INTRUSIVE_PRIME_C(786433), + BOOST_INTRUSIVE_PRIME_C(1572869), BOOST_INTRUSIVE_PRIME_C(3145739), + BOOST_INTRUSIVE_PRIME_C(6291469), BOOST_INTRUSIVE_PRIME_C(12582917), + BOOST_INTRUSIVE_PRIME_C(25165843), BOOST_INTRUSIVE_PRIME_C(50331653), + BOOST_INTRUSIVE_PRIME_C(100663319), BOOST_INTRUSIVE_PRIME_C(201326611), + BOOST_INTRUSIVE_PRIME_C(402653189), BOOST_INTRUSIVE_PRIME_C(805306457), + BOOST_INTRUSIVE_PRIME_C(1610612741), BOOST_INTRUSIVE_PRIME_C(3221225473), +#if BOOST_INTRUSIVE_64_BIT_SIZE_T + //Taken from Boost.MultiIndex code, thanks to Joaquin M Lopez Munoz. + BOOST_INTRUSIVE_PRIME_C(6442450939), BOOST_INTRUSIVE_PRIME_C(12884901893), + BOOST_INTRUSIVE_PRIME_C(25769803751), BOOST_INTRUSIVE_PRIME_C(51539607551), + BOOST_INTRUSIVE_PRIME_C(103079215111), BOOST_INTRUSIVE_PRIME_C(206158430209), + BOOST_INTRUSIVE_PRIME_C(412316860441), BOOST_INTRUSIVE_PRIME_C(824633720831), + BOOST_INTRUSIVE_PRIME_C(1649267441651), BOOST_INTRUSIVE_PRIME_C(3298534883309), + BOOST_INTRUSIVE_PRIME_C(6597069766657), BOOST_INTRUSIVE_PRIME_C(13194139533299), + BOOST_INTRUSIVE_PRIME_C(26388279066623), BOOST_INTRUSIVE_PRIME_C(52776558133303), + BOOST_INTRUSIVE_PRIME_C(105553116266489), BOOST_INTRUSIVE_PRIME_C(211106232532969), + BOOST_INTRUSIVE_PRIME_C(422212465066001), BOOST_INTRUSIVE_PRIME_C(844424930131963), + BOOST_INTRUSIVE_PRIME_C(1688849860263953), BOOST_INTRUSIVE_PRIME_C(3377699720527861), + BOOST_INTRUSIVE_PRIME_C(6755399441055731), BOOST_INTRUSIVE_PRIME_C(13510798882111483), + BOOST_INTRUSIVE_PRIME_C(27021597764222939), BOOST_INTRUSIVE_PRIME_C(54043195528445957), + BOOST_INTRUSIVE_PRIME_C(108086391056891903), BOOST_INTRUSIVE_PRIME_C(216172782113783843), + BOOST_INTRUSIVE_PRIME_C(432345564227567621), BOOST_INTRUSIVE_PRIME_C(864691128455135207), + BOOST_INTRUSIVE_PRIME_C(1729382256910270481), BOOST_INTRUSIVE_PRIME_C(3458764513820540933), + BOOST_INTRUSIVE_PRIME_C(6917529027641081903), BOOST_INTRUSIVE_PRIME_C(13835058055282163729), + BOOST_INTRUSIVE_PRIME_C(18446744073709551557) +#else + BOOST_INTRUSIVE_PRIME_C(4294967291) +#endif + }; + +#undef BOOST_INTRUSIVE_PRIME_C +#undef BOOST_INTRUSIVE_64_BIT_SIZE_T + +template<int Dummy> +const std::size_t prime_list_holder<Dummy>::prime_list_size + = sizeof(prime_list)/sizeof(std::size_t); struct hash_bool_flags { @@ -57,101 +126,14 @@ struct hash_bool_flags static const std::size_t incremental_pos = 32u; }; -template - < class ValueTraits - , class Hash - , class Equal - , class SizeType - , class BucketTraits - , std::size_t BoolFlags - > -struct usetopt -{ - typedef ValueTraits value_traits; - typedef Hash hash; - typedef Equal equal; - typedef SizeType size_type; - typedef BucketTraits bucket_traits; - static const std::size_t bool_flags = BoolFlags; -}; - -template - < class UsetOpt - , std::size_t BoolMask - > -struct usetopt_mask -{ - typedef usetopt - <typename UsetOpt::value_traits - ,typename UsetOpt::hash - ,typename UsetOpt::equal - ,typename UsetOpt::size_type - ,typename UsetOpt::bucket_traits - ,UsetOpt::bool_flags & BoolMask - > type; -}; - -template <class NodeTraits> -struct hash_reduced_slist_node_traits -{ - template <class U> static detail::one test(...); - template <class U> static detail::two test(typename U::reduced_slist_node_traits* = 0); - static const bool value = sizeof(test<NodeTraits>(0)) == sizeof(detail::two); -}; - -template <class NodeTraits> -struct apply_reduced_slist_node_traits -{ - typedef typename NodeTraits::reduced_slist_node_traits type; -}; - -template <class NodeTraits> -struct reduced_slist_node_traits -{ - typedef typename detail::eval_if_c - < hash_reduced_slist_node_traits<NodeTraits>::value - , apply_reduced_slist_node_traits<NodeTraits> - , detail::identity<NodeTraits> - >::type type; -}; - -template<class NodeTraits> -struct get_slist_impl -{ - typedef trivial_value_traits<NodeTraits, normal_link> trivial_traits; - - //Reducing symbol length - struct type : make_slist - < typename NodeTraits::node - , boost::intrusive::value_traits<trivial_traits> - , boost::intrusive::constant_time_size<false> - , boost::intrusive::size_type<typename boost::make_unsigned - <typename pointer_traits<typename NodeTraits::node_ptr>::difference_type>::type > - >::type - {}; -}; - -template<class SupposedValueTraits> -struct real_from_supposed_value_traits -{ - typedef typename detail::eval_if_c - < detail::external_value_traits_is_true - <SupposedValueTraits>::value - , detail::eval_value_traits - <SupposedValueTraits> - , detail::identity - <SupposedValueTraits> - >::type type; -}; +namespace detail { template<class SupposedValueTraits> struct get_slist_impl_from_supposed_value_traits { - typedef typename - real_from_supposed_value_traits - < SupposedValueTraits>::type real_value_traits; + typedef SupposedValueTraits value_traits; typedef typename detail::get_node_traits - <real_value_traits>::type node_traits; + <value_traits>::type node_traits; typedef typename get_slist_impl <typename reduced_slist_node_traits <node_traits>::type @@ -214,135 +196,19 @@ struct optimize_multikey_is_true static const bool value = optimize_multikey_bool<T>::value > sizeof(one)*2; }; -template<class Config> -struct bucket_plus_size - : public detail::size_holder //size_traits - < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos) - , typename Config::size_type> -{ - typedef detail::size_holder - < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos) - , typename Config::size_type> size_traits; - typedef typename Config::bucket_traits bucket_traits; - - template<class BucketTraits> - bucket_plus_size(BOOST_FWD_REF(BucketTraits) b_traits) - : bucket_traits_(::boost::forward<BucketTraits>(b_traits)) - {} - - bucket_plus_size & operator =(const bucket_plus_size &x) - { - this->size_traits::operator=(x); - bucket_traits_ = x.bucket_traits_; - return *this; - } - bucket_traits bucket_traits_; -}; - -template<class Config> -struct bucket_hash_t - : public detail::ebo_functor_holder<typename Config::hash> //hash -{ - typedef typename Config::hash hasher; - typedef detail::size_holder - < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos) - , typename Config::size_type> size_traits; - typedef typename Config::bucket_traits bucket_traits; - - template<class BucketTraits> - bucket_hash_t(BOOST_FWD_REF(BucketTraits) b_traits, const hasher & h) - : detail::ebo_functor_holder<hasher>(h), bucket_plus_size_(::boost::forward<BucketTraits>(b_traits)) - {} - - bucket_plus_size<Config> bucket_plus_size_; -}; - -template<class Config, bool> -struct bucket_hash_equal_t - : public detail::ebo_functor_holder<typename Config::equal> -{ - typedef typename Config::equal equal; - typedef typename Config::hash hasher; - typedef typename Config::bucket_traits bucket_traits; - - template<class BucketTraits> - bucket_hash_equal_t(BOOST_FWD_REF(BucketTraits) b_traits, const hasher & h, const equal &e) - : detail::ebo_functor_holder<typename Config::equal>(e)//equal() - , bucket_hash(::boost::forward<BucketTraits>(b_traits), h) - {} - - template<class T> - void set_cache(T) - {} - - bucket_hash_t<Config> bucket_hash; -}; - -template<class Config> //cache_begin == true version -struct bucket_hash_equal_t<Config, true> - : public detail::ebo_functor_holder<typename Config::equal> -{ - typedef typename Config::equal equal; - typedef typename Config::hash hasher; - typedef typename Config::bucket_traits bucket_traits; - typedef typename unordered_bucket_ptr_impl - <typename Config::value_traits>::type bucket_ptr; - - template<class BucketTraits> - bucket_hash_equal_t(BOOST_FWD_REF(BucketTraits) b_traits, const hasher & h, const equal &e) - : detail::ebo_functor_holder<typename Config::equal>(e) //equal() - , bucket_hash(::boost::forward<BucketTraits>(b_traits), h) - {} - - void set_cache(const bucket_ptr & c) - { cached_begin_ = c; } - - bucket_hash_t<Config> bucket_hash; - bucket_ptr cached_begin_; -}; - -template<class Config> -struct hashtable_data_t : public Config::value_traits -{ - static const std::size_t bool_flags = Config::bool_flags; - typedef typename Config::value_traits value_traits; - typedef typename Config::equal equal; - typedef typename Config::hash hasher; - typedef typename Config::bucket_traits bucket_traits; - - template<class BucketTraits> - hashtable_data_t( BOOST_FWD_REF(BucketTraits) b_traits, const hasher & h - , const equal &e, const value_traits &val_traits) - : Config::value_traits(val_traits) //value_traits - , internal_(::boost::forward<BucketTraits>(b_traits), h, e) - {} - typedef typename detail::usetopt_mask - < Config - , detail::hash_bool_flags::constant_time_size_pos - | detail::hash_bool_flags::incremental_pos - >::type masked_config_t; - struct internal - : public detail::size_holder //split_traits - < 0 != (Config::bool_flags & hash_bool_flags::incremental_pos) - , typename Config::size_type> - { - template<class BucketTraits> - internal(BOOST_FWD_REF(BucketTraits) b_traits, const hasher & h, const equal &e) - : bucket_hash_equal_(::boost::forward<BucketTraits>(b_traits), h, e) - {} - - bucket_hash_equal_t - < masked_config_t - , 0 != (bool_flags & hash_bool_flags::cache_begin_pos) - > bucket_hash_equal_; - } internal_; -}; - struct insert_commit_data_impl { std::size_t hash; }; +template<class Node, class SlistNodePtr> +inline typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type + dcast_bucket_ptr(const SlistNodePtr &p) +{ + typedef typename pointer_traits<SlistNodePtr>::template rebind_pointer<Node>::type node_ptr; + return pointer_traits<node_ptr>::pointer_to(static_cast<Node&>(*p)); +} + template<class NodeTraits> struct group_functions { @@ -356,9 +222,6 @@ struct group_functions typedef typename reduced_node_traits::node slist_node; typedef circular_slist_algorithms<group_traits> group_algorithms; - static node_ptr dcast_bucket_ptr(const slist_node_ptr &p) - { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*p)); } - static slist_node_ptr get_bucket_before_begin (const slist_node_ptr &bucket_beg, const slist_node_ptr &bucket_end, const node_ptr &p) { @@ -384,7 +247,7 @@ struct group_functions slist_node_ptr possible_end = node_traits::get_next(last_node_group); while(!(bucket_beg <= possible_end && possible_end <= bucket_end)){ - first_node_of_group = dcast_bucket_ptr(possible_end); + first_node_of_group = detail::dcast_bucket_ptr<node>(possible_end); last_node_group = group_traits::get_next(first_node_of_group); possible_end = node_traits::get_next(last_node_group); } @@ -395,7 +258,7 @@ struct group_functions { //Just iterate using group links and obtain the node //before "first_in_group)" - node_ptr prev_node = dcast_bucket_ptr(bucket_node); + node_ptr prev_node = detail::dcast_bucket_ptr<node>(bucket_node); node_ptr nxt(node_traits::get_next(prev_node)); while(nxt != first_in_group){ prev_node = group_traits::get_next(nxt); @@ -426,12 +289,12 @@ struct group_functions node_ptr prev_in_group_ptr(group_traits::get_next(to_erase_ptr)); bool last_in_group = (end_ptr == nxt_ptr) || (group_traits::get_next(nxt_ptr) != to_erase_ptr); - bool first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr; + bool is_first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr; - if(first_in_group && last_in_group){ + if(is_first_in_group && last_in_group){ group_algorithms::init(to_erase_ptr); } - else if(first_in_group){ + else if(is_first_in_group){ group_algorithms::unlink_after(nxt_ptr); } else if(last_in_group){ @@ -465,7 +328,7 @@ struct group_functions if(group_algorithms::unique(first_in_group)) group_algorithms::link_after(first_in_group, n); else{ - group_algorithms::link_after(group_algorithms::node_traits::get_next(first_in_group), n); + group_algorithms::link_after(node_traits::get_next(first_in_group), n); } } else{ @@ -480,12 +343,12 @@ struct group_functions , const slist_node_ptr &first_end_ptr, const slist_node_ptr &last_end_ptr) { slist_node_ptr prev; - node_ptr elem(dcast_bucket_ptr(i)); + node_ptr elem(detail::dcast_bucket_ptr<node>(i)); //It's the last in group if the next_node is a bucket slist_node_ptr nxt(node_traits::get_next(elem)); - bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr)/* || - (group_traits::get_next(nxt) != elem)*/; + bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr) || + (group_traits::get_next(detail::dcast_bucket_ptr<node>(nxt)) != elem); //It's the first in group if group_previous's next_node is not //itself, as group list does not link bucket node_ptr prev_in_group(group_traits::get_next(elem)); @@ -575,6 +438,22 @@ struct node_functions {} }; +inline std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::false_) +{ return hash_value % bucket_cnt; } + +inline std::size_t hash_to_bucket(std::size_t hash_value, std::size_t bucket_cnt, detail::true_) +{ return hash_value & (bucket_cnt - 1); } + +template<bool Power2Buckets, bool Incremental> +inline std::size_t hash_to_bucket_split(std::size_t hash_value, std::size_t bucket_cnt, std::size_t split) +{ + std::size_t bucket_number = detail::hash_to_bucket(hash_value, bucket_cnt, detail::bool_<Power2Buckets>()); + if(Incremental) + if(bucket_number >= split) + bucket_number -= bucket_cnt/2; + return bucket_number; +} + } //namespace detail { //!This metafunction will obtain the type of a bucket @@ -584,7 +463,7 @@ template<class ValueTraitsOrHookOption> struct unordered_bucket : public detail::unordered_bucket_impl <typename ValueTraitsOrHookOption:: - template pack<none>::value_traits + template pack<empty>::proto_value_traits > {}; @@ -593,10 +472,10 @@ struct unordered_bucket //!a hash container. template<class ValueTraitsOrHookOption> struct unordered_bucket_ptr - : public detail::unordered_bucket_ptr_impl - <typename ValueTraitsOrHookOption:: - template pack<none>::value_traits - > + : public detail::unordered_bucket_ptr_impl + <typename ValueTraitsOrHookOption:: + template pack<empty>::proto_value_traits + > {}; //!This metafunction will obtain the type of the default bucket traits @@ -607,7 +486,7 @@ template<class ValueTraitsOrHookOption> struct unordered_default_bucket_traits { typedef typename ValueTraitsOrHookOption:: - template pack<none>::value_traits supposed_value_traits; + template pack<empty>::proto_value_traits supposed_value_traits; typedef typename detail:: get_slist_impl_from_supposed_value_traits <supposed_value_traits>::type slist_impl; @@ -618,28 +497,640 @@ struct unordered_default_bucket_traits struct default_bucket_traits; -template <class T> -struct uset_defaults - : pack_options - < none - , base_hook<detail::default_uset_hook> - , constant_time_size<true> - , size_type<std::size_t> - , equal<std::equal_to<T> > - , hash<boost::hash<T> > - , bucket_traits<default_bucket_traits> - , power_2_buckets<false> - , cache_begin<false> - , compare_hash<false> - , incremental<false> - >::type -{}; +//hashtable default hook traits +struct default_hashtable_hook_applier +{ template <class T> struct apply{ typedef typename T::default_hashtable_hook type; }; }; + +template<> +struct is_default_hook_tag<default_hashtable_hook_applier> +{ static const bool value = true; }; + +struct hashtable_defaults +{ + typedef default_hashtable_hook_applier proto_value_traits; + typedef std::size_t size_type; + typedef void equal; + typedef void hash; + typedef default_bucket_traits bucket_traits; + static const bool constant_time_size = true; + static const bool power_2_buckets = false; + static const bool cache_begin = false; + static const bool compare_hash = false; + static const bool incremental = false; +}; + +template<class ValueTraits, bool IsConst> +struct downcast_node_to_value_t + : public detail::node_to_value<ValueTraits, IsConst> +{ + typedef detail::node_to_value<ValueTraits, IsConst> base_t; + typedef typename base_t::result_type result_type; + typedef ValueTraits value_traits; + typedef typename detail::get_slist_impl + <typename detail::reduced_slist_node_traits + <typename value_traits::node_traits>::type + >::type slist_impl; + typedef typename detail::add_const_if_c + <typename slist_impl::node, IsConst>::type & first_argument_type; + typedef typename detail::add_const_if_c + < typename ValueTraits::node_traits::node + , IsConst>::type & intermediate_argument_type; + typedef typename pointer_traits + <typename ValueTraits::pointer>:: + template rebind_pointer + <const ValueTraits>::type const_value_traits_ptr; + + downcast_node_to_value_t(const const_value_traits_ptr &ptr) + : base_t(ptr) + {} + + result_type operator()(first_argument_type arg) const + { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); } +}; + +template<class F, class SlistNodePtr, class NodePtr> +struct node_cast_adaptor + : private detail::ebo_functor_holder<F> +{ + typedef detail::ebo_functor_holder<F> base_t; + + typedef typename pointer_traits<SlistNodePtr>::element_type slist_node; + typedef typename pointer_traits<NodePtr>::element_type node; + + template<class ConvertibleToF, class RealValuTraits> + node_cast_adaptor(const ConvertibleToF &c2f, const RealValuTraits *traits) + : base_t(base_t(c2f, traits)) + {} + + typename base_t::node_ptr operator()(const slist_node &to_clone) + { return base_t::operator()(static_cast<const node &>(to_clone)); } + + void operator()(SlistNodePtr to_clone) + { + base_t::operator()(pointer_traits<NodePtr>::pointer_to(static_cast<node &>(*to_clone))); + } +}; + +static const std::size_t hashtable_data_bool_flags_mask = + ( hash_bool_flags::cache_begin_pos + | hash_bool_flags::constant_time_size_pos + | hash_bool_flags::incremental_pos + ); + +//bucket_plus_vtraits stores ValueTraits + BucketTraits +//this data is needed by iterators to obtain the +//value from the iterator and detect the bucket +template<class ValueTraits, class BucketTraits> +struct bucket_plus_vtraits : public ValueTraits +{ + typedef BucketTraits bucket_traits; + typedef ValueTraits value_traits; + + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; + + typedef typename + detail::get_slist_impl_from_supposed_value_traits + <value_traits>::type slist_impl; + typedef typename value_traits::node_traits node_traits; + typedef unordered_group_adapter<node_traits> group_traits; + typedef typename slist_impl::iterator siterator; + typedef typename slist_impl::size_type size_type; + typedef detail::bucket_impl<slist_impl> bucket_type; + typedef detail::group_functions<node_traits> group_functions_t; + typedef typename slist_impl::node_algorithms node_algorithms; + typedef typename slist_impl::node_ptr slist_node_ptr; + typedef typename node_traits::node_ptr node_ptr; + typedef typename node_traits::node node; + typedef typename value_traits::value_type value_type; + typedef circular_slist_algorithms<group_traits> group_algorithms; + typedef typename pointer_traits + <typename value_traits::pointer>:: + template rebind_pointer + <const value_traits>::type const_value_traits_ptr; + typedef typename pointer_traits + <typename value_traits::pointer>:: + template rebind_pointer + <const bucket_plus_vtraits>::type const_bucket_value_traits_ptr; + typedef typename detail::unordered_bucket_ptr_impl + <value_traits>::type bucket_ptr; + typedef detail::bool_<detail::optimize_multikey_is_true + <node_traits>::value> optimize_multikey_t; + + template<class BucketTraitsType> + bucket_plus_vtraits(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits) + : ValueTraits(val_traits), bucket_traits_(::boost::forward<BucketTraitsType>(b_traits)) + {} + + bucket_plus_vtraits & operator =(const bucket_plus_vtraits &x) + { bucket_traits_ = x.bucket_traits_; return *this; } + + const_value_traits_ptr priv_value_traits_ptr() const + { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); } + + //bucket_value_traits + // + const bucket_plus_vtraits &get_bucket_value_traits() const + { return *this; } + + bucket_plus_vtraits &get_bucket_value_traits() + { return *this; } + + const_bucket_value_traits_ptr bucket_value_traits_ptr() const + { return pointer_traits<const_bucket_value_traits_ptr>::pointer_to(this->get_bucket_value_traits()); } + + //value traits + // + const value_traits &priv_value_traits() const + { return *this; } + + value_traits &priv_value_traits() + { return *this; } + + //bucket_traits + // + const bucket_traits &priv_bucket_traits() const + { return this->bucket_traits_; } + + bucket_traits &priv_bucket_traits() + { return this->bucket_traits_; } + + //bucket operations + bucket_ptr priv_bucket_pointer() const + { return this->priv_bucket_traits().bucket_begin(); } + + typename slist_impl::size_type priv_bucket_count() const + { return this->priv_bucket_traits().bucket_count(); } + + bucket_ptr priv_invalid_bucket() const + { + const bucket_traits &rbt = this->priv_bucket_traits(); + return rbt.bucket_begin() + rbt.bucket_count(); + } + siterator priv_invalid_local_it() const + { return this->priv_bucket_traits().bucket_begin()->before_begin(); } + + static siterator priv_get_last(bucket_type &b, detail::true_) //optimize multikey + { + //First find the last node of p's group. + //This requires checking the first node of the next group or + //the bucket node. + slist_node_ptr end_ptr(b.end().pointed_node()); + node_ptr possible_end(node_traits::get_next( detail::dcast_bucket_ptr<node>(end_ptr))); + node_ptr last_node_group(possible_end); + + while(end_ptr != possible_end){ + last_node_group = group_traits::get_next(detail::dcast_bucket_ptr<node>(possible_end)); + possible_end = node_traits::get_next(last_node_group); + } + return bucket_type::s_iterator_to(*last_node_group); + } + + static siterator priv_get_last(bucket_type &b, detail::false_) //NOT optimize multikey + { return b.previous(b.end()); } + + static siterator priv_get_previous(bucket_type &b, siterator i, detail::true_) //optimize multikey + { + node_ptr elem(detail::dcast_bucket_ptr<node>(i.pointed_node())); + node_ptr prev_in_group(group_traits::get_next(elem)); + bool first_in_group = node_traits::get_next(prev_in_group) != elem; + typename bucket_type::node &n = first_in_group + ? *group_functions_t::get_prev_to_first_in_group(b.end().pointed_node(), elem) + : *group_traits::get_next(elem) + ; + return bucket_type::s_iterator_to(n); + } + + static siterator priv_get_previous(bucket_type &b, siterator i, detail::false_) //NOT optimize multikey + { return b.previous(i); } + + static void priv_clear_group_nodes(bucket_type &b, detail::true_) //optimize multikey + { + siterator it(b.begin()), itend(b.end()); + while(it != itend){ + node_ptr to_erase(detail::dcast_bucket_ptr<node>(it.pointed_node())); + ++it; + group_algorithms::init(to_erase); + } + } + + static void priv_clear_group_nodes(bucket_type &, detail::false_) //NOT optimize multikey + {} + + std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_) //optimize multikey + { + const bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1); + slist_node_ptr bb = group_functions_t::get_bucket_before_begin + ( f->end().pointed_node() + , l->end().pointed_node() + , detail::dcast_bucket_ptr<node>(it.pointed_node())); + //Now get the bucket_impl from the iterator + const bucket_type &b = static_cast<const bucket_type&> + (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb))); + //Now just calculate the index b has in the bucket array + return static_cast<size_type>(&b - &*f); + } + + std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) //NO optimize multikey + { + bucket_ptr f(this->priv_bucket_pointer()), l(f + this->priv_bucket_count() - 1); + slist_node_ptr first_ptr(f->cend().pointed_node()) + , last_ptr(l->cend().pointed_node()); + + //The end node is embedded in the singly linked list: + //iterate until we reach it. + while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){ + ++it; + } + //Now get the bucket_impl from the iterator + const bucket_type &b = static_cast<const bucket_type&> + (bucket_type::container_from_end_iterator(it)); + + //Now just calculate the index b has in the bucket array + return static_cast<std::size_t>(&b - &*f); + } + + static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) //store_hash + { return node_traits::get_hash(detail::dcast_bucket_ptr<node>(n)); } + + static std::size_t priv_stored_hash(slist_node_ptr, detail::false_) //NO store_hash (This should never be called) + { BOOST_INTRUSIVE_INVARIANT_ASSERT(0); return 0; } + + node &priv_value_to_node(value_type &v) + { return *this->priv_value_traits().to_node_ptr(v); } + + const node &priv_value_to_node(const value_type &v) const + { return *this->priv_value_traits().to_node_ptr(v); } + + value_type &priv_value_from_slist_node(slist_node_ptr n) + { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); } + + const value_type &priv_value_from_slist_node(slist_node_ptr n) const + { return *this->priv_value_traits().to_value_ptr(detail::dcast_bucket_ptr<node>(n)); } + + void priv_clear_buckets(const bucket_ptr buckets_ptr, const size_type bucket_cnt) + { + bucket_ptr buckets_it = buckets_ptr; + for(size_type bucket_i = 0; bucket_i != bucket_cnt; ++buckets_it, ++bucket_i){ + if(safemode_or_autounlink){ + bucket_plus_vtraits::priv_clear_group_nodes(*buckets_it, optimize_multikey_t()); + buckets_it->clear_and_dispose(detail::init_disposer<node_algorithms>()); + } + else{ + buckets_it->clear(); + } + } + } + + bucket_traits bucket_traits_; +}; + +template<class Hash, class T> +struct get_hash +{ + typedef Hash type; +}; + +template<class T> +struct get_hash<void, T> +{ + typedef ::boost::hash<T> type; +}; + +//bucket_hash_t +//Stores bucket_plus_vtraits plust the hash function +template<class VoidOrKeyHash, class ValueTraits, class BucketTraits> +struct bucket_hash_t + : public detail::ebo_functor_holder + <typename get_hash< VoidOrKeyHash + , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type + >::type + > +{ + typedef typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits value_traits; + typedef typename value_traits::value_type value_type; + typedef typename value_traits::node_traits node_traits; + typedef typename get_hash< VoidOrKeyHash, value_type>::type hasher; + typedef BucketTraits bucket_traits; + typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t; + + template<class BucketTraitsType> + bucket_hash_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h) + : detail::ebo_functor_holder<hasher>(h), internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits)) + {} + + const hasher &priv_hasher() const + { return this->detail::ebo_functor_holder<hasher>::get(); } + + hasher &priv_hasher() + { return this->detail::ebo_functor_holder<hasher>::get(); } + + std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const //For store_hash == true + { return node_traits::get_hash(this->internal.priv_value_traits().to_node_ptr(v)); } + + std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const //For store_hash == false + { return this->priv_hasher()(v); } + + bucket_plus_vtraits_t internal; //4 +}; + + +template<class EqualTo, class T> +struct get_equal_to +{ + typedef EqualTo type; +}; + +template<class T> +struct get_equal_to<void, T> +{ + typedef ::std::equal_to<T> type; +}; + + +//bucket_hash_equal_t +//Stores bucket_hash_t and the equality function when the first +//non-empty bucket shall not be cached. +template<class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits, bool> +struct bucket_hash_equal_t + : public detail::ebo_functor_holder //equal + <typename get_equal_to< VoidOrKeyEqual + , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type + >::type + > +{ + typedef bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> bucket_hash_type; + typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t; + typedef typename bucket_plus_vtraits_t::value_traits value_traits; + typedef typename get_equal_to< VoidOrKeyEqual + , typename value_traits::value_type + >::type value_equal; + typedef typename bucket_hash_type::hasher hasher; + typedef BucketTraits bucket_traits; + typedef typename bucket_plus_vtraits_t::slist_impl slist_impl; + typedef typename slist_impl::size_type size_type; + typedef typename slist_impl::iterator siterator; + typedef detail::bucket_impl<slist_impl> bucket_type; + typedef typename detail::unordered_bucket_ptr_impl<value_traits>::type bucket_ptr; + + template<class BucketTraitsType> + bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const value_equal &e) + : detail::ebo_functor_holder<value_equal>(e) + , internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h) + {} + + bucket_ptr priv_get_cache() + { return this->internal.internal.priv_bucket_pointer(); } + + void priv_set_cache(const bucket_ptr &) + {} + + size_type priv_get_cache_bucket_num() + { return 0u; } + + void priv_initialize_cache() + {} + + void priv_swap_cache(bucket_hash_equal_t &) + {} + + siterator priv_begin() const + { + size_type n = 0; + size_type bucket_cnt = this->internal.internal.priv_bucket_count(); + for (n = 0; n < bucket_cnt; ++n){ + bucket_type &b = this->internal.internal.priv_bucket_pointer()[n]; + if(!b.empty()){ + return b.begin(); + } + } + return this->internal.internal.priv_invalid_local_it(); + } + + void priv_insertion_update_cache(size_type) + {} + + void priv_erasure_update_cache_range(size_type, size_type) + {} + + void priv_erasure_update_cache() + {} + + const value_equal &priv_equal() const + { return this->detail::ebo_functor_holder<value_equal>::get(); } + + value_equal &priv_equal() + { return this->detail::ebo_functor_holder<value_equal>::get(); } + + bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> internal; //3 +}; + +//bucket_hash_equal_t +//Stores bucket_hash_t and the equality function when the first +//non-empty bucket shall be cached. +template<class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits> //cache_begin == true version +struct bucket_hash_equal_t<VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits, true> + : public detail::ebo_functor_holder //equal + <typename get_equal_to< VoidOrKeyEqual + , typename bucket_plus_vtraits<ValueTraits,BucketTraits>::value_traits::value_type + >::type + > +{ + typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t; + typedef bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> bucket_hash_type; + typedef typename bucket_plus_vtraits + <ValueTraits,BucketTraits>::value_traits value_traits; + typedef typename get_equal_to + < VoidOrKeyEqual + , typename value_traits::value_type>::type value_equal; + typedef typename bucket_hash_type::hasher hasher; + typedef BucketTraits bucket_traits; + typedef typename bucket_plus_vtraits_t::slist_impl::size_type size_type; + typedef typename bucket_plus_vtraits_t::slist_impl::iterator siterator; + + template<class BucketTraitsType> + bucket_hash_equal_t(const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h, const value_equal &e) + : detail::ebo_functor_holder<value_equal>(e) + , internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h) + {} + + typedef typename detail::unordered_bucket_ptr_impl + <typename bucket_hash_type::value_traits>::type bucket_ptr; + + bucket_ptr &priv_get_cache() + { return cached_begin_; } + + const bucket_ptr &priv_get_cache() const + { return cached_begin_; } + + void priv_set_cache(const bucket_ptr &p) + { cached_begin_ = p; } + + std::size_t priv_get_cache_bucket_num() + { return this->cached_begin_ - this->internal.internal.priv_bucket_pointer(); } + + void priv_initialize_cache() + { this->cached_begin_ = this->internal.internal.priv_invalid_bucket(); } + + void priv_swap_cache(bucket_hash_equal_t &other) + { + std::swap(this->cached_begin_, other.cached_begin_); + } + + siterator priv_begin() const + { + if(this->cached_begin_ == this->internal.internal.priv_invalid_bucket()){ + return this->internal.internal.priv_invalid_local_it(); + } + else{ + return this->cached_begin_->begin(); + } + } + + void priv_insertion_update_cache(size_type insertion_bucket) + { + bucket_ptr p = this->internal.internal.priv_bucket_pointer() + insertion_bucket; + if(p < this->cached_begin_){ + this->cached_begin_ = p; + } + } + + const value_equal &priv_equal() const + { return this->detail::ebo_functor_holder<value_equal>::get(); } + + value_equal &priv_equal() + { return this->detail::ebo_functor_holder<value_equal>::get(); } + + void priv_erasure_update_cache_range(size_type first_bucket_num, size_type last_bucket_num) + { + //If the last bucket is the end, the cache must be updated + //to the last position if all + if(this->priv_get_cache_bucket_num() == first_bucket_num && + this->internal.internal.priv_bucket_pointer()[first_bucket_num].empty() ){ + this->priv_set_cache(this->internal.internal.priv_bucket_pointer() + last_bucket_num); + this->priv_erasure_update_cache(); + } + } + + void priv_erasure_update_cache() + { + if(this->cached_begin_ != this->internal.internal.priv_invalid_bucket()){ + size_type current_n = this->priv_get_cache() - this->internal.internal.priv_bucket_pointer(); + for( const size_type num_buckets = this->internal.internal.priv_bucket_count() + ; current_n < num_buckets + ; ++current_n, ++this->priv_get_cache()){ + if(!this->priv_get_cache()->empty()){ + return; + } + } + this->priv_initialize_cache(); + } + } + + bucket_ptr cached_begin_; + bucket_hash_t<VoidOrKeyHash, ValueTraits, BucketTraits> internal; //2 +}; + +//hashdata_internal +//Stores bucket_hash_equal_t and split_traits +template<class SizeType, std::size_t BoolFlags, class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits> +struct hashdata_internal + : public detail::size_holder< 0 != (BoolFlags & hash_bool_flags::incremental_pos), SizeType, int> //split_traits +{ + typedef bucket_hash_equal_t + < VoidOrKeyHash, VoidOrKeyEqual + , ValueTraits, BucketTraits + , 0 != (BoolFlags & hash_bool_flags::cache_begin_pos) + > internal_type; + typedef typename internal_type::value_equal value_equal; + typedef typename internal_type::hasher hasher; + typedef bucket_plus_vtraits<ValueTraits,BucketTraits> bucket_plus_vtraits_t; + typedef typename bucket_plus_vtraits_t::size_type size_type; + typedef typename bucket_plus_vtraits_t::bucket_ptr bucket_ptr; + typedef detail::size_holder + <0 != (BoolFlags & hash_bool_flags::incremental_pos) + , SizeType, int> split_traits; + typedef typename bucket_plus_vtraits_t:: + value_traits::node_traits node_traits; + typedef detail::bool_<detail::optimize_multikey_is_true + <node_traits>::value> optimize_multikey_t; + + template<class BucketTraitsType> + hashdata_internal( const ValueTraits &val_traits, BOOST_FWD_REF(BucketTraitsType) b_traits + , const hasher & h, const value_equal &e) + : internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e) + {} + + split_traits &priv_split_traits() + { return *this; } + + const split_traits &priv_split_traits() const + { return *this; } + + ~hashdata_internal() + { this->priv_clear_buckets(); } + + void priv_clear_buckets() + { + this->internal.internal.internal.priv_clear_buckets + ( this->internal.priv_get_cache() + , this->internal.internal.internal.priv_bucket_count() + - (this->internal.priv_get_cache() + - this->internal.internal.internal.priv_bucket_pointer())); + } + + void priv_clear_buckets_and_cache() + { + this->priv_clear_buckets(); + this->internal.priv_initialize_cache(); + } + + void priv_initialize_buckets_and_cache() + { + this->internal.internal.internal.priv_clear_buckets + ( this->internal.internal.internal.priv_bucket_pointer() + , this->internal.internal.internal.priv_bucket_count()); + this->internal.priv_initialize_cache(); + } + + internal_type internal; //2 +}; + +//hashtable_data_t +//Stores hashdata_internal and size_traits +template<class SizeType, std::size_t BoolFlags, class VoidOrKeyHash, class VoidOrKeyEqual, class ValueTraits, class BucketTraits> +struct hashtable_data_t + : public detail::size_holder + < 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos), SizeType> //size_traits +{ + typedef detail::size_holder + < 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos) + , SizeType> size_traits; + typedef hashdata_internal + < SizeType + , BoolFlags & (hash_bool_flags::incremental_pos | hash_bool_flags::cache_begin_pos) + , VoidOrKeyHash, VoidOrKeyEqual + , ValueTraits, BucketTraits> internal_type; + typedef ValueTraits value_traits; + typedef typename internal_type::value_equal value_equal; + typedef typename internal_type::hasher hasher; + typedef BucketTraits bucket_traits; + typedef bucket_plus_vtraits + <ValueTraits,BucketTraits> bucket_plus_vtraits_t; + + template<class BucketTraitsType> + hashtable_data_t( BOOST_FWD_REF(BucketTraitsType) b_traits, const hasher & h + , const value_equal &e, const value_traits &val_traits) + : internal(val_traits, ::boost::forward<BucketTraitsType>(b_traits), h, e) + {} + + internal_type internal; //1 +}; /// @endcond //! The class template hashtable is an intrusive hash table container, that //! is used to construct intrusive unordered_set and unordered_multiset containers. The -//! no-throw guarantee holds only, if the Equal object and Hasher don't throw. +//! no-throw guarantee holds only, if the VoidOrKeyEqual object and Hasher don't throw. //! //! hashtable is a semi-intrusive container: each object to be stored in the //! container must contain a proper hook, but the container also needs @@ -676,56 +1167,62 @@ struct uset_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyHash, class VoidOrKeyEqual, class SizeType, class BucketTraits, std::size_t BoolFlags> #endif class hashtable_impl - : private detail::clear_on_destructor_base<hashtable_impl<Config> > + : private hashtable_data_t + < SizeType + , BoolFlags & hashtable_data_bool_flags_mask + , VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits> { - template<class C> friend class detail::clear_on_destructor_base; + typedef hashtable_data_t + < SizeType + , BoolFlags & hashtable_data_bool_flags_mask + , VoidOrKeyHash, VoidOrKeyEqual, ValueTraits, BucketTraits> data_type; + public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; - typedef typename Config::bucket_traits bucket_traits; - static const bool external_bucket_traits = - detail::external_bucket_traits_is_true<bucket_traits>::value; - typedef typename detail::eval_if_c - < external_bucket_traits - , detail::eval_bucket_traits<bucket_traits> - , detail::identity<bucket_traits> - >::type real_bucket_traits; + typedef BucketTraits bucket_traits; + typedef typename detail::get_slist_impl <typename detail::reduced_slist_node_traits - <typename real_value_traits::node_traits>::type + <typename value_traits::node_traits>::type >::type slist_impl; + typedef bucket_plus_vtraits<ValueTraits, BucketTraits> bucket_plus_vtraits_t; + typedef typename bucket_plus_vtraits_t::const_value_traits_ptr const_value_traits_ptr; + + /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - typedef typename real_value_traits::value_type value_type; + typedef typename value_traits::pointer pointer; + typedef typename value_traits::const_pointer const_pointer; + typedef typename value_traits::value_type value_type; typedef typename pointer_traits<pointer>::reference reference; typedef typename pointer_traits<const_pointer>::reference const_reference; typedef typename pointer_traits<pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; + typedef SizeType size_type; typedef value_type key_type; - typedef typename Config::equal key_equal; - typedef typename Config::hash hasher; + typedef typename data_type::value_equal key_equal; + typedef typename data_type::value_equal value_equal; + typedef typename data_type::hasher hasher; typedef detail::bucket_impl<slist_impl> bucket_type; typedef typename pointer_traits <pointer>::template rebind_pointer < bucket_type >::type bucket_ptr; + typedef typename pointer_traits + <pointer>::template rebind_pointer + < const bucket_type >::type const_bucket_ptr; + typedef typename pointer_traits + <bucket_ptr>::reference bucket_reference; + typedef typename pointer_traits + <bucket_ptr>::reference const_bucket_reference; typedef typename slist_impl::iterator siterator; typedef typename slist_impl::const_iterator const_siterator; - typedef detail::hashtable_iterator<hashtable_impl, false> iterator; - typedef detail::hashtable_iterator<hashtable_impl, true> const_iterator; - typedef typename real_value_traits::node_traits node_traits; + typedef hashtable_iterator<bucket_plus_vtraits_t, false> iterator; + typedef hashtable_iterator<bucket_plus_vtraits_t, true> const_iterator; + typedef typename value_traits::node_traits node_traits; typedef typename node_traits::node node; typedef typename pointer_traits <pointer>::template rebind_pointer @@ -733,17 +1230,21 @@ class hashtable_impl typedef typename pointer_traits <pointer>::template rebind_pointer < const node >::type const_node_ptr; + typedef typename pointer_traits + <node_ptr>::reference node_reference; + typedef typename pointer_traits + <const_node_ptr>::reference const_node_reference; typedef typename slist_impl::node_algorithms node_algorithms; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; static const bool store_hash = detail::store_hash_is_true<node_traits>::value; - static const bool unique_keys = 0 != (Config::bool_flags & detail::hash_bool_flags::unique_keys_pos); - static const bool constant_time_size = 0 != (Config::bool_flags & detail::hash_bool_flags::constant_time_size_pos); - static const bool cache_begin = 0 != (Config::bool_flags & detail::hash_bool_flags::cache_begin_pos); - static const bool compare_hash = 0 != (Config::bool_flags & detail::hash_bool_flags::compare_hash_pos); - static const bool incremental = 0 != (Config::bool_flags & detail::hash_bool_flags::incremental_pos); - static const bool power_2_buckets = incremental || (0 != (Config::bool_flags & detail::hash_bool_flags::power_2_buckets_pos)); + static const bool unique_keys = 0 != (BoolFlags & hash_bool_flags::unique_keys_pos); + static const bool constant_time_size = 0 != (BoolFlags & hash_bool_flags::constant_time_size_pos); + static const bool cache_begin = 0 != (BoolFlags & hash_bool_flags::cache_begin_pos); + static const bool compare_hash = 0 != (BoolFlags & hash_bool_flags::compare_hash_pos); + static const bool incremental = 0 != (BoolFlags & hash_bool_flags::incremental_pos); + static const bool power_2_buckets = incremental || (0 != (BoolFlags & hash_bool_flags::power_2_buckets_pos)); static const bool optimize_multikey = detail::optimize_multikey_is_true<node_traits>::value && !unique_keys; @@ -768,75 +1269,31 @@ class hashtable_impl typedef detail::bool_<cache_begin> cache_begin_t; typedef detail::bool_<power_2_buckets> power_2_buckets_t; typedef detail::size_holder<constant_time_size, size_type> size_traits; - typedef detail::size_holder<incremental, size_type> split_traits; + typedef detail::size_holder<incremental, size_type, int> split_traits; typedef detail::group_functions<node_traits> group_functions_t; typedef detail::node_functions<node_traits> node_functions_t; - static const std::size_t hashtable_data_bool_flags_mask = - ( detail::hash_bool_flags::cache_begin_pos - | detail::hash_bool_flags::constant_time_size_pos - | detail::hash_bool_flags::incremental_pos - ); - typedef typename detail::usetopt_mask - <Config, hashtable_data_bool_flags_mask>::type masked_config_t; - detail::hashtable_data_t<masked_config_t> data_; - - template<bool IsConst> - struct downcast_node_to_value - : public detail::node_to_value<hashtable_impl, IsConst> - { - typedef detail::node_to_value<hashtable_impl, IsConst> base_t; - typedef typename base_t::result_type result_type; - typedef typename detail::add_const_if_c - <typename slist_impl::node, IsConst>::type &first_argument_type; - typedef typename detail::add_const_if_c - <node, IsConst>::type &intermediate_argument_type; - - downcast_node_to_value(const hashtable_impl *cont) - : base_t(cont) - {} - - result_type operator()(first_argument_type arg) const - { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); } - }; - - template<class F> - struct node_cast_adaptor - : private detail::ebo_functor_holder<F> - { - typedef detail::ebo_functor_holder<F> base_t; - - template<class ConvertibleToF> - node_cast_adaptor(const ConvertibleToF &c2f, const hashtable_impl *cont) - : base_t(base_t(c2f, cont)) - {} - - typename base_t::node_ptr operator()(const typename slist_impl::node &to_clone) - { return base_t::operator()(static_cast<const node &>(to_clone)); } - - void operator()(typename slist_impl::node_ptr to_clone) - { - base_t::operator()(pointer_traits<node_ptr>::pointer_to(static_cast<node &>(*to_clone))); - } - }; - private: //noncopyable, movable BOOST_MOVABLE_BUT_NOT_COPYABLE(hashtable_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); + BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink))); //Cache begin is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(cache_begin && ((int)real_value_traits::link_mode == (int)auto_unlink))); + BOOST_STATIC_ASSERT(!(cache_begin && ((int)value_traits::link_mode == (int)auto_unlink))); template<class Disposer> - node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> > + node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms> + , slist_node_ptr, node_ptr > make_node_disposer(const Disposer &disposer) const - { return node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> >(disposer, this); } + { + return node_cast_adaptor + < detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms> + , slist_node_ptr, node_ptr > + (disposer, &this->priv_value_traits()); + } /// @endcond @@ -845,36 +1302,18 @@ class hashtable_impl typedef detail::transform_iterator < typename slist_impl::iterator - , downcast_node_to_value<false> > local_iterator; + , downcast_node_to_value_t + < value_traits + , false> > local_iterator; typedef detail::transform_iterator < typename slist_impl::iterator - , downcast_node_to_value<true> > const_local_iterator; - - /// @cond - - const real_value_traits &get_real_value_traits(detail::false_) const - { return this->data_; } - - const real_value_traits &get_real_value_traits(detail::true_) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::false_) - { return this->data_; } - - real_value_traits &get_real_value_traits(detail::true_) - { return data_.get_value_traits(*this); } - - /// @endcond + , downcast_node_to_value_t + < value_traits + , true> > const_local_iterator; public: - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - //! <b>Requires</b>: buckets must not be being used by any other resource. //! //! <b>Effects</b>: Constructs an empty unordered_set, storing a reference @@ -888,32 +1327,32 @@ class hashtable_impl //! //! <b>Notes</b>: buckets array must be disposed only after //! *this is disposed. - hashtable_impl ( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) - : data_(b_traits, hash_func, equal_func, v_traits) + explicit hashtable_impl ( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) + : data_type(b_traits, hash_func, equal_func, v_traits) { - priv_initialize_buckets(); + this->data_type::internal.priv_initialize_buckets_and_cache(); this->priv_size_traits().set_size(size_type(0)); - size_type bucket_size = this->priv_buckets_len(); - BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_size != 0); + size_type bucket_sz = this->priv_bucket_count(); + BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_sz != 0); //Check power of two bucket array if the option is activated BOOST_INTRUSIVE_INVARIANT_ASSERT - (!power_2_buckets || (0 == (bucket_size & (bucket_size-1)))); - priv_split_traits().set_size(bucket_size>>1); + (!power_2_buckets || (0 == (bucket_sz & (bucket_sz-1)))); + this->priv_split_traits().set_size(bucket_sz>>1); } //! <b>Effects</b>: to-do //! hashtable_impl(BOOST_RV_REF(hashtable_impl) x) - : data_( ::boost::move(x.priv_bucket_traits()) + : data_type( ::boost::move(x.priv_bucket_traits()) , ::boost::move(x.priv_hasher()) , ::boost::move(x.priv_equal()) , ::boost::move(x.priv_value_traits()) ) { - priv_swap_cache(cache_begin_t(), x); + this->priv_swap_cache(x); x.priv_initialize_cache(); if(constant_time_size){ this->priv_size_traits().set_size(size_type(0)); @@ -931,6 +1370,7 @@ class hashtable_impl hashtable_impl& operator=(BOOST_RV_REF(hashtable_impl) x) { this->swap(x); return *this; } + #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set //! are not deleted (i.e. no destructors are called). //! @@ -938,8 +1378,8 @@ class hashtable_impl //! it's a safe-mode or auto-unlink value. Otherwise constant. //! //! <b>Throws</b>: Nothing. - ~hashtable_impl() - {} + ~hashtable_impl(); + #endif //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set. //! @@ -948,7 +1388,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. iterator begin() - { return iterator(this->priv_begin(), this); } + { return iterator(this->priv_begin(), &this->get_bucket_value_traits()); } //! <b>Effects</b>: Returns a const_iterator pointing to the beginning //! of the unordered_set. @@ -968,7 +1408,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. const_iterator cbegin() const - { return const_iterator(this->priv_begin(), this); } + { return const_iterator(this->priv_begin(), &this->get_bucket_value_traits()); } //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set. //! @@ -976,7 +1416,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. iterator end() - { return iterator(priv_invalid_local_it(), 0); } + { return iterator(this->priv_invalid_local_it(), 0); } //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set. //! @@ -992,7 +1432,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. const_iterator cend() const - { return const_iterator(priv_invalid_local_it(), 0); } + { return const_iterator(this->priv_invalid_local_it(), 0); } //! <b>Effects</b>: Returns the hasher object used by the unordered_set. //! @@ -1026,9 +1466,9 @@ class hashtable_impl return this->begin() == this->end(); } else{ - size_type buckets_len = this->priv_buckets_len(); - const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_buckets()); - for (size_type n = 0; n < buckets_len; ++n, ++b){ + size_type bucket_cnt = this->priv_bucket_count(); + const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer()); + for (size_type n = 0; n < bucket_cnt; ++n, ++b){ if(!b->empty()){ return false; } @@ -1049,9 +1489,9 @@ class hashtable_impl return this->priv_size_traits().get_size(); else{ size_type len = 0; - size_type buckets_len = this->priv_buckets_len(); - const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_buckets()); - for (size_type n = 0; n < buckets_len; ++n, ++b){ + size_type bucket_cnt = this->priv_bucket_count(); + const bucket_type *b = boost::intrusive::detail::to_raw_pointer(this->priv_bucket_pointer()); + for (size_type n = 0; n < bucket_cnt; ++n, ++b){ len += b->size(); } return len; @@ -1072,12 +1512,12 @@ class hashtable_impl { using std::swap; //These can throw - swap(this->priv_equal(), other.priv_equal()); + swap(this->priv_equal(), other.priv_equal()); swap(this->priv_hasher(), other.priv_hasher()); //These can't throw swap(this->priv_bucket_traits(), other.priv_bucket_traits()); swap(this->priv_value_traits(), other.priv_value_traits()); - priv_swap_cache(cache_begin_t(), other); + this->priv_swap_cache(other); if(constant_time_size){ size_type backup = this->priv_size_traits().get_size(); this->priv_size_traits().set_size(other.priv_size_traits().get_size()); @@ -1125,12 +1565,15 @@ class hashtable_impl //If src bucket count is bigger or equal, structural copy is possible if(!incremental && (src_bucket_count >= dst_bucket_count)){ //First clone the first ones - const bucket_ptr src_buckets = src.priv_buckets(); - const bucket_ptr dst_buckets = this->priv_buckets(); + const bucket_ptr src_buckets = src.priv_bucket_pointer(); + const bucket_ptr dst_buckets = this->priv_bucket_pointer(); size_type constructed; - typedef node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> > NodeDisposer; - typedef node_cast_adaptor<detail::node_cloner<Cloner, hashtable_impl> > NodeCloner; - NodeDisposer node_disp(disposer, this); + + typedef node_cast_adaptor< detail::node_disposer<Disposer, value_traits, CircularSListAlgorithms> + , slist_node_ptr, node_ptr > NodeDisposer; + typedef node_cast_adaptor< detail::node_cloner <Cloner, value_traits, CircularSListAlgorithms> + , slist_node_ptr, node_ptr > NodeCloner; + NodeDisposer node_disp(disposer, &this->priv_value_traits()); detail::exception_array_disposer<bucket_type, NodeDisposer, size_type> rollback(dst_buckets[0], node_disp, constructed); @@ -1139,7 +1582,7 @@ class hashtable_impl ; ++constructed){ dst_buckets[constructed].clone_from ( src_buckets[constructed] - , NodeCloner(cloner, this), node_disp); + , NodeCloner(cloner, &this->priv_value_traits()), node_disp); } if(src_bucket_count != dst_bucket_count){ //Now insert the remaining ones using the modulo trick @@ -1147,12 +1590,12 @@ class hashtable_impl ; constructed < src_bucket_count ; ++constructed){ bucket_type &dst_b = - dst_buckets[priv_hash_to_bucket(constructed, dst_bucket_count, dst_bucket_count)]; + dst_buckets[detail::hash_to_bucket_split<power_2_buckets, incremental>(constructed, dst_bucket_count, dst_bucket_count)]; bucket_type &src_b = src_buckets[constructed]; for( siterator b(src_b.begin()), e(src_b.end()) ; b != e ; ++b){ - dst_b.push_front(*(NodeCloner(cloner, this)(*b.pointed_node()))); + dst_b.push_front(*(NodeCloner(cloner, &this->priv_value_traits())(*b.pointed_node()))); } } } @@ -1161,13 +1604,13 @@ class hashtable_impl rollback.release(); this->priv_size_traits().set_size(src.priv_size_traits().get_size()); this->priv_split_traits().set_size(dst_bucket_count); - priv_insertion_update_cache(0u); - priv_erasure_update_cache(); + this->priv_insertion_update_cache(0u); + this->priv_erasure_update_cache(); } else if(store_hash){ //Unlike previous cloning algorithm, this can throw //if cloner, hasher or comparison functor throw - const_iterator b(src.begin()), e(src.end()); + const_iterator b(src.cbegin()), e(src.cend()); detail::exception_disposer<hashtable_impl, Disposer> rollback(*this, disposer); for(; b != e; ++b){ @@ -1179,7 +1622,7 @@ class hashtable_impl else{ //Unlike previous cloning algorithm, this can throw //if cloner, hasher or comparison functor throw - const_iterator b(src.begin()), e(src.end()); + const_iterator b(src.cbegin()), e(src.cend()); detail::exception_disposer<hashtable_impl, Disposer> rollback(*this, disposer); for(; b != e; ++b){ @@ -1209,7 +1652,7 @@ class hashtable_impl siterator prev; siterator it = this->priv_find (value, this->priv_hasher(), this->priv_equal(), bucket_num, hash_value, prev); - return priv_insert_equal_find(value, bucket_num, hash_value, it); + return this->priv_insert_equal_find(value, bucket_num, hash_value, it); } //! <b>Requires</b>: Dereferencing iterator must yield an lvalue @@ -1323,11 +1766,11 @@ class hashtable_impl siterator prev; siterator prev_pos = this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash, prev); - bool success = prev_pos == priv_invalid_local_it(); + bool success = prev_pos == this->priv_invalid_local_it(); if(success){ prev_pos = prev; } - return std::pair<iterator, bool>(iterator(prev_pos, this),success); + return std::pair<iterator, bool>(iterator(prev_pos, &this->get_bucket_value_traits()),success); } //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data @@ -1351,16 +1794,16 @@ class hashtable_impl //! After a successful rehashing insert_commit_data remains valid. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) { - size_type bucket_num = priv_hash_to_bucket(commit_data.hash); - bucket_type &b = this->priv_buckets()[bucket_num]; + size_type bucket_num = this->priv_hash_to_bucket(commit_data.hash); + bucket_type &b = this->priv_bucket_pointer()[bucket_num]; this->priv_size_traits().increment(); - node_ptr n = pointer_traits<node_ptr>::pointer_to(priv_value_to_node(value)); + node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value)); node_functions_t::store_hash(n, commit_data.hash, store_hash_t()); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); - priv_insertion_update_cache(bucket_num); + this->priv_insertion_update_cache(bucket_num); group_functions_t::insert_in_group(node_ptr(), n, optimize_multikey_t()); - return iterator(b.insert_after(b.before_begin(), *n), this); + return iterator(b.insert_after(b.before_begin(), *n), &this->get_bucket_value_traits()); } //! <b>Effects</b>: Erases the element pointed to by i. @@ -1443,9 +1886,9 @@ class hashtable_impl /// @endcond ) { - priv_erase(i, disposer, optimize_multikey_t()); + this->priv_erase(i, disposer, optimize_multikey_t()); this->priv_size_traits().decrement(); - priv_erasure_update_cache(); + this->priv_erasure_update_cache(); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. @@ -1468,8 +1911,9 @@ class hashtable_impl siterator first_local_it(b.slist_it()); size_type first_bucket_num = this->priv_get_bucket_num(first_local_it); + const bucket_ptr buck_ptr = this->priv_bucket_pointer(); siterator before_first_local_it - = priv_get_previous(priv_buckets()[first_bucket_num], first_local_it); + = this->priv_get_previous(buck_ptr[first_bucket_num], first_local_it); size_type last_bucket_num; siterator last_local_it; @@ -1477,14 +1921,14 @@ class hashtable_impl //of the last bucket if(e == this->end()){ last_bucket_num = this->bucket_count() - 1; - last_local_it = priv_buckets()[last_bucket_num].end(); + last_local_it = buck_ptr[last_bucket_num].end(); } else{ last_local_it = e.slist_it(); last_bucket_num = this->priv_get_bucket_num(last_local_it); } - priv_erase_range(before_first_local_it, first_bucket_num, last_local_it, last_bucket_num, disposer); - priv_erasure_update_cache(first_bucket_num, last_bucket_num); + this->priv_erase_range(before_first_local_it, first_bucket_num, last_local_it, last_bucket_num, disposer); + this->priv_erasure_update_cache_range(first_bucket_num, last_bucket_num); } } @@ -1505,7 +1949,7 @@ class hashtable_impl //! to the erased elements. No destructors are called. template<class Disposer> size_type erase_and_dispose(const_reference value, Disposer disposer) - { return this->erase_and_dispose(value, priv_hasher(), priv_equal(), disposer); } + { return this->erase_and_dispose(value, this->priv_hasher(), this->priv_equal(), disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1529,25 +1973,24 @@ class hashtable_impl size_type bucket_num; std::size_t h; siterator prev; - siterator it = - this->priv_find(key, hash_func, equal_func, bucket_num, h, prev); - bool success = it != priv_invalid_local_it(); - size_type count(0); + siterator it = this->priv_find(key, hash_func, equal_func, bucket_num, h, prev); + bool success = it != this->priv_invalid_local_it(); + size_type cnt(0); if(!success){ return 0; } else if(optimize_multikey){ siterator last = bucket_type::s_iterator_to (*node_traits::get_next(group_functions_t::get_last_in_group - (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()))); - this->priv_erase_range_impl(bucket_num, prev, last, disposer, count); + (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t()))); + this->priv_erase_range_impl(bucket_num, prev, last, disposer, cnt); } else{ //If found erase all equal values - bucket_type &b = this->priv_buckets()[bucket_num]; - for(siterator end = b.end(); it != end; ++count, ++it){ + bucket_type &b = this->priv_bucket_pointer()[bucket_num]; + for(siterator end_sit = b.end(); it != end_sit; ++cnt, ++it){ slist_node_ptr n(it.pointed_node()); - const value_type &v = priv_value_from_slist_node(n); + const value_type &v = this->priv_value_from_slist_node(n); if(compare_hash){ std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t()); if(h != vh || !equal_func(key, v)){ @@ -1561,8 +2004,8 @@ class hashtable_impl } b.erase_after_and_dispose(prev, it, make_node_disposer(disposer)); } - priv_erasure_update_cache(); - return count; + this->priv_erasure_update_cache(); + return cnt; } //! <b>Effects</b>: Erases all of the elements. @@ -1576,7 +2019,7 @@ class hashtable_impl //! to the erased elements. No destructors are called. void clear() { - priv_clear_buckets(); + this->data_type::internal.priv_clear_buckets_and_cache(); this->priv_size_traits().set_size(size_type(0)); } @@ -1596,13 +2039,13 @@ class hashtable_impl { if(!constant_time_size || !this->empty()){ size_type num_buckets = this->bucket_count(); - bucket_ptr b = this->priv_buckets(); + bucket_ptr b = this->priv_bucket_pointer(); for(; num_buckets--; ++b){ b->clear_and_dispose(make_node_disposer(disposer)); } this->priv_size_traits().set_size(size_type(0)); } - priv_initialize_cache(); + this->priv_initialize_cache(); } //! <b>Effects</b>: Returns the number of contained elements with the given value @@ -1629,9 +2072,9 @@ class hashtable_impl template<class KeyType, class KeyHasher, class KeyValueEqual> size_type count(const KeyType &key, const KeyHasher &hash_func, const KeyValueEqual &equal_func) const { - size_type bucket_n1, bucket_n2, count; - this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count); - return count; + size_type bucket_n1, bucket_n2, cnt; + this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); + return cnt; } //! <b>Effects</b>: Finds an iterator to the first element is equal to @@ -1669,7 +2112,7 @@ class hashtable_impl std::size_t hash; siterator prev; siterator local_it = this->priv_find(key, hash_func, equal_func, bucket_n, hash, prev); - return iterator(local_it, this); + return iterator(local_it, &this->get_bucket_value_traits()); } //! <b>Effects</b>: Finds a const_iterator to the first element whose key is @@ -1708,7 +2151,7 @@ class hashtable_impl std::size_t hash_value; siterator prev; siterator sit = this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev); - return const_iterator(sit, this); + return const_iterator(sit, &this->get_bucket_value_traits()); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent @@ -1745,11 +2188,11 @@ class hashtable_impl std::pair<iterator,iterator> equal_range (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) { - size_type bucket_n1, bucket_n2, count; + size_type bucket_n1, bucket_n2, cnt; std::pair<siterator, siterator> ret = this->priv_equal_range - (key, hash_func, equal_func, bucket_n1, bucket_n2, count); + (key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); return std::pair<iterator, iterator> - (iterator(ret.first, this), iterator(ret.second, this)); + (iterator(ret.first, &this->get_bucket_value_traits()), iterator(ret.second, &this->get_bucket_value_traits())); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent @@ -1787,11 +2230,12 @@ class hashtable_impl std::pair<const_iterator,const_iterator> equal_range (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const { - size_type bucket_n1, bucket_n2, count; + size_type bucket_n1, bucket_n2, cnt; std::pair<siterator, siterator> ret = - this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count); + this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, cnt); return std::pair<const_iterator, const_iterator> - (const_iterator(ret.first, this), const_iterator(ret.second, this)); + ( const_iterator(ret.first, &this->get_bucket_value_traits()) + , const_iterator(ret.second, &this->get_bucket_value_traits())); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1805,7 +2249,8 @@ class hashtable_impl //! <b>Throws</b>: If the internal hash function throws. iterator iterator_to(reference value) { - return iterator(bucket_type::s_iterator_to(priv_value_to_node(value)), this); + return iterator(bucket_type::s_iterator_to + (this->priv_value_to_node(value)), &this->get_bucket_value_traits()); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1819,8 +2264,10 @@ class hashtable_impl //! <b>Throws</b>: If the internal hash function throws. const_iterator iterator_to(const_reference value) const { - siterator sit = bucket_type::s_iterator_to(const_cast<node &>(this->priv_value_to_node(value))); - return const_iterator(sit, this); + node_reference r = *pointer_traits<node_ptr>::const_cast_from + (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value))); + siterator sit = bucket_type::s_iterator_to(r); + return const_iterator(sit, &this->get_bucket_value_traits()); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1838,8 +2285,8 @@ class hashtable_impl static local_iterator s_local_iterator_to(reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(value)); - return local_iterator(sit, (hashtable_impl*)0); + siterator sit = bucket_type::s_iterator_to(*value_traits::to_node_ptr(value)); + return local_iterator(sit, const_value_traits_ptr()); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1857,8 +2304,10 @@ class hashtable_impl static const_local_iterator s_local_iterator_to(const_reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(const_cast<value_type&>(value))); - return const_local_iterator(sit, (hashtable_impl*)0); + node_reference r = *pointer_traits<node_ptr>::const_cast_from + (value_traits::to_node_ptr(value)); + siterator sit = bucket_type::s_iterator_to(r); + return const_local_iterator(sit, const_value_traits_ptr()); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1873,7 +2322,7 @@ class hashtable_impl local_iterator local_iterator_to(reference value) { siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value)); - return local_iterator(sit, this); + return local_iterator(sit, this->priv_value_traits_ptr()); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of @@ -1887,9 +2336,10 @@ class hashtable_impl //! <b>Throws</b>: Nothing. const_local_iterator local_iterator_to(const_reference value) const { - siterator sit = bucket_type::s_iterator_to - (const_cast<node &>(this->priv_value_to_node(value))); - return const_local_iterator(sit, this); + node_reference r = *pointer_traits<node_ptr>::const_cast_from + (pointer_traits<const_node_ptr>::pointer_to(this->priv_value_to_node(value))); + siterator sit = bucket_type::s_iterator_to(r); + return const_local_iterator(sit, this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns the number of buckets passed in the constructor @@ -1899,7 +2349,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. size_type bucket_count() const - { return this->priv_buckets_len(); } + { return this->priv_bucket_count(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1909,7 +2359,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. size_type bucket_size(size_type n) const - { return this->priv_buckets()[n].size(); } + { return this->priv_bucket_pointer()[n].size(); } //! <b>Effects</b>: Returns the index of the bucket in which elements //! with keys equivalent to k would be found, if any such element existed. @@ -1936,7 +2386,7 @@ class hashtable_impl //! <b>Note</b>: the return value is in the range [0, this->bucket_count()). template<class KeyType, class KeyHasher> size_type bucket(const KeyType& k, const KeyHasher &hash_func) const - { return priv_hash_to_bucket(hash_func(k)); } + { return this->priv_hash_to_bucket(hash_func(k)); } //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor //! or the last rehash function. @@ -1945,7 +2395,7 @@ class hashtable_impl //! //! <b>Throws</b>: Nothing. bucket_ptr bucket_pointer() const - { return this->priv_buckets(); } + { return this->priv_bucket_pointer(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1959,7 +2409,7 @@ class hashtable_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator begin(size_type n) - { return local_iterator(this->priv_buckets()[n].begin(), this); } + { return local_iterator(this->priv_bucket_pointer()[n].begin(), this->priv_value_traits_ptr()); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1988,8 +2438,8 @@ class hashtable_impl //! containing all of the elements in the nth bucket. const_local_iterator cbegin(size_type n) const { - siterator sit = const_cast<bucket_type&>(this->priv_buckets()[n]).begin(); - return const_local_iterator(sit, this); + bucket_reference br = pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n]; + return const_local_iterator(br.begin(), this->priv_value_traits_ptr()); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). @@ -2004,7 +2454,7 @@ class hashtable_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator end(size_type n) - { return local_iterator(this->priv_buckets()[n].end(), this); } + { return local_iterator(this->priv_bucket_pointer()[n].end(), this->priv_value_traits_ptr()); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -2032,19 +2482,22 @@ class hashtable_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator cend(size_type n) const - { return const_local_iterator(const_cast<bucket_type&>(this->priv_buckets()[n]).end(), this); } + { + bucket_reference br = pointer_traits<bucket_ptr>::const_cast_from(this->priv_bucket_pointer())[n]; + return const_local_iterator ( br.end(), this->priv_value_traits_ptr()); + } - //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array - //! or the same as the old bucket array. new_size is the length of the - //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer() - //! n can be bigger or smaller than this->bucket_count(). + //! <b>Requires</b>: new_bucket_traits can hold a pointer to a new bucket array + //! or the same as the old bucket array with a different length. new_size is the length of the + //! the array pointed by new_buckets. If new_bucket_traits.bucket_begin() == this->bucket_pointer() + //! new_bucket_traits.bucket_count() can be bigger or smaller than this->bucket_count(). //! 'new_bucket_traits' copy constructor should not throw. //! - //! <b>Effects</b>: Updates the internal reference with the new bucket erases + //! <b>Effects</b>: Updates the internal reference with the new bucket, erases //! the values from the old bucket and inserts then in the new one. //! Bucket traits hold by *this is assigned from new_bucket_traits. //! If the container is configured as incremental<>, the split bucket is set - //! to the new bucket_len(). + //! to the new bucket_count(). //! //! If store_hash option is true, this method does not use the hash function. //! @@ -2053,27 +2506,27 @@ class hashtable_impl //! <b>Throws</b>: If the hasher functor throws. Basic guarantee. void rehash(const bucket_traits &new_bucket_traits) { - bucket_ptr new_buckets = new_bucket_traits.bucket_begin(); - size_type new_buckets_len = new_bucket_traits.bucket_count(); - bucket_ptr old_buckets = this->priv_buckets(); - size_type old_buckets_len = this->priv_buckets_len(); + const bucket_ptr new_buckets = new_bucket_traits.bucket_begin(); + size_type new_bucket_count = new_bucket_traits.bucket_count(); + const bucket_ptr old_buckets = this->priv_bucket_pointer(); + size_type old_bucket_count = this->priv_bucket_count(); //Check power of two bucket array if the option is activated BOOST_INTRUSIVE_INVARIANT_ASSERT - (!power_2_buckets || (0 == (new_buckets_len & (new_buckets_len-1u)))); + (!power_2_buckets || (0 == (new_bucket_count & (new_bucket_count-1u)))); - size_type n = priv_get_cache_bucket_num(); + size_type n = this->priv_get_cache_bucket_num(); const bool same_buffer = old_buckets == new_buckets; //If the new bucket length is a common factor //of the old one we can avoid hash calculations. - const bool fast_shrink = (!incremental) && (old_buckets_len > new_buckets_len) && - (power_2_buckets ||(old_buckets_len % new_buckets_len) == 0); + const bool fast_shrink = (!incremental) && (old_bucket_count > new_bucket_count) && + (power_2_buckets ||(old_bucket_count % new_bucket_count) == 0); //If we are shrinking the same bucket array and it's //is a fast shrink, just rehash the last nodes - size_type new_first_bucket_num = new_buckets_len; - if(same_buffer && fast_shrink && (n < new_buckets_len)){ - n = new_buckets_len; - new_first_bucket_num = priv_get_cache_bucket_num(); + size_type new_first_bucket_num = new_bucket_count; + if(same_buffer && fast_shrink && (n < new_bucket_count)){ + n = new_bucket_count; + new_first_bucket_num = this->priv_get_cache_bucket_num(); } //Anti-exception stuff: they destroy the elements if something goes wrong. @@ -2084,34 +2537,34 @@ class hashtable_impl bucket_type & newbuck = new_buckets[0]; bucket_type & oldbuck = old_buckets[0]; detail::exception_array_disposer<bucket_type, NodeDisposer, size_type> - rollback1(newbuck, node_disp, new_buckets_len); + rollback1(newbuck, node_disp, new_bucket_count); detail::exception_array_disposer<bucket_type, NodeDisposer, size_type> - rollback2(oldbuck, node_disp, old_buckets_len); + rollback2(oldbuck, node_disp, old_bucket_count); //Put size in a safe value for rollback exception size_type size_backup = this->priv_size_traits().get_size(); this->priv_size_traits().set_size(0); //Put cache to safe position - priv_initialize_cache(); - priv_insertion_update_cache(size_type(0u)); + this->priv_initialize_cache(); + this->priv_insertion_update_cache(size_type(0u)); //Iterate through nodes - for(; n < old_buckets_len; ++n){ + for(; n < old_bucket_count; ++n){ bucket_type &old_bucket = old_buckets[n]; if(!fast_shrink){ siterator before_i(old_bucket.before_begin()); - siterator end(old_bucket.end()); + siterator end_sit(old_bucket.end()); siterator i(old_bucket.begin()); - for(;i != end; ++i){ - const value_type &v = priv_value_from_slist_node(i.pointed_node()); + for(;i != end_sit; ++i){ + const value_type &v = this->priv_value_from_slist_node(i.pointed_node()); const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t()); - const size_type new_n = priv_hash_to_bucket(hash_value, new_buckets_len, new_buckets_len); + const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>(hash_value, new_bucket_count, new_bucket_count); if(cache_begin && new_n < new_first_bucket_num) new_first_bucket_num = new_n; siterator last = bucket_type::s_iterator_to (*group_functions_t::get_last_in_group - (dcast_bucket_ptr(i.pointed_node()), optimize_multikey_t())); + (detail::dcast_bucket_ptr<node>(i.pointed_node()), optimize_multikey_t())); if(same_buffer && new_n == n){ before_i = last; } @@ -2123,7 +2576,7 @@ class hashtable_impl } } else{ - const size_type new_n = priv_hash_to_bucket(n, new_buckets_len, new_buckets_len); + const size_type new_n = detail::hash_to_bucket_split<power_2_buckets, incremental>(n, new_bucket_count, new_bucket_count); if(cache_begin && new_n < new_first_bucket_num) new_first_bucket_num = new_n; bucket_type &new_b = new_buckets[new_n]; @@ -2131,16 +2584,16 @@ class hashtable_impl new_b.splice_after( new_b.before_begin() , old_bucket , old_bucket.before_begin() - , priv_get_last(old_bucket)); + , hashtable_impl::priv_get_last(old_bucket)); } } } this->priv_size_traits().set_size(size_backup); - this->priv_split_traits().set_size(new_buckets_len); - this->priv_real_bucket_traits() = new_bucket_traits; - priv_initialize_cache(); - priv_insertion_update_cache(new_first_bucket_num); + this->priv_split_traits().set_size(new_bucket_count); + this->priv_bucket_traits() = new_bucket_traits; + this->priv_initialize_cache(); + this->priv_insertion_update_cache(new_first_bucket_num); rollback1.release(); rollback2.release(); } @@ -2158,57 +2611,57 @@ class hashtable_impl { //This function is only available for containers with incremental hashing BOOST_STATIC_ASSERT(( incremental && power_2_buckets )); - size_type split_idx = priv_split_traits().get_size(); - size_type bucket_len = priv_buckets_len(); + const size_type split_idx = this->priv_split_traits().get_size(); + const size_type bucket_cnt = this->priv_bucket_count(); + const bucket_ptr buck_ptr = this->priv_bucket_pointer(); if(grow){ //Test if the split variable can be changed - if(split_idx >= bucket_len) + if(split_idx >= bucket_cnt) return false; - size_type bucket_len = priv_buckets_len(); - size_type bucket_to_rehash = split_idx - bucket_len/2; - bucket_type &old_bucket = this->priv_buckets()[bucket_to_rehash]; + const size_type bucket_to_rehash = split_idx - bucket_cnt/2; + bucket_type &old_bucket = buck_ptr[bucket_to_rehash]; siterator before_i(old_bucket.before_begin()); - siterator end(old_bucket.end()); + const siterator end_sit(old_bucket.end()); siterator i(old_bucket.begin()); - priv_split_traits().increment(); + this->priv_split_traits().increment(); //Anti-exception stuff: if an exception is thrown while //moving elements from old_bucket to the target bucket, all moved //elements are moved back to the original one. detail::incremental_rehash_rollback<bucket_type, split_traits> rollback - ( this->priv_buckets()[split_idx], old_bucket, priv_split_traits()); - for(;i != end; ++i){ - const value_type &v = priv_value_from_slist_node(i.pointed_node()); + ( buck_ptr[split_idx], old_bucket, this->priv_split_traits()); + for(;i != end_sit; ++i){ + const value_type &v = this->priv_value_from_slist_node(i.pointed_node()); const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t()); - const size_type new_n = priv_hash_to_bucket(hash_value); + const size_type new_n = this->priv_hash_to_bucket(hash_value); siterator last = bucket_type::s_iterator_to (*group_functions_t::get_last_in_group - (dcast_bucket_ptr(i.pointed_node()), optimize_multikey_t())); + (detail::dcast_bucket_ptr<node>(i.pointed_node()), optimize_multikey_t())); if(new_n == bucket_to_rehash){ before_i = last; } else{ - bucket_type &new_b = this->priv_buckets()[new_n]; + bucket_type &new_b = buck_ptr[new_n]; new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last); } i = before_i; } rollback.release(); - priv_erasure_update_cache(); + this->priv_erasure_update_cache(); return true; } else{ //Test if the split variable can be changed - if(split_idx <= bucket_len/2) + if(split_idx <= bucket_cnt/2) return false; - const size_type target_bucket_num = split_idx - 1 - bucket_len/2; - bucket_type &target_bucket = this->priv_buckets()[target_bucket_num]; - bucket_type &source_bucket = this->priv_buckets()[split_idx-1]; + const size_type target_bucket_num = split_idx - 1 - bucket_cnt/2; + bucket_type &target_bucket = buck_ptr[target_bucket_num]; + bucket_type &source_bucket = buck_ptr[split_idx-1]; target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket); - priv_split_traits().decrement(); - priv_insertion_update_cache(target_bucket_num); + this->priv_split_traits().decrement(); + this->priv_insertion_update_cache(target_bucket_num); return true; } } @@ -2231,7 +2684,7 @@ class hashtable_impl //This function is only available for containers with incremental hashing BOOST_STATIC_ASSERT(( incremental && power_2_buckets )); size_type new_bucket_traits_size = new_bucket_traits.bucket_count(); - size_type cur_bucket_traits = this->priv_buckets_len(); + size_type cur_bucket_traits = this->priv_bucket_count(); if(new_bucket_traits_size/2 != cur_bucket_traits && new_bucket_traits_size != cur_bucket_traits/2){ return false; } @@ -2249,9 +2702,9 @@ class hashtable_impl return false; } - const size_type ini_n = priv_get_cache_bucket_num(); - const bucket_ptr old_buckets = this->priv_buckets(); - this->priv_real_bucket_traits() = new_bucket_traits; + const size_type ini_n = this->priv_get_cache_bucket_num(); + const bucket_ptr old_buckets = this->priv_bucket_pointer(); + this->priv_bucket_traits() = new_bucket_traits; if(new_bucket_traits.bucket_begin() != old_buckets){ for(size_type n = ini_n; n < split_idx; ++n){ bucket_type &new_bucket = new_bucket_traits.bucket_begin()[n]; @@ -2259,8 +2712,8 @@ class hashtable_impl new_bucket.splice_after(new_bucket.cbefore_begin(), old_bucket); } //Put cache to safe position - priv_initialize_cache(); - priv_insertion_update_cache(ini_n); + this->priv_initialize_cache(); + this->priv_insertion_update_cache(ini_n); } return true; } @@ -2290,11 +2743,10 @@ class hashtable_impl //! <b>Throws</b>: Nothing. static size_type suggested_upper_bucket_count(size_type n) { - const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0]; - const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size; + const std::size_t *primes = &prime_list_holder<0>::prime_list[0]; + const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size; std::size_t const* bound = std::lower_bound(primes, primes_end, n); - if(bound == primes_end) - --bound; + bound -= (bound == primes_end); return size_type(*bound); } @@ -2309,127 +2761,138 @@ class hashtable_impl //! <b>Throws</b>: Nothing. static size_type suggested_lower_bucket_count(size_type n) { - const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0]; - const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size; + const std::size_t *primes = &prime_list_holder<0>::prime_list[0]; + const std::size_t *primes_end = primes + prime_list_holder<0>::prime_list_size; size_type const* bound = std::upper_bound(primes, primes_end, n); - if(bound != primes) - --bound; + bound -= (bound != primes); return size_type(*bound); } - /// @cond + void check() const {} private: + size_traits &priv_size_traits() + { return static_cast<size_traits&>(static_cast<data_type&>(*this)); } - std::size_t priv_hash_to_bucket(std::size_t hash_value) const - { return priv_hash_to_bucket(hash_value, this->priv_real_bucket_traits().bucket_count(), priv_split_traits().get_size()); } + const size_traits &priv_size_traits() const + { return static_cast<const size_traits&>(static_cast<const data_type&>(*this)); } - std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_len, std::size_t split) const - { - std::size_t bucket_number = priv_hash_to_bucket_impl(hash_value, bucket_len, power_2_buckets_t()); - if(incremental) - if(bucket_number >= split) - bucket_number -= bucket_len/2; - return bucket_number; - } + bucket_ptr priv_bucket_pointer() const + { return this->data_type::internal.internal.internal.internal.priv_bucket_pointer(); } - std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_len, detail::false_) const - { return hash_value % bucket_len; } + SizeType priv_bucket_count() const + { return this->data_type::internal.internal.internal.internal.priv_bucket_count(); } - std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_len, detail::true_) const - { return hash_value & (bucket_len - 1); } + const bucket_plus_vtraits<ValueTraits, BucketTraits> &get_bucket_value_traits() const + { return this->data_type::internal.internal.internal.internal.get_bucket_value_traits(); } - const key_equal &priv_equal() const - { return static_cast<const key_equal&>(this->data_.internal_.bucket_hash_equal_.get()); } + bucket_plus_vtraits<ValueTraits, BucketTraits> &get_bucket_value_traits() + { return this->data_type::internal.internal.internal.internal.get_bucket_value_traits(); } - key_equal &priv_equal() - { return static_cast<key_equal&>(this->data_.internal_.bucket_hash_equal_.get()); } + bucket_traits &priv_bucket_traits() + { return this->data_type::internal.internal.internal.internal.priv_bucket_traits(); } - const value_traits &priv_value_traits() const - { return data_; } + const bucket_traits &priv_bucket_traits() const + { return this->data_type::internal.internal.internal.internal.priv_bucket_traits(); } value_traits &priv_value_traits() - { return data_; } + { return this->data_type::internal.internal.internal.internal.priv_value_traits(); } - value_type &priv_value_from_slist_node(slist_node_ptr n) - { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); } - - const value_type &priv_value_from_slist_node(slist_node_ptr n) const - { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); } + const value_traits &priv_value_traits() const + { return this->data_type::internal.internal.internal.internal.priv_value_traits(); } - const real_bucket_traits &priv_real_bucket_traits(detail::false_) const - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + const_value_traits_ptr priv_value_traits_ptr() const + { return this->data_type::internal.internal.internal.internal.priv_value_traits_ptr(); } - const real_bucket_traits &priv_real_bucket_traits(detail::true_) const - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } + siterator priv_invalid_local_it() const + { return this->data_type::internal.internal.internal.internal.priv_invalid_local_it(); } + + split_traits &priv_split_traits() + { return this->data_type::internal.priv_split_traits(); } - real_bucket_traits &priv_real_bucket_traits(detail::false_) - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + const split_traits &priv_split_traits() const + { return this->data_type::internal.priv_split_traits(); } - real_bucket_traits &priv_real_bucket_traits(detail::true_) - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); } + bucket_ptr priv_get_cache() + { return this->data_type::internal.internal.priv_get_cache(); } - const real_bucket_traits &priv_real_bucket_traits() const - { return this->priv_real_bucket_traits(detail::bool_<external_bucket_traits>()); } + void priv_initialize_cache() + { return this->data_type::internal.internal.priv_initialize_cache(); } - real_bucket_traits &priv_real_bucket_traits() - { return this->priv_real_bucket_traits(detail::bool_<external_bucket_traits>()); } + siterator priv_begin() const + { return this->data_type::internal.internal.priv_begin(); } - const bucket_traits &priv_bucket_traits() const - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + const value_equal &priv_equal() const + { return this->data_type::internal.internal.priv_equal(); } - bucket_traits &priv_bucket_traits() - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; } + value_equal &priv_equal() + { return this->data_type::internal.internal.priv_equal(); } const hasher &priv_hasher() const - { return static_cast<const hasher&>(this->data_.internal_.bucket_hash_equal_.bucket_hash.get()); } + { return this->data_type::internal.internal.internal.priv_hasher(); } hasher &priv_hasher() - { return static_cast<hasher&>(this->data_.internal_.bucket_hash_equal_.bucket_hash.get()); } - - bucket_ptr priv_buckets() const - { return this->priv_real_bucket_traits().bucket_begin(); } - - size_type priv_buckets_len() const - { return this->priv_real_bucket_traits().bucket_count(); } + { return this->data_type::internal.internal.internal.priv_hasher(); } - static node_ptr uncast(const const_node_ptr & ptr) - { return node_ptr(const_cast<node*>(boost::intrusive::detail::to_raw_pointer(ptr))); } + void priv_swap_cache(hashtable_impl &h) + { this->data_type::internal.internal.priv_swap_cache(h.data_type::internal.internal); } node &priv_value_to_node(value_type &v) - { return *this->get_real_value_traits().to_node_ptr(v); } + { return this->data_type::internal.internal.internal.internal.priv_value_to_node(v); } const node &priv_value_to_node(const value_type &v) const - { return *this->get_real_value_traits().to_node_ptr(v); } + { return this->data_type::internal.internal.internal.internal.priv_value_to_node(v); } - size_traits &priv_size_traits() - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_; } + SizeType priv_get_cache_bucket_num() + { return this->data_type::internal.internal.priv_get_cache_bucket_num(); } - const size_traits &priv_size_traits() const - { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_; } + void priv_insertion_update_cache(SizeType n) + { return this->data_type::internal.internal.priv_insertion_update_cache(n); } - split_traits &priv_split_traits() - { return this->data_.internal_; } + template<bool Boolean> + std::size_t priv_stored_or_compute_hash(const value_type &v, detail::bool_<Boolean> b) const + { return this->data_type::internal.internal.internal.priv_stored_or_compute_hash(v, b); } - const split_traits &priv_split_traits() const - { return this->data_.internal_; } + value_type &priv_value_from_slist_node(slist_node_ptr n) + { return this->data_type::internal.internal.internal.internal.priv_value_from_slist_node(n); } + + const value_type &priv_value_from_slist_node(slist_node_ptr n) const + { return this->data_type::internal.internal.internal.internal.priv_value_from_slist_node(n); } + + void priv_erasure_update_cache_range(SizeType first_bucket_num, SizeType last_bucket_num) + { return this->data_type::internal.internal.priv_erasure_update_cache_range(first_bucket_num, last_bucket_num); } + + void priv_erasure_update_cache() + { return this->data_type::internal.internal.priv_erasure_update_cache(); } + + static std::size_t priv_stored_hash(slist_node_ptr n, detail::true_ true_value) + { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, true_value); } + + static std::size_t priv_stored_hash(slist_node_ptr n, detail::false_ false_value) + { return bucket_plus_vtraits<ValueTraits, BucketTraits>::priv_stored_hash(n, false_value); } + + std::size_t priv_hash_to_bucket(std::size_t hash_value) const + { + return detail::hash_to_bucket_split<power_2_buckets, incremental> + (hash_value, this->priv_bucket_traits().bucket_count(), this->priv_split_traits().get_size()); + } template<class Disposer> void priv_erase_range_impl - (size_type bucket_num, siterator before_first_it, siterator end, Disposer disposer, size_type &num_erased) + (size_type bucket_num, siterator before_first_it, siterator end_sit, Disposer disposer, size_type &num_erased) { - const bucket_ptr buckets = priv_buckets(); + const bucket_ptr buckets = this->priv_bucket_pointer(); bucket_type &b = buckets[bucket_num]; - if(before_first_it == b.before_begin() && end == b.end()){ - priv_erase_range_impl(bucket_num, 1, disposer, num_erased); + if(before_first_it == b.before_begin() && end_sit == b.end()){ + this->priv_erase_range_impl(bucket_num, 1, disposer, num_erased); } else{ num_erased = 0; siterator to_erase(before_first_it); ++to_erase; - slist_node_ptr end_ptr = end.pointed_node(); - while(to_erase != end){ - group_functions_t::erase_from_group(end_ptr, dcast_bucket_ptr(to_erase.pointed_node()), optimize_multikey_t()); + slist_node_ptr end_ptr = end_sit.pointed_node(); + while(to_erase != end_sit){ + group_functions_t::erase_from_group(end_ptr, detail::dcast_bucket_ptr<node>(to_erase.pointed_node()), optimize_multikey_t()); to_erase = b.erase_after_and_dispose(before_first_it, make_node_disposer(disposer)); ++num_erased; } @@ -2442,16 +2905,16 @@ class hashtable_impl (size_type first_bucket_num, size_type num_buckets, Disposer disposer, size_type &num_erased) { //Now fully clear the intermediate buckets - const bucket_ptr buckets = priv_buckets(); + const bucket_ptr buckets = this->priv_bucket_pointer(); num_erased = 0; for(size_type i = first_bucket_num; i < (num_buckets + first_bucket_num); ++i){ bucket_type &b = buckets[i]; siterator b_begin(b.before_begin()); siterator nxt(b_begin); ++nxt; - siterator end(b.end()); - while(nxt != end){ - group_functions_t::init_group(dcast_bucket_ptr(nxt.pointed_node()), optimize_multikey_t()); + siterator end_sit(b.end()); + while(nxt != end_sit){ + group_functions_t::init_group(detail::dcast_bucket_ptr<node>(nxt.pointed_node()), optimize_multikey_t()); nxt = b.erase_after_and_dispose (b_begin, make_node_disposer(disposer)); this->priv_size_traits().decrement(); @@ -2467,217 +2930,35 @@ class hashtable_impl { size_type num_erased; if (first_bucket == last_bucket){ - priv_erase_range_impl(first_bucket, before_first_it, last_it, disposer, num_erased); + this->priv_erase_range_impl(first_bucket, before_first_it, last_it, disposer, num_erased); } else { - bucket_type *b = (&this->priv_buckets()[0]); - priv_erase_range_impl(first_bucket, before_first_it, b[first_bucket].end(), disposer, num_erased); + bucket_type *b = (&this->priv_bucket_pointer()[0]); + this->priv_erase_range_impl(first_bucket, before_first_it, b[first_bucket].end(), disposer, num_erased); if(size_type n = (last_bucket - first_bucket - 1)) - priv_erase_range_impl(first_bucket + 1, n, disposer, num_erased); - priv_erase_range_impl(last_bucket, b[last_bucket].before_begin(), last_it, disposer, num_erased); - } - } - - static node_ptr dcast_bucket_ptr(typename slist_impl::node_ptr p) - { return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*p)); } - - std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const - { return node_traits::get_hash(this->get_real_value_traits().to_node_ptr(v)); } - - std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const - { return priv_hasher()(v); } - - std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) const - { return node_traits::get_hash(dcast_bucket_ptr(n)); } - - std::size_t priv_stored_hash(slist_node_ptr, detail::false_) const - { - //This code should never be reached! - BOOST_INTRUSIVE_INVARIANT_ASSERT(0); - return 0; - } - - static void priv_clear_group_nodes(bucket_type &b, detail::true_) - { - siterator it(b.begin()), itend(b.end()); - while(it != itend){ - node_ptr to_erase(dcast_bucket_ptr(it.pointed_node())); - ++it; - group_algorithms::init(to_erase); + this->priv_erase_range_impl(first_bucket + 1, n, disposer, num_erased); + this->priv_erase_range_impl(last_bucket, b[last_bucket].before_begin(), last_it, disposer, num_erased); } } - static void priv_clear_group_nodes(bucket_type &, detail::false_) - {} - std::size_t priv_get_bucket_num(siterator it) - { return priv_get_bucket_num_hash_dispatch(it, store_hash_t()); } + { return this->priv_get_bucket_num_hash_dispatch(it, store_hash_t()); } - std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) + std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_) //store_hash { return this->priv_hash_to_bucket (this->priv_stored_hash(it.pointed_node(), store_hash_t())); } - std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) - { return priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); } - - std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_) - { - bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); - slist_node_ptr bb = group_functions_t::get_bucket_before_begin - ( f->end().pointed_node() - , l->end().pointed_node() - , dcast_bucket_ptr(it.pointed_node())); - //Now get the bucket_impl from the iterator - const bucket_type &b = static_cast<const bucket_type&> - (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb))); - //Now just calculate the index b has in the bucket array - return static_cast<size_type>(&b - &*f); - } - - std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_) - { - bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); - slist_node_ptr first_ptr(f->cend().pointed_node()) - , last_ptr(l->cend().pointed_node()); - - //The end node is embedded in the singly linked list: - //iterate until we reach it. - while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){ - ++it; - } - //Now get the bucket_impl from the iterator - const bucket_type &b = static_cast<const bucket_type&> - (bucket_type::container_from_end_iterator(it)); - - //Now just calculate the index b has in the bucket array - return static_cast<std::size_t>(&b - &*f); - } - - siterator priv_get_previous - (bucket_type &b, siterator i) - { return priv_get_previous(b, i, optimize_multikey_t()); } - - siterator priv_get_previous - (bucket_type &b, siterator i, detail::true_) - { - node_ptr elem(dcast_bucket_ptr(i.pointed_node())); - node_ptr prev_in_group(group_traits::get_next(elem)); - bool first_in_group = node_traits::get_next(prev_in_group) != elem; - typename bucket_type::node &n = first_in_group - ? *group_functions_t::get_prev_to_first_in_group(b.end().pointed_node(), elem) - : *group_traits::get_next(elem) - ; - return bucket_type::s_iterator_to(n); - } + std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_) //NO store_hash + { return this->data_type::internal.internal.internal.internal.priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); } - siterator priv_get_previous - (bucket_type &b, siterator i, detail::false_) - { return b.previous(i); } + static siterator priv_get_previous(bucket_type &b, siterator i) + { return bucket_plus_vtraits_t::priv_get_previous(b, i, optimize_multikey_t()); } static siterator priv_get_last(bucket_type &b) - { return priv_get_last(b, optimize_multikey_t()); } - - static siterator priv_get_last(bucket_type &b, detail::true_) - { - //First find the last node of p's group. - //This requires checking the first node of the next group or - //the bucket node. - slist_node_ptr end_ptr(b.end().pointed_node()); - node_ptr possible_end(node_traits::get_next( dcast_bucket_ptr(end_ptr))); - node_ptr last_node_group(possible_end); - - while(end_ptr != possible_end){ - last_node_group = group_traits::get_next(dcast_bucket_ptr(possible_end)); - possible_end = node_traits::get_next(last_node_group); - } - return bucket_type::s_iterator_to(*last_node_group); - } - - static siterator priv_get_last(bucket_type &b, detail::false_) - { return b.previous(b.end()); } -/* - siterator priv_get_previous_and_next_in_group - (siterator i, node_ptr &nxt_in_group) - { - siterator prev; - node_ptr elem(dcast_bucket_ptr(i.pointed_node())); - bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1); - - slist_node_ptr first_end_ptr(f->cend().pointed_node()); - slist_node_ptr last_end_ptr (l->cend().pointed_node()); + { return bucket_plus_vtraits_t::priv_get_last(b, optimize_multikey_t()); } - node_ptr nxt(node_traits::get_next(elem)); - node_ptr prev_in_group(group_traits::get_next(elem)); - bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr) || - (group_traits::get_next(nxt) != elem); - bool first_in_group = node_traits::get_next(prev_in_group) != elem; - - if(first_in_group){ - node_ptr start_pos; - if(last_in_group){ - start_pos = elem; - nxt_in_group = node_ptr(); - } - else{ - start_pos = prev_in_group; - nxt_in_group = node_traits::get_next(elem); - } - slist_node_ptr bucket_node; - if(store_hash){ - bucket_node = this->priv_buckets() - [this->priv_hash_to_bucket - (this->priv_stored_hash(elem, store_hash_t())) - ].before_begin().pointed_node(); - } - else{ - bucket_node = group_functions_t::get_bucket_before_begin - (first_end_ptr, last_end_ptr, start_pos); - } - prev = bucket_type::s_iterator_to - (*group_functions_t::get_prev_to_first_in_group(bucket_node, elem)); - } - else{ - if(last_in_group){ - nxt_in_group = group_functions_t::get_first_in_group_of_last_in_group(elem); - } - else{ - nxt_in_group = node_traits::get_next(elem); - } - prev = bucket_type::s_iterator_to(*group_traits::get_next(elem)); - } - return prev; - } -*/ - -/* - template<class Disposer> - void priv_erase(const_iterator i, Disposer disposer, detail::true_) - { - siterator elem(i.slist_it()); - node_ptr nxt_in_group; - siterator prev = priv_get_previous_and_next_in_group(elem, nxt_in_group); - bucket_type::s_erase_after_and_dispose(prev, make_node_disposer(disposer)); - if(nxt_in_group) - group_algorithms::unlink_after(nxt_in_group); - if(safemode_or_autounlink) - group_algorithms::init(dcast_bucket_ptr(elem.pointed_node())); - } -*/ - -/* - if(store_hash){ - bucket_node = this->priv_buckets() - [this->priv_hash_to_bucket - (this->priv_stored_hash(elem, store_hash_t())) - ].before_begin().pointed_node(); - } - else{ - bucket_node = group_functions_t::get_bucket_before_begin - (first_end_ptr, last_end_ptr, start_pos); - } -*/ template<class Disposer> void priv_erase(const_iterator i, Disposer disposer, detail::true_) { @@ -2685,14 +2966,14 @@ class hashtable_impl slist_node_ptr f_bucket_end, l_bucket_end; if(store_hash){ f_bucket_end = l_bucket_end = - (this->priv_buckets() + (this->priv_bucket_pointer() [this->priv_hash_to_bucket (this->priv_stored_hash(elem, store_hash_t())) ]).before_begin().pointed_node(); } else{ - f_bucket_end = this->priv_buckets()->cend().pointed_node(); - l_bucket_end = f_bucket_end + priv_buckets_len() - 1; + f_bucket_end = this->priv_bucket_pointer()->cend().pointed_node(); + l_bucket_end = f_bucket_end + this->priv_bucket_count() - 1; } node_ptr nxt_in_group; siterator prev = bucket_type::s_iterator_to @@ -2703,196 +2984,43 @@ class hashtable_impl if(nxt_in_group) group_algorithms::unlink_after(nxt_in_group); if(safemode_or_autounlink) - group_algorithms::init(dcast_bucket_ptr(elem)); + group_algorithms::init(detail::dcast_bucket_ptr<node>(elem)); } template <class Disposer> void priv_erase(const_iterator i, Disposer disposer, detail::false_) { siterator to_erase(i.slist_it()); - bucket_type &b = this->priv_buckets()[this->priv_get_bucket_num(to_erase)]; - siterator prev(priv_get_previous(b, to_erase)); + bucket_type &b = this->priv_bucket_pointer()[this->priv_get_bucket_num(to_erase)]; + siterator prev(this->priv_get_previous(b, to_erase)); b.erase_after_and_dispose(prev, make_node_disposer(disposer)); } - bucket_ptr priv_invalid_bucket() const - { - const real_bucket_traits &rbt = this->priv_real_bucket_traits(); - return rbt.bucket_begin() + rbt.bucket_count(); - } - - siterator priv_invalid_local_it() const - { return priv_invalid_bucket()->end(); } - - siterator priv_begin() const - { return priv_begin(cache_begin_t()); } - - siterator priv_begin(detail::false_) const - { - size_type n = 0; - size_type buckets_len = this->priv_buckets_len(); - for (n = 0; n < buckets_len; ++n){ - bucket_type &b = this->priv_buckets()[n]; - if(!b.empty()){ - return b.begin(); - } - } - return priv_invalid_local_it(); - } - - siterator priv_begin(detail::true_) const - { - if(this->data_.internal_.bucket_hash_equal_.cached_begin_ == priv_invalid_bucket()){ - return priv_invalid_local_it(); - } - else{ - return this->data_.internal_.bucket_hash_equal_.cached_begin_->begin(); - } - } - - void priv_initialize_cache() - { priv_initialize_cache(cache_begin_t()); } - - void priv_initialize_cache(detail::true_) - { this->data_.internal_.bucket_hash_equal_.cached_begin_ = priv_invalid_bucket(); } - - void priv_initialize_cache(detail::false_) - {} - - void priv_insertion_update_cache(size_type insertion_bucket) - { priv_insertion_update_cache(insertion_bucket, cache_begin_t()); } - - void priv_insertion_update_cache(size_type insertion_bucket, detail::true_) - { - bucket_ptr p = priv_buckets() + insertion_bucket; - if(p < this->data_.internal_.bucket_hash_equal_.cached_begin_){ - this->data_.internal_.bucket_hash_equal_.cached_begin_ = p; - } - } - - void priv_insertion_update_cache(size_type, detail::false_) - {} - - void priv_erasure_update_cache(size_type first_bucket, size_type last_bucket) - { priv_erasure_update_cache(first_bucket, last_bucket, cache_begin_t()); } - - void priv_erasure_update_cache(size_type first_bucket_num, size_type last_bucket_num, detail::true_) - { - //If the last bucket is the end, the cache must be updated - //to the last position if all - if(priv_get_cache_bucket_num() == first_bucket_num && - priv_buckets()[first_bucket_num].empty() ){ - priv_set_cache(priv_buckets() + last_bucket_num); - priv_erasure_update_cache(); - } - } - - void priv_erasure_update_cache(size_type, size_type, detail::false_) - {} - - void priv_erasure_update_cache() - { priv_erasure_update_cache(cache_begin_t()); } - - void priv_erasure_update_cache(detail::true_) - { - if(constant_time_size && !size()){ - priv_initialize_cache(); - } - else{ - size_type current_n = this->data_.internal_.bucket_hash_equal_.cached_begin_ - priv_buckets(); - for( const size_type num_buckets = this->priv_buckets_len() - ; current_n < num_buckets - ; ++current_n, ++this->data_.internal_.bucket_hash_equal_.cached_begin_){ - if(!this->data_.internal_.bucket_hash_equal_.cached_begin_->empty()){ - return; - } - } - priv_initialize_cache(); - } - } - - void priv_erasure_update_cache(detail::false_) - {} - - void priv_swap_cache(detail::true_, hashtable_impl &other) - { - std::swap( this->data_.internal_.bucket_hash_equal_.cached_begin_ - , other.data_.internal_.bucket_hash_equal_.cached_begin_); - } - - void priv_swap_cache(detail::false_, hashtable_impl &) - {} - - bucket_ptr priv_get_cache() - { return priv_get_cache(cache_begin_t()); } - - bucket_ptr priv_get_cache(detail::true_) - { return this->data_.internal_.bucket_hash_equal_.cached_begin_; } - - bucket_ptr priv_get_cache(detail::false_) - { return this->priv_buckets(); } - - void priv_set_cache(const bucket_ptr &p) - { this->data_.internal_.bucket_hash_equal_.set_cache(p); } - - size_type priv_get_cache_bucket_num() - { return priv_get_cache_bucket_num(cache_begin_t()); } - - size_type priv_get_cache_bucket_num(detail::true_) - { return this->data_.internal_.bucket_hash_equal_.cached_begin_ - this->priv_buckets(); } - - size_type priv_get_cache_bucket_num(detail::false_) - { return 0u; } - - void priv_clear_buckets() - { - this->priv_clear_buckets - ( priv_get_cache() - , this->priv_buckets_len() - (priv_get_cache() - priv_buckets())); - } - - void priv_initialize_buckets() - { this->priv_clear_buckets(priv_buckets(), this->priv_buckets_len()); } - - void priv_clear_buckets(bucket_ptr buckets_ptr, size_type buckets_len) - { - for(; buckets_len--; ++buckets_ptr){ - if(safemode_or_autounlink){ - priv_clear_group_nodes(*buckets_ptr, optimize_multikey_t()); - buckets_ptr->clear_and_dispose(detail::init_disposer<node_algorithms>()); - } - else{ - buckets_ptr->clear(); - } - } - priv_initialize_cache(); - } - template<class KeyType, class KeyHasher, class KeyValueEqual> siterator priv_find ( const KeyType &key, KeyHasher hash_func , KeyValueEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const { h = hash_func(key); - return priv_find_with_hash(key, equal_func, bucket_number, h, previt); + return this->priv_find_with_hash(key, equal_func, bucket_number, h, previt); } template<class KeyType, class KeyValueEqual> siterator priv_find_with_hash ( const KeyType &key, KeyValueEqual equal_func, size_type &bucket_number, const std::size_t h, siterator &previt) const { - bucket_number = priv_hash_to_bucket(h); - bucket_type &b = this->priv_buckets()[bucket_number]; + bucket_number = this->priv_hash_to_bucket(h); + bucket_type &b = this->priv_bucket_pointer()[bucket_number]; previt = b.before_begin(); if(constant_time_size && this->empty()){ - return priv_invalid_local_it(); + return this->priv_invalid_local_it(); } siterator it = previt; ++it; while(it != b.end()){ - const value_type &v = priv_value_from_slist_node(it.pointed_node()); + const value_type &v = this->priv_value_from_slist_node(it.pointed_node()); if(compare_hash){ std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t()); if(h == vh && equal_func(key, v)){ @@ -2905,7 +3033,7 @@ class hashtable_impl if(optimize_multikey){ previt = bucket_type::s_iterator_to (*group_functions_t::get_last_in_group - (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t())); + (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t())); it = previt; } else{ @@ -2914,7 +3042,7 @@ class hashtable_impl ++it; } previt = b.before_begin(); - return priv_invalid_local_it(); + return this->priv_invalid_local_it(); } iterator priv_insert_equal_with_hash(reference value, std::size_t hash_value) @@ -2923,33 +3051,33 @@ class hashtable_impl siterator prev; siterator it = this->priv_find_with_hash (value, this->priv_equal(), bucket_num, hash_value, prev); - return priv_insert_equal_find(value, bucket_num, hash_value, it); + return this->priv_insert_equal_find(value, bucket_num, hash_value, it); } iterator priv_insert_equal_find(reference value, size_type bucket_num, std::size_t hash_value, siterator it) { - bucket_type &b = this->priv_buckets()[bucket_num]; - bool found_equal = it != priv_invalid_local_it(); + bucket_type &b = this->priv_bucket_pointer()[bucket_num]; + bool found_equal = it != this->priv_invalid_local_it(); if(!found_equal){ it = b.before_begin(); } //Now store hash if needed - node_ptr n = pointer_traits<node_ptr>::pointer_to(priv_value_to_node(value)); + node_ptr n = pointer_traits<node_ptr>::pointer_to(this->priv_value_to_node(value)); node_functions_t::store_hash(n, hash_value, store_hash_t()); //Checks for some modes if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n)); - //Shorcut for optimize_multikey cases + //Shortcut for optimize_multikey cases if(optimize_multikey){ node_ptr first_in_group = found_equal ? - dcast_bucket_ptr(it.pointed_node()) : node_ptr(); + detail::dcast_bucket_ptr<node>(it.pointed_node()) : node_ptr(); group_functions_t::insert_in_group(first_in_group, n, optimize_multikey_t()); } //Update cache and increment size if needed - priv_insertion_update_cache(bucket_num); + this->priv_insertion_update_cache(bucket_num); this->priv_size_traits().increment(); //Insert the element in the bucket after it - return iterator(b.insert_after(it, *n), this); + return iterator(b.insert_after(it, *n), &this->get_bucket_value_traits()); } template<class KeyType, class KeyHasher, class KeyValueEqual> @@ -2959,61 +3087,65 @@ class hashtable_impl , KeyValueEqual equal_func , size_type &bucket_number_first , size_type &bucket_number_second - , size_type &count) const + , size_type &cnt) const { std::size_t h; - count = 0; + cnt = 0; siterator prev; //Let's see if the element is present std::pair<siterator, siterator> to_return - ( priv_find(key, hash_func, equal_func, bucket_number_first, h, prev) - , priv_invalid_local_it()); + ( this->priv_find(key, hash_func, equal_func, bucket_number_first, h, prev) + , this->priv_invalid_local_it()); if(to_return.first == to_return.second){ bucket_number_second = bucket_number_first; return to_return; } - //If it's present, find the first that it's not equal in - //the same bucket - bucket_type &b = this->priv_buckets()[bucket_number_first]; - siterator it = to_return.first; - if(optimize_multikey){ - to_return.second = bucket_type::s_iterator_to - (*node_traits::get_next(group_functions_t::get_last_in_group - (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()))); - count = std::distance(it, to_return.second); - if(to_return.second != b.end()){ - bucket_number_second = bucket_number_first; - return to_return; + { + //If it's present, find the first that it's not equal in + //the same bucket + bucket_type &b = this->priv_bucket_pointer()[bucket_number_first]; + siterator it = to_return.first; + if(optimize_multikey){ + to_return.second = bucket_type::s_iterator_to + (*node_traits::get_next(group_functions_t::get_last_in_group + (detail::dcast_bucket_ptr<node>(it.pointed_node()), optimize_multikey_t()))); + + cnt = 0; + for(; it != to_return.second; ++it){ ++cnt; } + if(to_return.second != b.end()){ + bucket_number_second = bucket_number_first; + return to_return; + } } - } - else{ - ++count; - ++it; - while(it != b.end()){ - const value_type &v = priv_value_from_slist_node(it.pointed_node()); - if(compare_hash){ - std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t()); - if(hv != h || !equal_func(key, v)){ + else{ + ++cnt; + ++it; + while(it != b.end()){ + const value_type &v = this->priv_value_from_slist_node(it.pointed_node()); + if(compare_hash){ + std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t()); + if(hv != h || !equal_func(key, v)){ + to_return.second = it; + bucket_number_second = bucket_number_first; + return to_return; + } + } + else if(!equal_func(key, v)){ to_return.second = it; bucket_number_second = bucket_number_first; return to_return; } + ++it; + ++cnt; } - else if(!equal_func(key, v)){ - to_return.second = it; - bucket_number_second = bucket_number_first; - return to_return; - } - ++it; - ++count; } } //If we reached the end, find the first, non-empty bucket for(bucket_number_second = bucket_number_first+1 - ; bucket_number_second != this->priv_buckets_len() + ; bucket_number_second != this->priv_bucket_count() ; ++bucket_number_second){ - bucket_type &b = this->priv_buckets()[bucket_number_second]; + bucket_type &b = this->priv_bucket_pointer()[bucket_number_second]; if(!b.empty()){ to_return.second = b.begin(); return to_return; @@ -3021,7 +3153,7 @@ class hashtable_impl } //Otherwise, return the end node - to_return.second = priv_invalid_local_it(); + to_return.second = this->priv_invalid_local_it(); return to_return; } /// @endcond @@ -3031,42 +3163,23 @@ class hashtable_impl #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T , bool UniqueKeys - , class O1 = none, class O2 = none - , class O3 = none, class O4 = none - , class O5 = none, class O6 = none - , class O7 = none, class O8 = none - , class O9 = none, class O10= none + , class PackedOptions > #else template <class T, bool UniqueKeys, class ...Options> #endif -struct make_hashtable_opt +struct make_bucket_traits { - typedef typename pack_options - < uset_defaults<T>, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 - #else - Options... - #endif - >::type packed_options; - //Real value traits must be calculated from options typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; - typedef typename packed_options::bucket_traits specified_bucket_traits; + <T, typename PackedOptions::proto_value_traits>::type value_traits; + + typedef typename PackedOptions::bucket_traits specified_bucket_traits; //Real bucket traits must be calculated from options and calculated value_traits typedef typename detail::get_slist_impl <typename detail::reduced_slist_node_traits - <typename real_value_traits::node_traits>::type + <typename value_traits::node_traits>::type >::type slist_impl; typedef typename @@ -3076,21 +3189,7 @@ struct make_hashtable_opt >::value , detail::bucket_traits_impl<slist_impl> , specified_bucket_traits - >::type real_bucket_traits; - - typedef detail::usetopt - < value_traits - , typename packed_options::hash - , typename packed_options::equal - , typename packed_options::size_type - , real_bucket_traits - , (std::size_t(UniqueKeys)*detail::hash_bool_flags::unique_keys_pos) - | (std::size_t(packed_options::constant_time_size)*detail::hash_bool_flags::constant_time_size_pos) - | (std::size_t(packed_options::power_2_buckets)*detail::hash_bool_flags::power_2_buckets_pos) - | (std::size_t(packed_options::cache_begin)*detail::hash_bool_flags::cache_begin_pos) - | (std::size_t(packed_options::compare_hash)*detail::hash_bool_flags::compare_hash_pos) - | (std::size_t(packed_options::incremental)*detail::hash_bool_flags::incremental_pos) - > type; + >::type type; }; /// @endcond @@ -3099,25 +3198,43 @@ struct make_hashtable_opt #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - , class O5 = none, class O6 = none - , class O7 = none, class O8 = none - , class O9 = none, class O10= none +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void, class O6 = void + , class O7 = void, class O8 = void + , class O9 = void, class O10= void > #endif struct make_hashtable { /// @cond + typedef typename pack_options + < hashtable_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + + typedef typename make_bucket_traits + <T, false, packed_options>::type bucket_traits; + typedef hashtable_impl - < typename make_hashtable_opt - <T, false, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 - #else - Options... - #endif - >::type + < value_traits + , typename packed_options::hash + , typename packed_options::equal + , typename packed_options::size_type + , bucket_traits + , (std::size_t(false)*hash_bool_flags::unique_keys_pos) + | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos) + | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos) + | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos) + | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos) + | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos) > implementation_defined; /// @endcond @@ -3151,7 +3268,6 @@ class hashtable public: typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; typedef typename Base::bucket_ptr bucket_ptr; @@ -3161,9 +3277,9 @@ class hashtable typedef typename Base::key_equal key_equal; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - hashtable ( const bucket_traits &b_traits + explicit hashtable ( const bucket_traits &b_traits , const hasher & hash_func = hasher() , const key_equal &equal_func = key_equal() , const value_traits &v_traits = value_traits()) @@ -3175,7 +3291,7 @@ class hashtable {} hashtable& operator=(BOOST_RV_REF(hashtable) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<hashtable&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } }; #endif diff --git a/boost/intrusive/intrusive_fwd.hpp b/boost/intrusive/intrusive_fwd.hpp index c95767ef35..a4498161a1 100644 --- a/boost/intrusive/intrusive_fwd.hpp +++ b/boost/intrusive/intrusive_fwd.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,21 +13,51 @@ #ifndef BOOST_INTRUSIVE_FWD_HPP #define BOOST_INTRUSIVE_FWD_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +//! \file +//! This header file forward declares most Intrusive classes. +//! +//! It forward declares the following containers and hooks: +//! - boost::intrusive::slist / boost::intrusive::slist_base_hook / boost::intrusive::slist_member_hook +//! - boost::intrusive::list / boost::intrusive::list_base_hook / boost::intrusive::list_member_hook +//! - boost::intrusive::bstree / boost::intrusive::bs_set / boost::intrusive::bs_multiset / +//! boost::intrusive::bs_set_base_hook / boost::intrusive::bs_set_member_hook +//! - boost::intrusive::rbtree / boost::intrusive::set / boost::intrusive::multiset / +//! boost::intrusive::set_base_hook / boost::intrusive::set_member_hook +//! - boost::intrusive::avltree / boost::intrusive::avl_set / boost::intrusive::avl_multiset / +//! boost::intrusive::avl_set_base_hook / boost::intrusive::avl_set_member_hook +//! - boost::intrusive::splaytree / boost::intrusive::splay_set / boost::intrusive::splay_multiset +//! - boost::intrusive::sgtree / boost::intrusive::sg_set / boost::intrusive::sg_multiset +//! - boost::intrusive::treap / boost::intrusive::treap_set / boost::intrusive::treap_multiset +//! - boost::intrusive::hashtable / boost::intrusive::unordered_set / boost::intrusive::unordered_multiset / +//! boost::intrusive::unordered_set_base_hook / boost::intrusive::unordered_set_member_hook / +//! - boost::intrusive::any_base_hook / boost::intrusive::any_member_hook +//! +//! It forward declares the following container or hook options: +//! - boost::intrusive::constant_time_size / boost::intrusive::size_type / boost::intrusive::compare / boost::intrusive::equal +//! - boost::intrusive::floating_point / boost::intrusive::priority / boost::intrusive::hash +//! - boost::intrusive::value_traits / boost::intrusive::member_hook / boost::intrusive::function_hook / boost::intrusive::base_hook +//! - boost::intrusive::void_pointer / boost::intrusive::tag / boost::intrusive::link_mode +//! - boost::intrusive::optimize_size / boost::intrusive::linear / boost::intrusive::cache_last +//! - boost::intrusive::bucket_traits / boost::intrusive::store_hash / boost::intrusive::optimize_multikey +//! - boost::intrusive::power_2_buckets / boost::intrusive::cache_begin / boost::intrusive::compare_hash / boost::intrusive::incremental +//! +//! It forward declares the following value traits utilities: +//! - boost::intrusive::value_traits / boost::intrusive::derivation_value_traits / +//! boost::intrusive::trivial_value_traits +//! +//! Finally it forward declares the following general purpose utilities: +//! - boost::intrusive::pointer_plus_bits / boost::intrusive::priority_compare. + +#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + #include <cstddef> #include <boost/intrusive/link_mode.hpp> #include <boost/intrusive/detail/workaround.hpp> -/// @cond - -namespace boost { - -namespace intrusive { - -struct none; - -} //namespace intrusive{ -} //namespace boost{ - namespace boost { namespace intrusive { @@ -43,43 +73,62 @@ template<class NodeTraits> class circular_slist_algorithms; template<class NodeTraits> +class linear_slist_algorithms; + +template<class NodeTraits> +class bstree_algorithms; + +template<class NodeTraits> class rbtree_algorithms; +template<class NodeTraits> +class avltree_algorithms; + +template<class NodeTraits> +class sgtree_algorithms; + +template<class NodeTraits> +class splaytree_algorithms; + +template<class NodeTraits> +class treap_algorithms; + //////////////////////////// // Containers //////////////////////////// //slist -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none - , class O5 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void > #else template<class T, class ...Options> #endif class slist; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class slist_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> @@ -87,109 +136,102 @@ template<class ...Options> class slist_member_hook; //list -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class T, class ...Options> #endif class list; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class list_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class list_member_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template - < class O1 = none - , class O2 = none - , class O3 = none - > -#else -template<class ...Options> -#endif -class list_hook; - //rbtree/set/multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class rbtree; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class multiset; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> #endif class set_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> @@ -197,125 +239,109 @@ template<class ...Options> class set_member_hook; //splaytree/splay_set/splay_multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class splaytree; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class splay_set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class splay_multiset; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template - < class O1 = none - , class O2 = none - , class O3 = none - > -#else -template<class ...Options> -#endif -class splay_set_base_hook; - -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template - < class O1 = none - , class O2 = none - , class O3 = none - > -#else -template<class ...Options> -#endif -class splay_set_member_hook; - //avltree/avl_set/avl_multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class avltree; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class avl_set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class avl_multiset; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> #endif class avl_set_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> @@ -324,105 +350,149 @@ class avl_set_member_hook; //treap/treap_set/treap_multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class treap; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class treap_set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class treap_multiset; -//Default priority comparison functor -template <class T> -struct priority_compare; - //sgtree/sg_set/sg_multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class sgtree; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class sg_set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void > #else template<class T, class ...Options> #endif class sg_multiset; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template + < class T + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + > +#else +template<class T, class ...Options> +#endif +class bstree; + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class T + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + > +#else +template<class T, class ...Options> +#endif +class bs_set; + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template + < class T + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + > +#else +template<class T, class ...Options> +#endif +class bs_multiset; + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +template + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class bs_set_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> @@ -431,112 +501,229 @@ class bs_set_member_hook; //hashtable/unordered_set/unordered_multiset -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none - , class O5 = none - , class O6 = none - , class O7 = none - , class O8 = none - , class O9 = none - , class O10 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void + , class O7 = void + , class O8 = void + , class O9 = void + , class O10 = void > #else template<class T, class ...Options> #endif class hashtable; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none - , class O5 = none - , class O6 = none - , class O7 = none - , class O8 = none - , class O9 = none - , class O10 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void + , class O7 = void + , class O8 = void + , class O9 = void + , class O10 = void > #else template<class T, class ...Options> #endif class unordered_set; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template < class T - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none - , class O5 = none - , class O6 = none - , class O7 = none - , class O8 = none - , class O9 = none - , class O10 = none + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void + , class O7 = void + , class O8 = void + , class O9 = void + , class O10 = void > #else template<class T, class ...Options> #endif class unordered_multiset; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> #endif class unordered_set_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none + < class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void > #else template<class ...Options> #endif class unordered_set_member_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class any_base_hook; -#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template - < class O1 = none - , class O2 = none - , class O3 = none + < class O1 = void + , class O2 = void + , class O3 = void > #else template<class ...Options> #endif class any_member_hook; +//Options + +template<bool Enabled> +struct constant_time_size; + +template<typename SizeType> +struct size_type; + +template<typename Compare> +struct compare; + +template<bool Enabled> +struct floating_point; + +template<typename Equal> +struct equal; + +template<typename Priority> +struct priority; + +template<typename Hash> +struct hash; + +template<typename ValueTraits> struct value_traits; + +template< typename Parent + , typename MemberHook + , MemberHook Parent::* PtrToMember> +struct member_hook; + +template<typename Functor> +struct function_hook; + +template<typename BaseHook> +struct base_hook; + +template<typename VoidPointer> +struct void_pointer; + +template<typename Tag> +struct tag; + +template<link_mode_type LinkType> +struct link_mode; + +template<bool Enabled> struct +optimize_size; + +template<bool Enabled> +struct linear; + +template<bool Enabled> +struct cache_last; + +template<typename BucketTraits> +struct bucket_traits; + +template<bool Enabled> +struct store_hash; + +template<bool Enabled> +struct optimize_multikey; + +template<bool Enabled> +struct power_2_buckets; + +template<bool Enabled> +struct cache_begin; + +template<bool Enabled> +struct compare_hash; + +template<bool Enabled> +struct incremental; + +//Value traits + +template<typename ValueTraits> +struct value_traits; + +template< typename Parent + , typename MemberHook + , MemberHook Parent::* PtrToMember> +struct member_hook; + +template< typename Functor> +struct function_hook; + +template<typename BaseHook> +struct base_hook; + +template<class T, class NodeTraits, link_mode_type LinkMode = safe_link> +struct derivation_value_traits; + +template<class NodeTraits, link_mode_type LinkMode = normal_link> +struct trivial_value_traits; + +//Additional utilities + +template<typename VoidPointer, std::size_t Alignment> +struct max_pointer_plus_bits; + +template<std::size_t Alignment> +struct max_pointer_plus_bits<void *, Alignment>; + +template<typename Pointer, std::size_t NumBits> +struct pointer_plus_bits; + +template<typename T, std::size_t NumBits> +struct pointer_plus_bits<T *, NumBits>; + +template<typename Ptr> +struct pointer_traits; + +template<typename T> +struct pointer_traits<T *>; + } //namespace intrusive { } //namespace boost { -/// @endcond +#endif //#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) #endif //#ifndef BOOST_INTRUSIVE_FWD_HPP diff --git a/boost/intrusive/linear_slist_algorithms.hpp b/boost/intrusive/linear_slist_algorithms.hpp index db4092d2c9..31e5594384 100644 --- a/boost/intrusive/linear_slist_algorithms.hpp +++ b/boost/intrusive/linear_slist_algorithms.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,9 +14,14 @@ #ifndef BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP #define BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/common_slist_algorithms.hpp> +#include <boost/intrusive/detail/algo_type.hpp> #include <cstddef> #include <utility> @@ -319,6 +324,16 @@ class linear_slist_algorithms } }; +/// @cond + +template<class NodeTraits> +struct get_algo<LinearSListAlgorithms, NodeTraits> +{ + typedef linear_slist_algorithms<NodeTraits> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/link_mode.hpp b/boost/intrusive/link_mode.hpp index c04f77526e..c7245d9c1f 100644 --- a/boost/intrusive/link_mode.hpp +++ b/boost/intrusive/link_mode.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -10,8 +10,12 @@ // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_VALUE_LINK_TYPE_HPP -#define BOOST_INTRUSIVE_VALUE_LINK_TYPE_HPP +#ifndef BOOST_INTRUSIVE_LINK_MODE_HPP +#define BOOST_INTRUSIVE_LINK_MODE_HPP + +#if defined(_MSC_VER) +# pragma once +#endif namespace boost { namespace intrusive { @@ -40,7 +44,20 @@ enum link_mode_type{ //!the container without using any function provided by the containers. auto_unlink }; + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +template <link_mode_type link_mode> +struct is_safe_autounlink +{ + static const bool value = + (int)link_mode == (int)auto_unlink || + (int)link_mode == (int)safe_link; +}; + +#endif //BOOST_INTRUSIVE_DOXYGEN_INVOKED + } //namespace intrusive } //namespace boost -#endif //BOOST_INTRUSIVE_VALUE_LINK_TYPE_HPP +#endif //BOOST_INTRUSIVE_LINK_MODE_HPP diff --git a/boost/intrusive/list.hpp b/boost/intrusive/list.hpp index 5450bc5d81..297267d34b 100644 --- a/boost/intrusive/list.hpp +++ b/boost/intrusive/list.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,48 +14,57 @@ #ifndef BOOST_INTRUSIVE_LIST_HPP #define BOOST_INTRUSIVE_LIST_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/intrusive_fwd.hpp> +#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/list_hook.hpp> #include <boost/intrusive/circular_list_algorithms.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/link_mode.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> +#include <boost/intrusive/detail/default_header_holder.hpp> +#include <boost/intrusive/detail/reverse_iterator.hpp> +#include <boost/intrusive/detail/uncast.hpp> +#include <boost/intrusive/detail/list_iterator.hpp> +#include <boost/intrusive/detail/array_initializer.hpp> +#include <boost/intrusive/detail/exception_disposer.hpp> +#include <boost/intrusive/detail/equal_to_value.hpp> +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> +#include <boost/intrusive/detail/simple_disposers.hpp> +#include <boost/intrusive/detail/size_holder.hpp> + +#include <boost/move/utility_core.hpp> #include <boost/static_assert.hpp> -#include <boost/intrusive/options.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <iterator> + #include <algorithm> #include <functional> #include <cstddef> -#include <boost/move/move.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class SizeType, bool ConstantTimeSize> -struct listopt -{ - typedef ValueTraits value_traits; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; -}; +struct default_list_hook_applier +{ template <class T> struct apply{ typedef typename T::default_list_hook type; }; }; +template<> +struct is_default_hook_tag<default_list_hook_applier> +{ static const bool value = true; }; -template <class T> struct list_defaults - : pack_options - < none - , base_hook<detail::default_list_hook> - , constant_time_size<true> - , size_type<std::size_t> - >::type -{}; +{ + typedef default_list_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void header_holder_type; +}; /// @endcond @@ -72,43 +81,35 @@ struct list_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class list_impl - : private detail::clear_on_destructor_base< list_impl<Config> > { - template<class C> friend class detail::clear_on_destructor_base; //Public typedefs public: - typedef typename Config::value_traits value_traits; - /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; - /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; + typedef ValueTraits value_traits; + typedef typename value_traits::pointer pointer; + typedef typename value_traits::const_pointer const_pointer; typedef typename pointer_traits<pointer>::element_type value_type; typedef typename pointer_traits<pointer>::reference reference; typedef typename pointer_traits<const_pointer>::reference const_reference; typedef typename pointer_traits<pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef list_iterator<list_impl, false> iterator; - typedef list_iterator<list_impl, true> const_iterator; + typedef SizeType size_type; + typedef list_iterator<value_traits, false> iterator; + typedef list_iterator<value_traits, true> const_iterator; typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; + typedef typename value_traits::node_traits node_traits; typedef typename node_traits::node node; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; typedef circular_list_algorithms<node_traits> node_algorithms; + typedef HeaderHolder header_holder_type; - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + static const bool constant_time_size = ConstantTimeSize; + static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; + static const bool has_container_from_iterator = + detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value; /// @cond @@ -118,34 +119,28 @@ class list_impl //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(list_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; //Constant-time size is incompatible with auto-unlink hooks! BOOST_STATIC_ASSERT(!(constant_time_size && - ((int)real_value_traits::link_mode == (int)auto_unlink) + ((int)value_traits::link_mode == (int)auto_unlink) )); - //Const cast emulation for smart pointers - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - node_ptr get_root_node() - { return pointer_traits<node_ptr>::pointer_to(data_.root_plus_size_.root_); } + { return data_.root_plus_size_.m_header.get_node(); } const_node_ptr get_root_node() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.root_plus_size_.root_); } + { return data_.root_plus_size_.m_header.get_node(); } struct root_plus_size : public size_traits { - node root_; + header_holder_type m_header; }; struct data_t : public value_traits { typedef typename list_impl::value_traits value_traits; - data_t(const value_traits &val_traits) + explicit data_t(const value_traits &val_traits) : value_traits(val_traits) {} @@ -158,51 +153,29 @@ class list_impl const size_traits &priv_size_traits() const { return data_.root_plus_size_; } - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } - - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } - - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } - const value_traits &priv_value_traits() const { return data_; } value_traits &priv_value_traits() { return data_; } - protected: - node &prot_root_node() - { return data_.root_plus_size_.root_; } + typedef typename boost::intrusive::value_traits_pointers + <ValueTraits>::const_value_traits_ptr const_value_traits_ptr; - node const &prot_root_node() const - { return data_.root_plus_size_.root_; } - - void prot_set_size(size_type s) - { data_.root_plus_size_.set_size(s); } + const_value_traits_ptr priv_value_traits_ptr() const + { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); } /// @endcond public: - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - //! <b>Effects</b>: constructs an empty list. //! //! <b>Complexity</b>: Constant //! - //! <b>Throws</b>: If real_value_traits::node_traits::node + //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). - list_impl(const value_traits &v_traits = value_traits()) + explicit list_impl(const value_traits &v_traits = value_traits()) : data_(v_traits) { this->priv_size_traits().set_size(size_type(0)); @@ -215,14 +188,16 @@ class list_impl //! //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called. //! - //! <b>Throws</b>: If real_value_traits::node_traits::node + //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). template<class Iterator> list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits()) : data_(v_traits) { + //nothrow, no need to rollback to release elements on exception this->priv_size_traits().set_size(size_type(0)); node_algorithms::init_header(this->get_root_node()); + //nothrow, no need to rollback to release elements on exception this->insert(this->cend(), b, e); } @@ -233,6 +208,7 @@ class list_impl { this->priv_size_traits().set_size(size_type(0)); node_algorithms::init_header(this->get_root_node()); + //nothrow, no need to rollback to release elements on exception this->swap(x); } @@ -251,7 +227,12 @@ class list_impl //! <b>Complexity</b>: Linear to the number of elements in the list, if //! it's a safe-mode or auto-unlink value . Otherwise constant. ~list_impl() - {} + { + if(is_safe_autounlink<ValueTraits::link_mode>::value){ + this->clear(); + node_algorithms::init(this->get_root_node()); + } + } //! <b>Requires</b>: value must be an lvalue. //! @@ -265,7 +246,7 @@ class list_impl //! <b>Note</b>: Does not affect the validity of iterators and references. void push_back(reference value) { - node_ptr to_insert = get_real_value_traits().to_node_ptr(value); + node_ptr to_insert = priv_value_traits().to_node_ptr(value); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert)); node_algorithms::link_before(this->get_root_node(), to_insert); @@ -284,7 +265,7 @@ class list_impl //! <b>Note</b>: Does not affect the validity of iterators and references. void push_front(reference value) { - node_ptr to_insert = get_real_value_traits().to_node_ptr(value); + node_ptr to_insert = priv_value_traits().to_node_ptr(value); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert)); node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert); @@ -321,7 +302,7 @@ class list_impl this->priv_size_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); } //! <b>Effects</b>: Erases the first element of the list. @@ -354,7 +335,7 @@ class list_impl this->priv_size_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); } //! <b>Effects</b>: Returns a reference to the first element of the list. @@ -363,7 +344,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. reference front() - { return *get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } + { return *priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } //! <b>Effects</b>: Returns a const_reference to the first element of the list. //! @@ -371,7 +352,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. const_reference front() const - { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); } + { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_next(this->get_root_node()))); } //! <b>Effects</b>: Returns a reference to the last element of the list. //! @@ -379,7 +360,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. reference back() - { return *get_real_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); } + { return *priv_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); } //! <b>Effects</b>: Returns a const_reference to the last element of the list. //! @@ -387,7 +368,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. const_reference back() const - { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_previous(this->get_root_node()))); } + { return *priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_previous(this->get_root_node()))); } //! <b>Effects</b>: Returns an iterator to the first element contained in the list. //! @@ -395,7 +376,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. iterator begin() - { return iterator(node_traits::get_next(this->get_root_node()), this); } + { return iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. //! @@ -411,7 +392,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. const_iterator cbegin() const - { return const_iterator(node_traits::get_next(this->get_root_node()), this); } + { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns an iterator to the end of the list. //! @@ -419,7 +400,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. iterator end() - { return iterator(this->get_root_node(), this); } + { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the end of the list. //! @@ -435,7 +416,7 @@ class list_impl //! //! <b>Complexity</b>: Constant. const_iterator cend() const - { return const_iterator(uncast(this->get_root_node()), this); } + { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning //! of the reversed list. @@ -637,15 +618,15 @@ class list_impl //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased elements. - iterator erase(const_iterator b, const_iterator e, difference_type n) + iterator erase(const_iterator b, const_iterator e, size_type n) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(b, e) == difference_type(n)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(b.pointed_node(), e.pointed_node()) == n); if(safemode_or_autounlink || constant_time_size){ return this->erase_and_dispose(b, e, detail::null_disposer()); } else{ if(constant_time_size){ - this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n); + this->priv_size_traits().decrease(n); } node_algorithms::unlink(b.pointed_node(), e.pointed_node()); return e.unconst(); @@ -675,7 +656,7 @@ class list_impl this->priv_size_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(this->get_real_value_traits().to_value_ptr(to_erase)); + disposer(this->priv_value_traits().to_value_ptr(to_erase)); return i.unconst(); } @@ -709,7 +690,7 @@ class list_impl bp = node_traits::get_next(bp); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); this->priv_size_traits().decrement(); } return e.unconst(); @@ -755,7 +736,7 @@ class list_impl ++it; if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); } node_algorithms::init_header(this->get_root_node()); this->priv_size_traits().set_size(0); @@ -801,12 +782,12 @@ class list_impl //! <b>Note</b>: Does not affect the validity of iterators and references. iterator insert(const_iterator p, reference value) { - node_ptr to_insert = this->get_real_value_traits().to_node_ptr(value); + node_ptr to_insert = this->priv_value_traits().to_node_ptr(value); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert)); node_algorithms::link_before(p.pointed_node(), to_insert); this->priv_size_traits().increment(); - return iterator(to_insert, this); + return iterator(to_insert, this->priv_value_traits_ptr()); } //! <b>Requires</b>: Dereferencing iterator must yield @@ -886,11 +867,11 @@ class list_impl void splice(const_iterator p, list_impl& x) { if(!x.empty()){ - size_traits &thist = this->priv_size_traits(); - size_traits &xt = x.priv_size_traits(); node_algorithms::transfer (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node()); - thist.set_size(thist.get_size() + xt.get_size()); + size_traits &thist = this->priv_size_traits(); + size_traits &xt = x.priv_size_traits(); + thist.increase(xt.get_size()); xt.set_size(size_type(0)); } } @@ -899,7 +880,7 @@ class list_impl //! new_ele must point to an element contained in list x. //! //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list, - //! before the the element pointed by p. No destructors or copy constructors are called. + //! before the element pointed by p. No destructors or copy constructors are called. //! If p == new_ele or p == ++new_ele, this function is a null operation. //! //! <b>Throws</b>: Nothing. @@ -916,10 +897,10 @@ class list_impl } //! <b>Requires</b>: p must be a valid iterator of *this. - //! start and end must point to elements contained in list x. + //! f and e must point to elements contained in list x. //! - //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list, - //! before the the element pointed by p. No destructors or copy constructors are called. + //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list, + //! before the element pointed by p. No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. //! @@ -928,20 +909,20 @@ class list_impl //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end) + void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e) { if(constant_time_size) - this->splice(p, x, start, end, std::distance(start, end)); + this->splice(p, x, f, e, node_algorithms::distance(f.pointed_node(), e.pointed_node())); else - this->splice(p, x, start, end, 1);//distance is a dummy value + this->splice(p, x, f, e, 1);//distance is a dummy value } //! <b>Requires</b>: p must be a valid iterator of *this. - //! start and end must point to elements contained in list x. - //! n == std::distance(start, end) + //! f and e must point to elements contained in list x. + //! n == std::distance(f, e) //! - //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list, - //! before the the element pointed by p. No destructors or copy constructors are called. + //! <b>Effects</b>: Transfers the range pointed by f and e from list x to this list, + //! before the element pointed by p. No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. //! @@ -949,19 +930,19 @@ class list_impl //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end, difference_type n) + void splice(const_iterator p, list_impl&x, const_iterator f, const_iterator e, size_type n) { if(n){ if(constant_time_size){ + BOOST_INTRUSIVE_INVARIANT_ASSERT(n == node_algorithms::distance(f.pointed_node(), e.pointed_node())); + node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); size_traits &thist = this->priv_size_traits(); size_traits &xt = x.priv_size_traits(); - BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(start, end)); - node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node()); - thist.set_size(thist.get_size() + n); - xt.set_size(xt.get_size() - n); + thist.increase(n); + xt.decrease(n); } else{ - node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node()); + node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node()); } } } @@ -969,7 +950,7 @@ class list_impl //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>. //! The sort is stable, that is, the relative order of equivalent elements is preserved. //! - //! <b>Throws</b>: If real_value_traits::node_traits::node + //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or std::less<value_type> throws. Basic guarantee. //! @@ -985,7 +966,7 @@ class list_impl //! <b>Effects</b>: This function sorts the list *this according to p. The sort is //! stable, that is, the relative order of equivalent elements is preserved. //! - //! <b>Throws</b>: If real_value_traits::node_traits::node + //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the predicate throws. Basic guarantee. //! @@ -1121,7 +1102,17 @@ class list_impl //! and iterators to elements that are not removed remain valid. template<class Pred> void remove_if(Pred pred) - { this->remove_and_dispose_if(pred, detail::null_disposer()); } + { + const node_ptr root_node = this->get_root_node(); + typename node_algorithms::stable_partition_info info; + node_algorithms::stable_partition + (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); + //Invariants preserved by stable_partition so erase can be safely called + //The first element might have changed so calculate it again + this->erase( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr()) + , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) + , info.num_1st_partition); + } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1138,16 +1129,15 @@ class list_impl template<class Pred, class Disposer> void remove_and_dispose_if(Pred pred, Disposer disposer) { - const_iterator cur(this->cbegin()); - const_iterator last(this->cend()); - while(cur != last) { - if(pred(*cur)){ - cur = this->erase_and_dispose(cur, disposer); - } - else{ - ++cur; - } - } + const node_ptr root_node = this->get_root_node(); + typename node_algorithms::stable_partition_info info; + node_algorithms::stable_partition + (node_traits::get_next(root_node), root_node, detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); + //Invariants preserved by stable_partition so erase can be safely called + //The first element might have changed so calculate it again + this->erase_and_dispose( const_iterator(node_traits::get_next(root_node), this->priv_value_traits_ptr()) + , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) + , disposer); } //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent @@ -1239,8 +1229,8 @@ class list_impl static iterator s_iterator_to(reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value))); - return iterator(real_value_traits::to_node_ptr(value), 0); + BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(value))); + return iterator(value_traits::to_node_ptr(value), const_value_traits_ptr()); } //! <b>Requires</b>: value must be a const reference to a value inserted in a list. @@ -1257,8 +1247,9 @@ class list_impl static const_iterator s_iterator_to(const_reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value)))); - return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), 0); + reference r =*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(value_traits::to_node_ptr(r))); + return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr()); } //! <b>Requires</b>: value must be a reference to a value inserted in a list. @@ -1272,8 +1263,8 @@ class list_impl //! <b>Note</b>: Iterators and references are not invalidated. iterator iterator_to(reference value) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value))); - return iterator(real_value_traits::to_node_ptr(value), this); + BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(value))); + return iterator(this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); } //! <b>Requires</b>: value must be a const reference to a value inserted in a list. @@ -1287,8 +1278,45 @@ class list_impl //! <b>Note</b>: Iterators and references are not invalidated. const_iterator iterator_to(const_reference value) const { - BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value)))); - return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), this); + reference r = *pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(this->priv_value_traits().to_node_ptr(r))); + return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr()); + } + + //! <b>Effects</b>: Asserts the integrity of the container. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG). + //! Experimental function, interface might change in future versions. + void check() const + { + const_node_ptr header_ptr = get_root_node(); + // header's next and prev are never null + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(header_ptr)); + // header's next and prev either both point to header (empty list) or neither does + BOOST_INTRUSIVE_INVARIANT_ASSERT((node_traits::get_next(header_ptr) == header_ptr) + == (node_traits::get_previous(header_ptr) == header_ptr)); + if (node_traits::get_next(header_ptr) == header_ptr) + { + if (constant_time_size) + BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0); + return; + } + size_t node_count = 0; + const_node_ptr p = header_ptr; + while (true) + { + const_node_ptr next_p = node_traits::get_next(p); + BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p); + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_previous(next_p) == p); + p = next_p; + if (p == header_ptr) break; + ++node_count; + } + if (constant_time_size) + BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count); } /// @cond @@ -1296,8 +1324,11 @@ class list_impl private: static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) { - root_plus_size *r = detail::parent_from_member<root_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &root_plus_size::root_); + BOOST_STATIC_ASSERT((has_container_from_iterator)); + node_ptr p = end_iterator.pointed_node(); + header_holder_type* h = header_holder_type::get_holder(p); + root_plus_size* r = detail::parent_from_member + < root_plus_size, header_holder_type>(h, &root_plus_size::m_header); data_t *d = detail::parent_from_member<data_t, root_plus_size> ( r, &data_t::root_plus_size_); list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_); @@ -1309,29 +1340,29 @@ class list_impl #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline bool operator< #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif bool operator== #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { - typedef list_impl<Config> list_type; + typedef list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> list_type; typedef typename list_type::const_iterator const_iterator; const bool C = list_type::constant_time_size; if(C && x.size() != y.size()){ @@ -1361,65 +1392,65 @@ bool operator== #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline bool operator!= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { return !(x == y); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline bool operator> #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { return y < x; } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline bool operator<= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { return !(y < x); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline bool operator>= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const list_impl<T, Options...> &x, const list_impl<T, Options...> &y) #else -(const list_impl<Config> &x, const list_impl<Config> &y) +(const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, const list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { return !(x < y); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template <class ValueTraits, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif inline void swap #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (list_impl<T, Options...> &x, list_impl<T, Options...> &y) #else -(list_impl<Config> &x, list_impl<Config> &y) +(list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &x, list_impl<ValueTraits, SizeType, ConstantTimeSize, HeaderHolder> &y) #endif { x.swap(y); } @@ -1428,30 +1459,31 @@ inline void swap #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none, class O3 = none> +template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_list { /// @cond typedef typename pack_options - < list_defaults<T>, + < list_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 + O1, O2, O3, O4 #else Options... #endif >::type packed_options; typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; typedef list_impl < - listopt - < value_traits - , typename packed_options::size_type - , packed_options::constant_time_size - > + value_traits, + typename packed_options::size_type, + packed_options::constant_time_size, + header_holder_type > implementation_defined; /// @endcond typedef implementation_defined type; @@ -1461,14 +1493,14 @@ struct make_list #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3> +template<class T, class O1, class O2, class O3, class O4> #else template<class T, class ...Options> #endif class list : public make_list<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 + O1, O2, O3, O4 #else Options... #endif @@ -1477,14 +1509,13 @@ class list typedef typename make_list <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 + O1, O2, O3, O4 #else Options... #endif >::type Base; - typedef typename Base::real_value_traits real_value_traits; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value)); BOOST_MOVABLE_BUT_NOT_COPYABLE(list) public: @@ -1492,7 +1523,7 @@ class list typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; - list(const value_traits &v_traits = value_traits()) + explicit list(const value_traits &v_traits = value_traits()) : Base(v_traits) {} @@ -1506,7 +1537,7 @@ class list {} list& operator=(BOOST_RV_REF(list) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<list &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static list &container_from_end_iterator(iterator end_iterator) { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); } diff --git a/boost/intrusive/list_hook.hpp b/boost/intrusive/list_hook.hpp index b674868242..1a06a980b7 100644 --- a/boost/intrusive/list_hook.hpp +++ b/boost/intrusive/list_hook.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,9 +14,13 @@ #ifndef BOOST_INTRUSIVE_LIST_HOOK_HPP #define BOOST_INTRUSIVE_LIST_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/detail/list_node.hpp> #include <boost/intrusive/circular_list_algorithms.hpp> #include <boost/intrusive/options.hpp> @@ -25,20 +29,12 @@ namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer> -struct get_list_node_algo -{ - typedef circular_list_algorithms<list_node_traits<VoidPointer> > type; -}; -/// @endcond - //! Helper metafunction to define a \c \c list_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_list_base_hook { @@ -52,11 +48,11 @@ struct make_list_base_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_list_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < circular_list_algorithms<list_node_traits<typename packed_options::void_pointer> > , typename packed_options::tag , packed_options::link_mode - , detail::ListBaseHook + , ListBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -77,7 +73,7 @@ struct make_list_base_hook //! \c auto_unlink or \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else @@ -165,7 +161,7 @@ class list_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_list_member_hook { @@ -179,11 +175,11 @@ struct make_list_member_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_list_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < circular_list_algorithms<list_node_traits<typename packed_options::void_pointer> > , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -199,7 +195,7 @@ struct make_list_member_hook //! \c auto_unlink or \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else diff --git a/boost/intrusive/member_value_traits.hpp b/boost/intrusive/member_value_traits.hpp index 0462dbd65d..96c50ee45c 100644 --- a/boost/intrusive/member_value_traits.hpp +++ b/boost/intrusive/member_value_traits.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,8 +13,14 @@ #ifndef BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP #define BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> + #include <boost/intrusive/link_mode.hpp> -#include <iterator> #include <boost/intrusive/detail/parent_from_member.hpp> #include <boost/intrusive/pointer_traits.hpp> @@ -26,7 +32,11 @@ namespace intrusive { //!store a node_traits::node template< class T, class NodeTraits , typename NodeTraits::node T::* PtrToMember - , link_mode_type LinkMode = safe_link> + , link_mode_type LinkMode + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + = safe_link + #endif +> struct member_value_traits { public: @@ -35,6 +45,7 @@ struct member_value_traits typedef typename node_traits::node node; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; + typedef pointer_traits<node_ptr> node_ptr_traits; typedef typename pointer_traits<node_ptr>::template rebind_pointer<T>::type pointer; typedef typename pointer_traits<node_ptr>::template @@ -46,25 +57,28 @@ struct member_value_traits static const link_mode_type link_mode = LinkMode; static node_ptr to_node_ptr(reference value) - { return node_ptr(&(value.*PtrToMember)); } + { return pointer_traits<node_ptr>::pointer_to(value.*PtrToMember); } static const_node_ptr to_node_ptr(const_reference value) - { return node_ptr(&(value.*PtrToMember)); } + { return pointer_traits<const_node_ptr>::pointer_to(value.*PtrToMember); } static pointer to_value_ptr(const node_ptr &n) { - return pointer(detail::parent_from_member<value_type, node> + return pointer_traits<pointer>::pointer_to(*detail::parent_from_member<value_type, node> (boost::intrusive::detail::to_raw_pointer(n), PtrToMember)); } static const_pointer to_value_ptr(const const_node_ptr &n) { - return pointer(detail::parent_from_member<value_type, node> + return pointer_traits<const_pointer>::pointer_to(*detail::parent_from_member<value_type, node> (boost::intrusive::detail::to_raw_pointer(n), PtrToMember)); + } }; } //namespace intrusive } //namespace boost +#include <boost/intrusive/detail/config_end.hpp> + #endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP diff --git a/boost/intrusive/options.hpp b/boost/intrusive/options.hpp index e657438836..9a77750c7f 100644 --- a/boost/intrusive/options.hpp +++ b/boost/intrusive/options.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,232 +13,54 @@ #ifndef BOOST_INTRUSIVE_OPTIONS_HPP #define BOOST_INTRUSIVE_OPTIONS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/link_mode.hpp> +#include <boost/intrusive/pack_options.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/static_assert.hpp> - namespace boost { namespace intrusive { -/// @cond - -struct default_tag; -struct member_tag; - -namespace detail{ - -struct default_hook_tag{}; - -#define BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER) \ -struct BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER : public default_hook_tag\ -{\ - template <class T>\ - struct apply\ - { typedef typename T::BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER type; };\ -}\ - -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_list_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_slist_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_set_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_uset_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_avl_set_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_splay_set_hook); -BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_bs_set_hook); - -#undef BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION - -template <class ValueTraits> -struct eval_value_traits -{ - typedef typename ValueTraits::value_traits type; -}; - -template <class T> -struct external_bucket_traits_is_true -{ - static const bool value = external_bucket_traits_bool<T>::value == 3; -}; - -template <class BucketTraits> -struct eval_bucket_traits -{ - typedef typename BucketTraits::bucket_traits type; -}; +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED -template <class T, class BaseHook> -struct concrete_hook_base_value_traits -{ - typedef typename BaseHook::boost_intrusive_tags tags; - typedef detail::base_hook_traits - < T - , typename tags::node_traits - , tags::link_mode - , typename tags::tag - , tags::hook_type> type; -}; - -template <class BaseHook> -struct concrete_hook_base_node_traits -{ typedef typename BaseHook::boost_intrusive_tags::node_traits type; }; - -template <class T, class BaseHook> -struct any_hook_base_value_traits -{ - typedef typename BaseHook::boost_intrusive_tags tags; - typedef detail::base_hook_traits - < T - , typename BaseHook::node_traits - , tags::link_mode - , typename tags::tag - , tags::hook_type> type; -}; - -template <class BaseHook> -struct any_hook_base_node_traits -{ typedef typename BaseHook::node_traits type; }; - -template<class T, class BaseHook> -struct get_base_value_traits -{ - typedef typename detail::eval_if_c - < internal_any_hook_bool_is_true<BaseHook>::value - , any_hook_base_value_traits<T, BaseHook> - , concrete_hook_base_value_traits<T, BaseHook> - >::type type; -}; - -template<class BaseHook> -struct get_base_node_traits -{ - typedef typename detail::eval_if_c - < internal_any_hook_bool_is_true<BaseHook>::value - , any_hook_base_node_traits<BaseHook> - , concrete_hook_base_node_traits<BaseHook> - >::type type; -}; +struct empty +{}; -template<class T, class MemberHook> -struct get_member_value_traits -{ - typedef typename MemberHook::member_value_traits type; -}; +template<class Functor> +struct fhtraits; -template<class MemberHook> -struct get_member_node_traits -{ - typedef typename MemberHook::member_value_traits::node_traits type; -}; +template<class T, class Hook, Hook T::* P> +struct mhtraits; -template<class T, class SupposedValueTraits> -struct get_value_traits -{ - typedef typename detail::eval_if_c - <detail::is_convertible<SupposedValueTraits*, detail::default_hook_tag*>::value - ,detail::apply<SupposedValueTraits, T> - ,detail::identity<SupposedValueTraits> - >::type supposed_value_traits; - //...if it's a default hook - typedef typename detail::eval_if_c - < internal_base_hook_bool_is_true<supposed_value_traits>::value - //...get it's internal value traits using - //the provided T value type. - , get_base_value_traits<T, supposed_value_traits> - //...else use it's internal value traits tag - //(member hooks and custom value traits are in this group) - , detail::eval_if_c - < internal_member_value_traits<supposed_value_traits>::value - , get_member_value_traits<T, supposed_value_traits> - , detail::identity<supposed_value_traits> - > - >::type type; -}; - -template<class ValueTraits> -struct get_explicit_node_traits -{ - typedef typename ValueTraits::node_traits type; -}; +//typedef void default_tag; +struct default_tag; +struct member_tag; template<class SupposedValueTraits> -struct get_node_traits -{ - typedef SupposedValueTraits supposed_value_traits; - //...if it's a base hook - typedef typename detail::eval_if_c - < internal_base_hook_bool_is_true<supposed_value_traits>::value - //...get it's internal value traits using - //the provided T value type. - , get_base_node_traits<supposed_value_traits> - //...else use it's internal value traits tag - //(member hooks and custom value traits are in this group) - , detail::eval_if_c - < internal_member_value_traits<supposed_value_traits>::value - , get_member_node_traits<supposed_value_traits> - , get_explicit_node_traits<supposed_value_traits> - > - >::type type; -}; - -} //namespace detail{ +struct is_default_hook_tag; - -//!This type indicates that no option is being used -//!and that the default options should be used -struct none -{ - template<class Base> - struct pack : Base - { }; -}; - -/// @endcond +#endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED //!This option setter specifies if the intrusive //!container stores its size as a member to //!obtain constant-time size() member. -template<bool Enabled> -struct constant_time_size -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool constant_time_size = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(constant_time_size, bool, Enabled, constant_time_size) + +//!This option setter specifies a container header holder type +BOOST_INTRUSIVE_OPTION_TYPE(header_holder_type, HeaderHolder, HeaderHolder, header_holder_type) //!This option setter specifies the type that //!the container will use to store its size. -template<class SizeType> -struct size_type -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef SizeType size_type; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(size_type, SizeType, SizeType, size_type) //!This option setter specifies the strict weak ordering //!comparison functor for the value type -template<class Compare> -struct compare -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef Compare compare; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(compare, Compare, Compare, compare) //!This option setter for scapegoat containers specifies if //!the intrusive scapegoat container should use a non-variable @@ -252,74 +74,39 @@ struct compare //!If the user only needs an alpha value near 1/sqrt(2), this //!option also improves performance since avoids logarithm //!and division operations when rebalancing the tree. -template<bool Enabled> -struct floating_point -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool floating_point = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(floating_point, bool, Enabled, floating_point) //!This option setter specifies the equality //!functor for the value type -template<class Equal> -struct equal -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef Equal equal; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(equal, Equal, Equal, equal) //!This option setter specifies the equality //!functor for the value type -template<class Priority> -struct priority -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef Priority priority; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(priority, Priority, Priority, priority) //!This option setter specifies the hash //!functor for the value type -template<class Hash> -struct hash -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef Hash hash; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(hash, Hash, Hash, hash) //!This option setter specifies the relationship between the type //!to be managed by the container (the value type) and the node to be //!used in the node algorithms. It also specifies the linking policy. -template<typename ValueTraits> -struct value_traits -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef ValueTraits value_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(value_traits, ValueTraits, ValueTraits, proto_value_traits) + +//#define BOOST_INTRUSIVE_COMMA , +//#define BOOST_INTRUSIVE_LESS < +//#define BOOST_INTRUSIVE_MORE > +//BOOST_INTRUSIVE_OPTION_TYPE (member_hook, Parent BOOST_INTRUSIVE_COMMA class MemberHook BOOST_INTRUSIVE_COMMA MemberHook Parent::* PtrToMember , mhtraits BOOST_INTRUSIVE_LESS Parent BOOST_INTRUSIVE_COMMA MemberHook BOOST_INTRUSIVE_COMMA PtrToMember BOOST_INTRUSIVE_MORE , proto_value_traits) +//template< class Parent , class MemberHook , MemberHook Parent::* PtrToMember> +//struct member_hook { +// template<class Base> struct pack : Base { +// typedef mhtraits < Parent , MemberHook , PtrToMember > proto_value_traits; +// }; +//}; +// +//#undef BOOST_INTRUSIVE_COMMA +//#undef BOOST_INTRUSIVE_LESS +//#undef BOOST_INTRUSIVE_MORE //!This option setter specifies the member hook the //!container must use. @@ -328,172 +115,78 @@ template< typename Parent , MemberHook Parent::* PtrToMember> struct member_hook { -/// @cond - typedef detail::member_hook_traits - < Parent - , MemberHook - , PtrToMember - > member_value_traits; +// @cond +// typedef typename MemberHook::hooktags::node_traits node_traits; +// typedef typename node_traits::node node_type; +// typedef node_type Parent::* Ptr2MemNode; +// typedef mhtraits +// < Parent +// , node_traits +// //This cast is really ugly but necessary to reduce template bloat. +// //Since we control the layout between the hook and the node, and there is +// //always single inheritance, the offset of the node is exactly the offset of +// //the hook. Since the node type is shared between all member hooks, this saves +// //quite a lot of symbol stuff. +// , (Ptr2MemNode)PtrToMember +// , MemberHook::hooktags::link_mode> member_value_traits; + typedef mhtraits <Parent, MemberHook, PtrToMember> member_value_traits; template<class Base> struct pack : Base { - typedef member_value_traits value_traits; + typedef member_value_traits proto_value_traits; }; /// @endcond }; - //!This option setter specifies the function object that will //!be used to convert between values to be inserted in a container //!and the hook to be used for that purpose. -template< typename Functor> -struct function_hook -{ -/// @cond - typedef detail::function_hook_traits - <Functor> function_value_traits; - template<class Base> - struct pack : Base - { - typedef function_value_traits value_traits; - }; -/// @endcond -}; - +BOOST_INTRUSIVE_OPTION_TYPE(function_hook, Functor, fhtraits<Functor>, proto_value_traits) //!This option setter specifies that the container //!must use the specified base hook -template<typename BaseHook> -struct base_hook -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef BaseHook value_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(base_hook, BaseHook, BaseHook, proto_value_traits) //!This option setter specifies the type of //!a void pointer. This will instruct the hook //!to use this type of pointer instead of the //!default one -template<class VoidPointer> -struct void_pointer -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef VoidPointer void_pointer; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(void_pointer, VoidPointer, VoidPointer, void_pointer) //!This option setter specifies the type of //!the tag of a base hook. A type cannot have two //!base hooks of the same type, so a tag can be used //!to differentiate two base hooks with otherwise same type -template<class Tag> -struct tag -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef Tag tag; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(tag, Tag, Tag, tag) //!This option setter specifies the link mode //!(normal_link, safe_link or auto_unlink) -template<link_mode_type LinkType> -struct link_mode -{ -/// @cond - template<class Base> - struct pack : Base - { - static const link_mode_type link_mode = LinkType; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(link_mode, link_mode_type, LinkType, link_mode) //!This option setter specifies if the hook //!should be optimized for size instead of for speed. -template<bool Enabled> -struct optimize_size -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool optimize_size = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_size, bool, Enabled, optimize_size) -//!This option setter specifies if the list container should +//!This option setter specifies if the slist container should //!use a linear implementation instead of a circular one. -template<bool Enabled> -struct linear -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool linear = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(linear, bool, Enabled, linear) -//!This option setter specifies if the list container should -//!use a linear implementation instead of a circular one. -template<bool Enabled> -struct cache_last -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool cache_last = Enabled; - }; -/// @endcond -}; +//!If true, slist also stores a pointer to the last element of the singly linked list. +//!This allows O(1) swap and splice_after(iterator, slist &) for circular slists and makes +//!possible new functions like push_back(reference) and back(). +BOOST_INTRUSIVE_OPTION_CONSTANT(cache_last, bool, Enabled, cache_last) //!This option setter specifies the bucket traits //!class for unordered associative containers. When this option is specified, //!instead of using the default bucket traits, a user defined holder will be defined -template<class BucketTraits> -struct bucket_traits -{ -/// @cond - template<class Base> - struct pack : Base - { - typedef BucketTraits bucket_traits; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_TYPE(bucket_traits, BucketTraits, BucketTraits, bucket_traits) //!This option setter specifies if the unordered hook //!should offer room to store the hash value. //!Storing the hash in the hook will speed up rehashing //!processes in applications where rehashing is frequent, //!rehashing might throw or the value is heavy to hash. -template<bool Enabled> -struct store_hash -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool store_hash = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(store_hash, bool, Enabled, store_hash) //!This option setter specifies if the unordered hook //!should offer room to store another link to another node @@ -501,51 +194,20 @@ struct store_hash //!Storing this link will speed up lookups and insertions on //!unordered_multiset containers with a great number of elements //!with the same key. -template<bool Enabled> -struct optimize_multikey -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool optimize_multikey = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_multikey, bool, Enabled, optimize_multikey) //!This option setter specifies if the bucket array will be always power of two. //!This allows using masks instead of the default modulo operation to determine //!the bucket number from the hash value, leading to better performance. //!In debug mode, if power of two buckets mode is activated, the bucket length //!will be checked to through assertions to assure the bucket length is power of two. -template<bool Enabled> -struct power_2_buckets -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool power_2_buckets = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(power_2_buckets, bool, Enabled, power_2_buckets) //!This option setter specifies if the container will cache a pointer to the first //!non-empty bucket so that begin() is always constant-time. //!This is specially helpful when we can have containers with a few elements //!but with big bucket arrays (that is, hashtables with low load factors). -template<bool Enabled> -struct cache_begin -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool cache_begin = Enabled; - }; -/// @endcond -}; - +BOOST_INTRUSIVE_OPTION_CONSTANT(cache_begin, bool, Enabled, cache_begin) //!This option setter specifies if the container will compare the hash value //!before comparing objects. This option can't be specified if store_hash<> @@ -553,17 +215,7 @@ struct cache_begin //!This is specially helpful when we have containers with a high load factor. //!and the comparison function is much more expensive that comparing already //!stored hash values. -template<bool Enabled> -struct compare_hash -{ -/// @cond - template<class Base> - struct pack : Base - { - static const bool compare_hash = Enabled; - }; -/// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(compare_hash, bool, Enabled, compare_hash) //!This option setter specifies if the hash container will use incremental //!hashing. With incremental hashing the cost of hash table expansion is spread @@ -571,237 +223,21 @@ struct compare_hash //!Therefore linear hashing is well suited for interactive applications or real-time //!appplications where the worst-case insertion time of non-incremental hash containers //!(rehashing the whole bucket array) is not admisible. -template<bool Enabled> -struct incremental -{ - /// @cond - template<class Base> - struct pack : Base - { - static const bool incremental = Enabled; - }; - /// @endcond -}; +BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, incremental) /// @cond -//To-do: pass to variadic templates -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - -template<class Prev, class Next> -struct do_pack -{ - //Use "pack" member template to pack options - typedef typename Next::template pack<Prev> type; -}; - -template<class Prev> -struct do_pack<Prev, none> -{ - //Avoid packing "none" to shorten template names - typedef Prev type; -}; - -template - < class DefaultOptions - , class O1 = none - , class O2 = none - , class O3 = none - , class O4 = none - , class O5 = none - , class O6 = none - , class O7 = none - , class O8 = none - , class O9 = none - , class O10 = none - , class O11 = none - > -struct pack_options -{ - // join options - typedef - typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < typename do_pack - < DefaultOptions - , O1 - >::type - , O2 - >::type - , O3 - >::type - , O4 - >::type - , O5 - >::type - , O6 - >::type - , O7 - >::type - , O8 - >::type - , O9 - >::type - , O10 - >::type - , O11 - >::type - type; -}; -#else - -//index_tuple -template<int... Indexes> -struct index_tuple{}; - -//build_number_seq -template<std::size_t Num, typename Tuple = index_tuple<> > -struct build_number_seq; - -template<std::size_t Num, int... Indexes> -struct build_number_seq<Num, index_tuple<Indexes...> > - : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> > -{}; - -template<int... Indexes> -struct build_number_seq<0, index_tuple<Indexes...> > -{ typedef index_tuple<Indexes...> type; }; - -template<class ...Types> -struct typelist -{}; - -//invert_typelist -template<class T> -struct invert_typelist; - -template<int I, typename Tuple> -struct typelist_element; - -template<int I, typename Head, typename... Tail> -struct typelist_element<I, typelist<Head, Tail...> > -{ - typedef typename typelist_element<I-1, typelist<Tail...> >::type type; -}; - -template<typename Head, typename... Tail> -struct typelist_element<0, typelist<Head, Tail...> > -{ - typedef Head type; -}; - -template<int ...Ints, class ...Types> -typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...> - inverted_typelist(index_tuple<Ints...>, typelist<Types...>) -{ - return typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>(); -} - -//sizeof_typelist -template<class Typelist> -struct sizeof_typelist; - -template<class ...Types> -struct sizeof_typelist< typelist<Types...> > -{ - static const std::size_t value = sizeof...(Types); -}; - -//invert_typelist_impl -template<class Typelist, class Indexes> -struct invert_typelist_impl; - - -template<class Typelist, int ...Ints> -struct invert_typelist_impl< Typelist, index_tuple<Ints...> > -{ - static const std::size_t last_idx = sizeof_typelist<Typelist>::value - 1; - typedef typelist - <typename typelist_element<last_idx - Ints, Typelist>::type...> type; -}; - -template<class Typelist, int Int> -struct invert_typelist_impl< Typelist, index_tuple<Int> > -{ - typedef Typelist type; -}; - -template<class Typelist> -struct invert_typelist_impl< Typelist, index_tuple<> > -{ - typedef Typelist type; -}; - -//invert_typelist -template<class Typelist> -struct invert_typelist; - -template<class ...Types> -struct invert_typelist< typelist<Types...> > -{ - typedef typelist<Types...> typelist_t; - typedef typename build_number_seq<sizeof...(Types)>::type indexes_t; - typedef typename invert_typelist_impl<typelist_t, indexes_t>::type type; -}; - -//Do pack -template<class Typelist> -struct do_pack; - -template<> -struct do_pack<typelist<> >; - -template<class Prev> -struct do_pack<typelist<Prev> > -{ - typedef Prev type; -}; - -template<class Prev, class Last> -struct do_pack<typelist<Prev, Last> > -{ - typedef typename Prev::template pack<Last> type; -}; - -template<class Prev, class ...Others> -struct do_pack<typelist<Prev, Others...> > -{ - typedef typename Prev::template pack - <typename do_pack<typelist<Others...> >::type> type; -}; - - -template<class ...Options> -struct pack_options +struct hook_defaults { - typedef typelist<Options...> typelist_t; - typedef typename invert_typelist<typelist_t>::type inverted_typelist; - typedef typename do_pack<inverted_typelist>::type type; + typedef void* void_pointer; + static const link_mode_type link_mode = safe_link; + typedef default_tag tag; + static const bool optimize_size = false; + static const bool store_hash = false; + static const bool linear = false; + static const bool optimize_multikey = false; }; -#endif - -struct hook_defaults - : public pack_options - < none - , void_pointer<void*> - , link_mode<safe_link> - , tag<default_tag> - , optimize_size<false> - , store_hash<false> - , linear<false> - , optimize_multikey<false> - >::type -{}; - /// @endcond } //namespace intrusive { diff --git a/boost/intrusive/pack_options.hpp b/boost/intrusive/pack_options.hpp new file mode 100644 index 0000000000..077b08b60c --- /dev/null +++ b/boost/intrusive/pack_options.hpp @@ -0,0 +1,374 @@ +///////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2013-2013 +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +///////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP +#define BOOST_INTRUSIVE_PACK_OPTIONS_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> + +namespace boost { +namespace intrusive { + +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + +template<class Prev, class Next> +struct do_pack +{ + //Use "pack" member template to pack options + typedef typename Next::template pack<Prev> type; +}; + +template<class Prev> +struct do_pack<Prev, void> +{ + //Avoid packing "void" to shorten template names + typedef Prev type; +}; + +template + < class DefaultOptions + , class O1 = void + , class O2 = void + , class O3 = void + , class O4 = void + , class O5 = void + , class O6 = void + , class O7 = void + , class O8 = void + , class O9 = void + , class O10 = void + , class O11 = void + > +struct pack_options +{ + // join options + typedef + typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < typename do_pack + < DefaultOptions + , O1 + >::type + , O2 + >::type + , O3 + >::type + , O4 + >::type + , O5 + >::type + , O6 + >::type + , O7 + >::type + , O8 + >::type + , O9 + >::type + , O10 + >::type + , O11 + >::type + type; +}; +#else + +//index_tuple +template<int... Indexes> +struct index_tuple{}; + +//build_number_seq +template<std::size_t Num, typename Tuple = index_tuple<> > +struct build_number_seq; + +template<std::size_t Num, int... Indexes> +struct build_number_seq<Num, index_tuple<Indexes...> > + : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> > +{}; + +template<int... Indexes> +struct build_number_seq<0, index_tuple<Indexes...> > +{ typedef index_tuple<Indexes...> type; }; + +template<class ...Types> +struct typelist +{}; + +//invert_typelist +template<class T> +struct invert_typelist; + +template<int I, typename Tuple> +struct typelist_element; + +template<int I, typename Head, typename... Tail> +struct typelist_element<I, typelist<Head, Tail...> > +{ + typedef typename typelist_element<I-1, typelist<Tail...> >::type type; +}; + +template<typename Head, typename... Tail> +struct typelist_element<0, typelist<Head, Tail...> > +{ + typedef Head type; +}; + +template<int ...Ints, class ...Types> +typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...> + inverted_typelist(index_tuple<Ints...>, typelist<Types...>) +{ + return typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>(); +} + +//sizeof_typelist +template<class Typelist> +struct sizeof_typelist; + +template<class ...Types> +struct sizeof_typelist< typelist<Types...> > +{ + static const std::size_t value = sizeof...(Types); +}; + +//invert_typelist_impl +template<class Typelist, class Indexes> +struct invert_typelist_impl; + + +template<class Typelist, int ...Ints> +struct invert_typelist_impl< Typelist, index_tuple<Ints...> > +{ + static const std::size_t last_idx = sizeof_typelist<Typelist>::value - 1; + typedef typelist + <typename typelist_element<last_idx - Ints, Typelist>::type...> type; +}; + +template<class Typelist, int Int> +struct invert_typelist_impl< Typelist, index_tuple<Int> > +{ + typedef Typelist type; +}; + +template<class Typelist> +struct invert_typelist_impl< Typelist, index_tuple<> > +{ + typedef Typelist type; +}; + +//invert_typelist +template<class Typelist> +struct invert_typelist; + +template<class ...Types> +struct invert_typelist< typelist<Types...> > +{ + typedef typelist<Types...> typelist_t; + typedef typename build_number_seq<sizeof...(Types)>::type indexes_t; + typedef typename invert_typelist_impl<typelist_t, indexes_t>::type type; +}; + +//Do pack +template<class Typelist> +struct do_pack; + +template<> +struct do_pack<typelist<> >; + +template<class Prev> +struct do_pack<typelist<Prev> > +{ + typedef Prev type; +}; + +template<class Prev, class Last> +struct do_pack<typelist<Prev, Last> > +{ + typedef typename Prev::template pack<Last> type; +}; + +template<class Prev, class ...Others> +struct do_pack<typelist<Prev, Others...> > +{ + typedef typename Prev::template pack + <typename do_pack<typelist<Others...> >::type> type; +}; + + +template<class DefaultOptions, class ...Options> +struct pack_options +{ + typedef typelist<DefaultOptions, Options...> typelist_t; + typedef typename invert_typelist<typelist_t>::type inverted_typelist; + typedef typename do_pack<inverted_typelist>::type type; +}; + +#endif //!defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + +#define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) \ +template< class TYPE> \ +struct OPTION_NAME \ +{ \ + template<class Base> \ + struct pack : Base \ + { \ + typedef TYPEDEF_EXPR TYPEDEF_NAME; \ + }; \ +}; \ +// + +#define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) \ +template< TYPE VALUE> \ +struct OPTION_NAME \ +{ \ + template<class Base> \ + struct pack : Base \ + { \ + static const TYPE CONSTANT_NAME = VALUE; \ + }; \ +}; \ +// + +#else //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +//! This class is a utility that takes: +//! - a default options class defining initial static constant +//! and typedefs +//! - several options defined with BOOST_INTRUSIVE_OPTION_CONSTANT and +//! BOOST_INTRUSIVE_OPTION_TYPE +//! +//! and packs them together in a new type that defines all options as +//! member typedefs or static constant values. Given options of form: +//! +//! \code +//! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, VoidPointer, my_pointer_type) +//! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental) +//! \endcode +//! +//! the following expression +//! +//! \code +//! +//! struct default_options +//! { +//! typedef long int_type; +//! static const int int_constant = -1; +//! }; +//! +//! pack_options< default_options, my_pointer<void*>, incremental<true> >::type +//! \endcode +//! +//! will create a type that will contain the following typedefs/constants +//! +//! \code +//! struct unspecified_type +//! { +//! //Default options +//! typedef long int_type; +//! static const int int_constant = -1; +//! +//! //Packed options (will ovewrite any default option) +//! typedef void* my_pointer_type; +//! static const bool is_incremental = true; +//! }; +//! \endcode +//! +//! If an option is specified in the default options argument and later +//! redefined as an option, the last definition will prevail. +template<class DefaultOptions, class ...Options> +struct pack_options +{ + typedef unspecified_type type; +}; + +//! Defines an option class of name OPTION_NAME that can be used to specify a type +//! of type TYPE... +//! +//! \code +//! struct OPTION_NAME<class TYPE> +//! { /*unspecified_content*/ }; +//! \endcode +//! +//! ...that after being combined with +//! <code>boost::intrusive::pack_options</code>, +//! will typedef TYPE as a typedef of name TYPEDEF_NAME. Example: +//! +//! \code +//! //[includes and namespaces omitted for brevity] +//! +//! //This macro will create the following class: +//! // template<class VoidPointer> +//! // struct my_pointer +//! // { unspecified_content }; +//! BOOST_INTRUSIVE_OPTION_TYPE(my_pointer, VoidPointer, boost::remove_pointer<VoidPointer>::type, my_pointer_type) +//! +//! struct empty_default{}; +//! +//! typedef pack_options< empty_default, typename my_pointer<void*> >::type::my_pointer_type type; +//! +//! BOOST_STATIC_ASSERT(( boost::is_same<type, void>::value )); +//! +//! \endcode +#define BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) + +//! Defines an option class of name OPTION_NAME that can be used to specify a constant +//! of type TYPE with value VALUE... +//! +//! \code +//! struct OPTION_NAME<TYPE VALUE> +//! { /*unspecified_content*/ }; +//! \endcode +//! +//! ...that after being combined with +//! <code>boost::intrusive::pack_options</code>, +//! will contain a CONSTANT_NAME static constant of value VALUE. Example: +//! +//! \code +//! //[includes and namespaces omitted for brevity] +//! +//! //This macro will create the following class: +//! // template<bool Enabled> +//! // struct incremental +//! // { unspecified_content }; +//! BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, is_incremental) +//! +//! struct empty_default{}; +//! +//! const bool is_incremental = pack_options< empty_default, incremental<true> >::type::is_incremental; +//! +//! BOOST_STATIC_ASSERT(( is_incremental == true )); +//! +//! \endcode +#define BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) + +#endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + +} //namespace intrusive { +} //namespace boost { + +#include <boost/intrusive/detail/config_end.hpp> + +#endif //#ifndef BOOST_INTRUSIVE_PACK_OPTIONS_HPP diff --git a/boost/intrusive/parent_from_member.hpp b/boost/intrusive/parent_from_member.hpp index f4658e5c5c..e6be5bce6b 100644 --- a/boost/intrusive/parent_from_member.hpp +++ b/boost/intrusive/parent_from_member.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2010-2012 +// (C) Copyright Ion Gaztanaga 2010-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -9,10 +9,16 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP -#define BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP +#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP +#define BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP + +#if defined(_MSC_VER) +# pragma once +#endif #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> + #include <boost/intrusive/detail/parent_from_member.hpp> namespace boost { @@ -39,4 +45,4 @@ inline const Parent *get_parent_from_member(const Member *member, const Member P #include <boost/intrusive/detail/config_end.hpp> -#endif //#ifndef BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP +#endif //#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP diff --git a/boost/intrusive/pointer_plus_bits.hpp b/boost/intrusive/pointer_plus_bits.hpp index a2a9f1bf72..1fcf67aa55 100644 --- a/boost/intrusive/pointer_plus_bits.hpp +++ b/boost/intrusive/pointer_plus_bits.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,6 +13,12 @@ #ifndef BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP #define BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/mpl.hpp> //ls_zeros #include <boost/intrusive/detail/assert.hpp> //BOOST_INTRUSIVE_INVARIANT_ASSERT @@ -47,7 +53,11 @@ struct max_pointer_plus_bits<void*, Alignment> //!has_pointer_plus_bits<>::value is non-zero can make use of these //!operations to embed the bits in the pointer. template<class Pointer, std::size_t NumBits> -struct pointer_plus_bits; +struct pointer_plus_bits + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + {} + #endif +; //!This is the specialization to embed extra bits of information //!in a raw pointer. The extra bits are stored in the lower bits of the pointer. @@ -79,4 +89,6 @@ struct pointer_plus_bits<T*, NumBits> } //namespace intrusive } //namespace boost +#include <boost/intrusive/detail/config_end.hpp> + #endif //BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP diff --git a/boost/intrusive/pointer_rebind.hpp b/boost/intrusive/pointer_rebind.hpp new file mode 100644 index 0000000000..852491355b --- /dev/null +++ b/boost/intrusive/pointer_rebind.hpp @@ -0,0 +1,188 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/intrusive for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_POINTER_REBIND_HPP +#define BOOST_INTRUSIVE_POINTER_REBIND_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/workaround.hpp> + +namespace boost { +namespace intrusive { + +/////////////////////////// +//struct pointer_rebind_mode +/////////////////////////// +template <typename Ptr, typename U> +struct pointer_has_rebind +{ + template <typename V> struct any + { any(const V&) { } }; + + template <typename X> + static char test(int, typename X::template rebind<U>*); + + template <typename X> + static int test(any<int>, void*); + + static const bool value = (1 == sizeof(test<Ptr>(0, 0))); +}; + +template <typename Ptr, typename U> +struct pointer_has_rebind_other +{ + template <typename V> struct any + { any(const V&) { } }; + + template <typename X> + static char test(int, typename X::template rebind<U>::other*); + + template <typename X> + static int test(any<int>, void*); + + static const bool value = (1 == sizeof(test<Ptr>(0, 0))); +}; + +template <typename Ptr, typename U> +struct pointer_rebind_mode +{ + static const unsigned int rebind = (unsigned int)pointer_has_rebind<Ptr, U>::value; + static const unsigned int rebind_other = (unsigned int)pointer_has_rebind_other<Ptr, U>::value; + static const unsigned int mode = rebind + rebind*rebind_other; +}; + +//////////////////////// +//struct pointer_rebinder +//////////////////////// +template <typename Ptr, typename U, unsigned int RebindMode> +struct pointer_rebinder; + +// Implementation of pointer_rebinder<U>::type if Ptr has +// its own rebind<U>::other type (C++03) +template <typename Ptr, typename U> +struct pointer_rebinder< Ptr, U, 2u > +{ + typedef typename Ptr::template rebind<U>::other type; +}; + +// Implementation of pointer_rebinder<U>::type if Ptr has +// its own rebind template. +template <typename Ptr, typename U> +struct pointer_rebinder< Ptr, U, 1u > +{ + typedef typename Ptr::template rebind<U> type; +}; + +// Specialization of pointer_rebinder if Ptr does not +// have its own rebind template but has a the form Ptr<A, An...>, +// where An... comprises zero or more type parameters. +// Many types fit this form, hence many pointers will get a +// reasonable default for rebind. +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +template <template <class, class...> class Ptr, typename A, class... An, class U> +struct pointer_rebinder<Ptr<A, An...>, U, 0u > +{ + typedef Ptr<U, An...> type; +}; + +//Needed for non-conforming compilers like GCC 4.3 +template <template <class> class Ptr, typename A, class U> +struct pointer_rebinder<Ptr<A>, U, 0u > +{ + typedef Ptr<U> type; +}; + +#else //C++03 compilers + +template <template <class> class Ptr //0arg + , typename A + , class U> +struct pointer_rebinder<Ptr<A>, U, 0u> +{ typedef Ptr<U> type; }; + +template <template <class, class> class Ptr //1arg + , typename A, class P0 + , class U> +struct pointer_rebinder<Ptr<A, P0>, U, 0u> +{ typedef Ptr<U, P0> type; }; + +template <template <class, class, class> class Ptr //2arg + , typename A, class P0, class P1 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1>, U, 0u> +{ typedef Ptr<U, P0, P1> type; }; + +template <template <class, class, class, class> class Ptr //3arg + , typename A, class P0, class P1, class P2 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2>, U, 0u> +{ typedef Ptr<U, P0, P1, P2> type; }; + +template <template <class, class, class, class, class> class Ptr //4arg + , typename A, class P0, class P1, class P2, class P3 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3> type; }; + +template <template <class, class, class, class, class, class> class Ptr //5arg + , typename A, class P0, class P1, class P2, class P3, class P4 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4> type; }; + +template <template <class, class, class, class, class, class, class> class Ptr //6arg + , typename A, class P0, class P1, class P2, class P3, class P4, class P5 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4, P5> type; }; + +template <template <class, class, class, class, class, class, class, class> class Ptr //7arg + , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6> type; }; + +template <template <class, class, class, class, class, class, class, class, class> class Ptr //8arg + , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6, P7>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6, P7> type; }; + +template <template <class, class, class, class, class, class, class, class, class, class> class Ptr //9arg + , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6, P7, P8>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6, P7, P8> type; }; + +template <template <class, class, class, class, class, class, class, class, class, class, class> class Ptr //10arg + , typename A, class P0, class P1, class P2, class P3, class P4, class P5, class P6, class P7, class P8, class P9 + , class U> +struct pointer_rebinder<Ptr<A, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9>, U, 0u> +{ typedef Ptr<U, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9> type; }; + +#endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + +template <typename Ptr, typename U> +struct pointer_rebind + : public pointer_rebinder<Ptr, U, pointer_rebind_mode<Ptr, U>::mode> +{}; + +template <typename T, typename U> +struct pointer_rebind<T*, U> +{ typedef U* type; }; + +} //namespace container { +} //namespace boost { + +#endif // defined(BOOST_INTRUSIVE_POINTER_REBIND_HPP) diff --git a/boost/intrusive/pointer_traits.hpp b/boost/intrusive/pointer_traits.hpp index 3ed1afb032..d3c66df091 100644 --- a/boost/intrusive/pointer_traits.hpp +++ b/boost/intrusive/pointer_traits.hpp @@ -6,7 +6,7 @@ // ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2011-2012. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // @@ -17,14 +17,17 @@ #ifndef BOOST_INTRUSIVE_POINTER_TRAITS_HPP #define BOOST_INTRUSIVE_POINTER_TRAITS_HPP -#if (defined _MSC_VER) && (_MSC_VER >= 1200) +#if defined(_MSC_VER) # pragma once #endif #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/workaround.hpp> #include <boost/intrusive/detail/memory_util.hpp> -#include <boost/type_traits/integral_constant.hpp> +#include <boost/intrusive/pointer_rebind.hpp> +#include <boost/intrusive/detail/pointer_element.hpp> +#include <boost/intrusive/detail/mpl.hpp> #include <cstddef> namespace boost { @@ -59,11 +62,9 @@ struct pointer_traits //!shall be used instead of rebind<U> to obtain a pointer to U. template <class U> using rebind = unspecified; - //!Ptr::rebind<U> if such a type exists; otherwise, SomePointer<U, Args> if Ptr is - //!a class template instantiation of the form SomePointer<T, Args>, where Args is zero or - //!more type arguments ; otherwise, the instantiation of rebind is ill-formed. + //!Ptr::reference if such a type exists (non-standard extension); otherwise, element_type & //! - typedef element_type &reference; + typedef unspecified_type reference; #else typedef Ptr pointer; // @@ -73,18 +74,19 @@ struct pointer_traits // typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT (boost::intrusive::detail::, Ptr, difference_type, std::ptrdiff_t) difference_type; - // - typedef typename boost::intrusive::detail::unvoid<element_type>::type& reference; + + typedef BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT + (boost::intrusive::detail::, Ptr, reference, typename boost::intrusive::detail::unvoid_ref<element_type>::type) reference; // template <class U> struct rebind_pointer { - typedef typename boost::intrusive::detail::type_rebinder<Ptr, U>::type type; + typedef typename boost::intrusive::pointer_rebind<Ptr, U>::type type; }; - #if !defined(BOOST_NO_TEMPLATE_ALIASES) - template <class U> using rebind = typename boost::intrusive::detail::type_rebinder<Ptr, U>::type; + #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) + template <class U> using rebind = typename boost::intrusive::pointer_rebind<Ptr, U>::type; #endif - #endif //#if !defined(BOOST_NO_TEMPLATE_ALIASES) + #endif //#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) //! <b>Remark</b>: If element_type is (possibly cv-qualified) void, r type is unspecified; otherwise, //! it is element_type &. @@ -97,8 +99,8 @@ struct pointer_traits //tries to converts &r to pointer. const bool value = boost::intrusive::detail:: has_member_function_callable_with_pointer_to - <Ptr, typename boost::intrusive::detail::unvoid<element_type &>::type>::value; - ::boost::integral_constant<bool, value> flag; + <Ptr, reference>::value; + boost::intrusive::detail::bool_<value> flag; return pointer_traits::priv_pointer_to(flag, r); } @@ -112,7 +114,7 @@ struct pointer_traits const bool value = boost::intrusive::detail:: has_member_function_callable_with_static_cast_from <Ptr, const UPtr>::value; - ::boost::integral_constant<bool, value> flag; + boost::intrusive::detail::bool_<value> flag; return pointer_traits::priv_static_cast_from(flag, uptr); } @@ -126,7 +128,7 @@ struct pointer_traits const bool value = boost::intrusive::detail:: has_member_function_callable_with_const_cast_from <Ptr, const UPtr>::value; - ::boost::integral_constant<bool, value> flag; + boost::intrusive::detail::bool_<value> flag; return pointer_traits::priv_const_cast_from(flag, uptr); } @@ -140,7 +142,7 @@ struct pointer_traits const bool value = boost::intrusive::detail:: has_member_function_callable_with_dynamic_cast_from <Ptr, const UPtr>::value; - ::boost::integral_constant<bool, value> flag; + boost::intrusive::detail::bool_<value> flag; return pointer_traits::priv_dynamic_cast_from(flag, uptr); } @@ -157,38 +159,46 @@ struct pointer_traits { return pointer_traits::to_raw_pointer(p.operator->()); } //priv_pointer_to - static pointer priv_pointer_to(boost::true_type, typename boost::intrusive::detail::unvoid<element_type>::type& r) - { return Ptr::pointer_to(r); } + static pointer priv_pointer_to(boost::intrusive::detail::true_, reference r) + { return Ptr::pointer_to(r); } - static pointer priv_pointer_to(boost::false_type, typename boost::intrusive::detail::unvoid<element_type>::type& r) - { return pointer(boost::intrusive::detail::addressof(r)); } + static pointer priv_pointer_to(boost::intrusive::detail::false_, reference r) + { return pointer(boost::intrusive::detail::addressof(r)); } //priv_static_cast_from template<class UPtr> - static pointer priv_static_cast_from(boost::true_type, const UPtr &uptr) + static pointer priv_static_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) { return Ptr::static_cast_from(uptr); } template<class UPtr> - static pointer priv_static_cast_from(boost::false_type, const UPtr &uptr) - { return pointer_to(static_cast<element_type&>(*uptr)); } + static pointer priv_static_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) + { return pointer_to(*static_cast<element_type*>(to_raw_pointer(uptr))); } //priv_const_cast_from template<class UPtr> - static pointer priv_const_cast_from(boost::true_type, const UPtr &uptr) + static pointer priv_const_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) { return Ptr::const_cast_from(uptr); } template<class UPtr> - static pointer priv_const_cast_from(boost::false_type, const UPtr &uptr) + static pointer priv_const_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) { return pointer_to(const_cast<element_type&>(*uptr)); } //priv_dynamic_cast_from template<class UPtr> - static pointer priv_dynamic_cast_from(boost::true_type, const UPtr &uptr) + static pointer priv_dynamic_cast_from(boost::intrusive::detail::true_, const UPtr &uptr) { return Ptr::dynamic_cast_from(uptr); } template<class UPtr> - static pointer priv_dynamic_cast_from(boost::false_type, const UPtr &uptr) - { return pointer_to(*dynamic_cast<element_type*>(&*uptr)); } + static pointer priv_dynamic_cast_from(boost::intrusive::detail::false_, const UPtr &uptr) + { + element_type *p = dynamic_cast<element_type*>(&*uptr); + if(!p){ + return pointer(); + } + else{ + return pointer_to(*p); + } + } ///@endcond }; @@ -224,8 +234,8 @@ struct pointer_traits<T*> //!shall be used instead of rebind<U> to obtain a pointer to U. template <class U> using rebind = U*; #else - typedef typename boost::intrusive::detail::unvoid<element_type>::type& reference; - #if !defined(BOOST_NO_TEMPLATE_ALIASES) + typedef typename boost::intrusive::detail::unvoid_ref<element_type>::type reference; + #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) template <class U> using rebind = U*; #endif #endif diff --git a/boost/intrusive/priority_compare.hpp b/boost/intrusive/priority_compare.hpp index abde27ac0d..419a7d2293 100644 --- a/boost/intrusive/priority_compare.hpp +++ b/boost/intrusive/priority_compare.hpp @@ -13,6 +13,10 @@ #ifndef BOOST_INTRUSIVE_PRIORITY_COMPARE_HPP #define BOOST_INTRUSIVE_PRIORITY_COMPARE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> @@ -23,14 +27,35 @@ namespace intrusive { template <class T> struct priority_compare - : public std::binary_function<T, T, bool> { + //Compatibility with std::binary_function + typedef T first_argument_type; + typedef T second_argument_type; + typedef bool result_type; + bool operator()(const T &val, const T &val2) const { return priority_order(val, val2); } }; +/// @cond + +template<class Less, class T> +struct get_prio +{ + typedef Less type; +}; + + +template<class T> +struct get_prio<void, T> +{ + typedef ::boost::intrusive::priority_compare<T> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/rbtree.hpp b/boost/intrusive/rbtree.hpp index 1c0c30edcb..d6e692ef95 100644 --- a/boost/intrusive/rbtree.hpp +++ b/boost/intrusive/rbtree.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,55 +12,50 @@ #ifndef BOOST_INTRUSIVE_RBTREE_HPP #define BOOST_INTRUSIVE_RBTREE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <algorithm> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> #include <functional> -#include <iterator> #include <utility> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/static_assert.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/set_hook.hpp> #include <boost/intrusive/detail/rbtree_node.hpp> +#include <boost/intrusive/bstree.hpp> #include <boost/intrusive/detail/tree_node.hpp> -#include <boost/intrusive/detail/ebo_functor_holder.hpp> #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> -#include <boost/intrusive/detail/function_detector.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/options.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> #include <boost/intrusive/rbtree_algorithms.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/move/move.hpp> + +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize> -struct setopt +struct default_rbtree_hook_applier +{ template <class T> struct apply{ typedef typename T::default_rbtree_hook type; }; }; + +template<> +struct is_default_hook_tag<default_rbtree_hook_applier> +{ static const bool value = true; }; + +struct rbtree_defaults { - typedef ValueTraits value_traits; - typedef Compare compare; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; + typedef default_rbtree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + typedef void header_holder_type; }; -template <class T> -struct set_defaults - : pack_options - < none - , base_hook<detail::default_set_hook> - , constant_time_size<true> - , size_type<std::size_t> - , compare<std::less<T> > - >::type -{}; - /// @endcond //! The class template rbtree is an intrusive red-black tree container, that @@ -79,1644 +74,411 @@ struct set_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class rbtree_impl - : private detail::clear_on_destructor_base<rbtree_impl<Config> > + /// @cond + : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> + /// @endcond { - template<class C> friend class detail::clear_on_destructor_base; public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; + typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType + , ConstantTimeSize, RbTreeAlgorithms + , HeaderHolder> tree_type; + typedef tree_type implementation_defined; /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - - typedef typename pointer_traits<pointer>::element_type value_type; - typedef value_type key_type; - typedef typename pointer_traits<pointer>::reference reference; - typedef typename pointer_traits<const_pointer>::reference const_reference; - typedef typename pointer_traits<const_pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef typename Config::compare value_compare; - typedef value_compare key_compare; - typedef tree_iterator<rbtree_impl, false> iterator; - typedef tree_iterator<rbtree_impl, true> const_iterator; - typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; - typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename node_traits::node_ptr node_ptr; - typedef typename node_traits::const_node_ptr const_node_ptr; - typedef rbtree_algorithms<node_traits> node_algorithms; - - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::key_type key_type; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef typename implementation_defined::node_algorithms node_algorithms; + + static const bool constant_time_size = implementation_defined::constant_time_size; /// @cond private: - typedef detail::size_holder<constant_time_size, size_type> size_traits; //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(rbtree_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; + /// @endcond + + public: + + typedef typename implementation_defined::insert_commit_data insert_commit_data; + + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit rbtree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} + + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) + template<class Iterator> + rbtree_impl( bool unique, Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(unique, b, e, cmp, v_traits) + {} - //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) + rbtree_impl(BOOST_RV_REF(rbtree_impl) x) + : tree_type(::boost::move(static_cast<tree_type&>(x))) + {} - struct header_plus_size : public size_traits - { node header_; }; + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) + rbtree_impl& operator=(BOOST_RV_REF(rbtree_impl) x) + { return static_cast<rbtree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare> - { - node_plus_pred_t(const value_compare &comp) - : detail::ebo_functor_holder<value_compare>(comp) - {} - header_plus_size header_plus_size_; - }; + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~rbtree_impl(); - struct data_t : public rbtree_impl::value_traits - { - typedef typename rbtree_impl::value_traits value_traits; - data_t(const value_compare & comp, const value_traits &val_traits) - : value_traits(val_traits), node_plus_pred_(comp) - {} - node_plus_pred_t node_plus_pred_; - } data_; + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); - const value_compare &priv_comp() const - { return data_.node_plus_pred_.get(); } + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; - value_compare &priv_comp() - { return data_.node_plus_pred_.get(); } + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; - const value_traits &priv_value_traits() const - { return data_; } + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); - value_traits &priv_value_traits() - { return data_; } + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; - node_ptr priv_header_ptr() - { return pointer_traits<node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; - const_node_ptr priv_header_ptr() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; - size_traits &priv_size_traits() - { return data_.node_plus_pred_.header_plus_size_; } + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; - const size_traits &priv_size_traits() const - { return data_.node_plus_pred_.header_plus_size_; } + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static rbtree_impl &container_from_end_iterator(iterator end_iterator); - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator); - protected: - value_compare &prot_comp() - { return priv_comp(); } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static rbtree_impl &container_from_iterator(iterator it); - const node &prot_header_node() const - { return data_.node_plus_pred_.header_plus_size_.header_; } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const rbtree_impl &container_from_iterator(const_iterator it); - node &prot_header_node() - { return data_.node_plus_pred_.header_plus_size_.header_; } + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; - void prot_set_size(size_type s) - { this->priv_size_traits().set_size(s); } + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; - /// @endcond + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; - public: + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } + //! @copydoc ::boost::intrusive::bstree::swap + void swap(rbtree_impl& other); - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } + //! @copydoc ::boost::intrusive::bstree::clone_from + template <class Cloner, class Disposer> + void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer); - typedef typename node_algorithms::insert_commit_data insert_commit_data; + //! @copydoc ::boost::intrusive::bstree::insert_equal(reference) + iterator insert_equal(reference value); - //! <b>Effects</b>: Constructs an empty tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructorof the value_compare object throws. Basic guarantee. - rbtree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty tree and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee. - template<class Iterator> - rbtree_impl( bool unique, Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - if(unique) - this->insert_unique(b, e); - else - this->insert_equal(b, e); - } - - //! <b>Effects</b>: to-do - //! - rbtree_impl(BOOST_RV_REF(rbtree_impl) x) - : data_(::boost::move(x.priv_comp()), ::boost::move(x.priv_value_traits())) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - this->swap(x); - } - - //! <b>Effects</b>: to-do - //! - rbtree_impl& operator=(BOOST_RV_REF(rbtree_impl) x) - { this->swap(x); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called), but the nodes according to - //! the value_traits template parameter are reinitialized and thus can be reused. - //! - //! <b>Complexity</b>: Linear to elements contained in *this. - //! - //! <b>Throws</b>: Nothing. - ~rbtree_impl() - {} + //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference) + iterator insert_equal(const_iterator hint, reference value); - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return iterator (node_traits::get_left(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return cbegin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return const_iterator (node_traits::get_left(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return iterator (this->priv_header_ptr(), this); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return cend(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return const_iterator (uncast(this->priv_header_ptr()), this); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return const_reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return const_reverse_iterator(end()); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return reverse_iterator(begin()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return const_reverse_iterator(begin()); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return const_reverse_iterator(begin()); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the rbtree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static rbtree_impl &container_from_end_iterator(iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the rbtree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } - - //! <b>Precondition</b>: it must be a valid iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static rbtree_impl &container_from_iterator(iterator it) - { return priv_container_from_iterator(it); } - - //! <b>Precondition</b>: it must be a valid end const_iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const rbtree_impl &container_from_iterator(const_iterator it) - { return priv_container_from_iterator(it); } - - //! <b>Effects</b>: Returns the value_compare object used by the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return priv_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return node_algorithms::unique(this->priv_header_ptr()); } - - //! <b>Effects</b>: Returns the number of elements stored in the tree. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { - if(constant_time_size) - return this->priv_size_traits().get_size(); - else{ - return (size_type)node_algorithms::size(this->priv_header_ptr()); - } - } - - //! <b>Effects</b>: Swaps the contents of two rbtrees. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the comparison functor's swap call throws. - void swap(rbtree_impl& other) - { - //This can throw - using std::swap; - swap(priv_comp(), priv_comp()); - //These can't throw - node_algorithms::swap_tree(this->priv_header_ptr(), node_ptr(other.priv_header_ptr())); - if(constant_time_size){ - size_type backup = this->priv_size_traits().get_size(); - this->priv_size_traits().set_size(other.priv_size_traits().get_size()); - other.priv_size_traits().set_size(backup); - } - } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree before the upper bound. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(reference value) - { - detail::key_nodeptr_comp<value_compare, rbtree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_equal_upper_bound - (this->priv_header_ptr(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } - - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator. - //! - //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case) - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(const_iterator hint, reference value) - { - detail::key_nodeptr_comp<value_compare, rbtree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_equal - (this->priv_header_ptr(), hint.pointed_node(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a each element of a range into the tree - //! before the upper bound of the key of each element. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator) template<class Iterator> - void insert_equal(Iterator b, Iterator e) - { - iterator iend(this->end()); - for (; b != e; ++b) - this->insert_equal(iend, *b); - } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree if the value - //! is not already present. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - std::pair<iterator, bool> insert_unique(reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), commit_data); - if(!ret.second) - return ret; - return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true); - } - - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator - //! - //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint - //! to where it will be inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time (two comparisons in the worst case) - //! if t is inserted immediately before hint. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_unique(const_iterator hint, reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), commit_data); - if(!ret.second) - return ret.first; - return insert_unique_commit(value, commit_data); - } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Tries to insert each element of a range into the tree. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - template<class Iterator> - void insert_unique(Iterator b, Iterator e) - { - if(this->empty()){ - iterator iend(this->end()); - for (; b != e; ++b) - this->insert_unique(iend, *b); - } - else{ - for (; b != e; ++b) - this->insert_unique(*b); - } - } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + void insert_equal(Iterator b, Iterator e); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(reference) + std::pair<iterator, bool> insert_unique(reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference) + iterator insert_unique(const_iterator hint, reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check - (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - (node_algorithms::insert_unique_check - (this->priv_header_ptr(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check (const_iterator hint, const KeyType &key - ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - (node_algorithms::insert_unique_check - (this->priv_header_ptr(), hint.pointed_node(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the container between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::insert_unique_commit - (this->priv_header_ptr(), to_insert, commit_data); - this->priv_size_traits().increment(); - return iterator(to_insert, this); - } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" tree ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - this->priv_size_traits().increment(); - return iterator(node_algorithms::insert_before - (this->priv_header_ptr(), pos.pointed_node(), to_insert), this); - } - - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - this->priv_size_traits().increment(); - node_algorithms::push_back(this->priv_header_ptr(), to_insert); - } - - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - this->priv_size_traits().increment(); - node_algorithms::push_front(this->priv_header_ptr(), to_insert); - } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { - const_iterator ret(i); - ++ret; - node_ptr to_erase(i.pointed_node()); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); - node_algorithms::erase(this->priv_header_ptr(), to_erase); - this->priv_size_traits().decrement(); - if(safemode_or_autounlink) - node_algorithms::init(to_erase); - return ret.unconst(); - } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { size_type n; return private_erase(b, e, n); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return this->erase(value, priv_comp()); } - - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_commit + iterator insert_unique_commit(reference value, const insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator) + template<class Iterator> + void insert_unique(Iterator b, Iterator e); + + //! @copydoc ::boost::intrusive::bstree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::bstree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::bstree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n); - return n; - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { - node_ptr to_erase(i.pointed_node()); - iterator ret(this->erase(i)); - disposer(get_real_value_traits().to_value_ptr(to_erase)); - return ret; - } - - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + size_type erase(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator i, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { - std::pair<iterator,iterator> p = this->equal_range(value); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { size_type n; return private_erase(b, e, n, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } - - //! <b>Effects</b>: Erases all of the elements. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { - if(safemode_or_autounlink){ - this->clear_and_dispose(detail::null_disposer()); - } - else{ - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - } - - //! <b>Effects</b>: Erases all of the elements calling disposer(p) for - //! each node to be erased. - //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)), - //! where N is the number of elements in the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. Calls N times to disposer functor. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::clear + void clear(); + + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { - node_algorithms::clear_and_dispose(this->priv_header_ptr() - , detail::node_disposer<Disposer, rbtree_impl>(disposer, this)); - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count(const_reference value) const - { return this->count(value, priv_comp()); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType &key, KeyValueCompare comp) const - { - std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); - return std::distance(ret.first, ret.second); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator lower_bound(const_reference value) - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator lower_bound(const_reference value) const - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator upper_bound(const_reference value) - { return this->upper_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator upper_bound(const_reference value) const - { return this->upper_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator find(const_reference value) - { return this->find(value, priv_comp()); } - - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator find(const_reference value) const - { return this->find(value, priv_comp()); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - return const_iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<iterator,iterator> equal_range(const_reference value) - { return this->equal_range(value, priv_comp()); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return this->equal_range(value, priv_comp()); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator,const_iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator,const_iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { - detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer) - { - this->clear_and_dispose(disposer); - if(!src.empty()){ - detail::exception_disposer<rbtree_impl, Disposer> - rollback(*this, disposer); - node_algorithms::clone - (const_node_ptr(src.priv_header_ptr()) - ,node_ptr(this->priv_header_ptr()) - ,detail::node_cloner<Cloner, rbtree_impl>(cloner, this) - ,detail::node_disposer<Disposer, rbtree_impl>(disposer, this)); - this->priv_size_traits().set_size(src.priv_size_traits().get_size()); - this->priv_comp() = src.priv_comp(); - rollback.release(); - } - } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { - node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance - (this->priv_header_ptr())); - if(!to_be_disposed) - return 0; - this->priv_size_traits().decrement(); - if(safemode_or_autounlink)//If this is commented does not work with normal_link - node_algorithms::init(to_be_disposed); - return get_real_value_traits().to_value_ptr(to_be_disposed); - } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { - node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this) - , this->priv_header_ptr() - , get_real_value_traits().to_node_ptr(with_this)); - if(safemode_or_autounlink) - node_algorithms::init(replace_this.pointed_node()); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return iterator (value_traits::to_node_ptr(value), 0); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return iterator (value_traits::to_node_ptr(value), this); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); } - - //! <b>Requires</b>: value shall not be in a tree. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { node_algorithms::init(value_traits::to_node_ptr(value)); } - - //! <b>Effects</b>: removes "value" from the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic time. - //! - //! <b>Note</b>: This static function is only usable with non-constant - //! time size containers that have stateless comparison functors. - //! - //! If the user calls - //! this function with a constant time size container or stateful comparison - //! functor a compilation error will be issued. - static void remove_node(reference value) - { - BOOST_STATIC_ASSERT((!constant_time_size)); - node_ptr to_remove(value_traits::to_node_ptr(value)); - node_algorithms::unlink(to_remove); - if(safemode_or_autounlink) - node_algorithms::init(to_remove); - } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - private: - template<class Disposer> - iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer) - { - for(n = 0; b != e; ++n) - this->erase_and_dispose(b++, disposer); - return b.unconst(); - } - - iterator private_erase(const_iterator b, const_iterator e, size_type &n) - { - for(n = 0; b != e; ++n) - this->erase(b++); - return b.unconst(); - } - /// @endcond + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - private: - static rbtree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) - { - header_plus_size *r = detail::parent_from_member<header_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &header_plus_size::header_); - node_plus_pred_t *n = detail::parent_from_member - <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_); - data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_); - rbtree_impl *rb = detail::parent_from_member<rbtree_impl, data_t>(d, &rbtree_impl::data_); - return *rb; - } - - static rbtree_impl &priv_container_from_iterator(const const_iterator &it) - { return priv_container_from_end_iterator(it.end_iterator_from_it()); } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator< -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } +bool operator< (const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -bool operator== -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ - typedef rbtree_impl<Config> tree_type; - typedef typename tree_type::const_iterator const_iterator; - - if(tree_type::constant_time_size && x.size() != y.size()){ - return false; - } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } -} +bool operator==(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y) -#else -(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(rbtree_impl<T, Options...> &x, rbtree_impl<T, Options...> &y) -#else -(rbtree_impl<Config> &x, rbtree_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(rbtree_impl<T, Options...> &x, rbtree_impl<T, Options...> &y); -/// @cond -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - > -#else +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +//! Helper metafunction to define a \c rbtree that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif -struct make_rbtree_opt +struct make_rbtree { + /// @cond typedef typename pack_options - < set_defaults<T>, + < rbtree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type packed_options; + typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; - typedef setopt + typedef rbtree_impl < value_traits , typename packed_options::compare , typename packed_options::size_type , packed_options::constant_time_size - > type; -}; -/// @endcond - -//! Helper metafunction to define a \c rbtree that yields to the same type when the -//! same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class ...Options> -#else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#endif -struct make_rbtree -{ - /// @cond - typedef rbtree_impl - < typename make_rbtree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class rbtree : public make_rbtree<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1725,7 +487,7 @@ class rbtree typedef typename make_rbtree <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1735,15 +497,16 @@ class rbtree public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::reverse_iterator reverse_iterator; + typedef typename Base::const_reverse_iterator const_reverse_iterator; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - rbtree( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit rbtree( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1759,7 +522,7 @@ class rbtree {} rbtree& operator=(BOOST_RV_REF(rbtree) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<rbtree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static rbtree &container_from_end_iterator(iterator end_iterator) { return static_cast<rbtree &>(Base::container_from_end_iterator(end_iterator)); } @@ -1767,16 +530,15 @@ class rbtree static const rbtree &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const rbtree &>(Base::container_from_end_iterator(end_iterator)); } - static rbtree &container_from_it(iterator it) + static rbtree &container_from_iterator(iterator it) { return static_cast<rbtree &>(Base::container_from_iterator(it)); } - static const rbtree &container_from_it(const_iterator it) + static const rbtree &container_from_iterator(const_iterator it) { return static_cast<const rbtree &>(Base::container_from_iterator(it)); } }; #endif - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/rbtree_algorithms.hpp b/boost/intrusive/rbtree_algorithms.hpp index 451a550a84..376deaf312 100644 --- a/boost/intrusive/rbtree_algorithms.hpp +++ b/boost/intrusive/rbtree_algorithms.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012. +// (C) Copyright Ion Gaztanaga 2006-2014. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -10,31 +10,6 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// -// The internal implementation of red-black trees is based on that of SGI STL -// stl_tree.h file: -// -// Copyright (c) 1996,1997 -// Silicon Graphics Computer Systems, Inc. -// -// Permission to use, copy, modify, distribute and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that the above copyright notice appear in all copies and -// that both that copyright notice and this permission notice appear -// in supporting documentation. Silicon Graphics makes no -// representations about the suitability of this software for any -// purpose. It is provided "as is" without express or implied warranty. -// -// -// Copyright (c) 1994 -// Hewlett-Packard Company -// -// Permission to use, copy, modify, distribute and sell this software -// and its documentation for any purpose is hereby granted without fee, -// provided that the above copyright notice appear in all copies and -// that both that copyright notice and this permission notice appear -// in supporting documentation. Hewlett-Packard Company makes no -// representations about the suitability of this software for any -// purpose. It is provided "as is" without express or implied warranty. // // The tree destruction algorithm is based on Julienne Walker and The EC Team code: // @@ -48,19 +23,80 @@ #ifndef BOOST_INTRUSIVE_RBTREE_ALGORITHMS_HPP #define BOOST_INTRUSIVE_RBTREE_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> +#include <boost/intrusive/detail/ebo_functor_holder.hpp> namespace boost { namespace intrusive { +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +template<class NodeTraits, class F> +struct rbtree_node_cloner + : private detail::ebo_functor_holder<F> +{ + typedef typename NodeTraits::node_ptr node_ptr; + typedef detail::ebo_functor_holder<F> base_t; + + rbtree_node_cloner(F f) + : base_t(f) + {} + + node_ptr operator()(const node_ptr & p) + { + node_ptr n = base_t::get()(p); + NodeTraits::set_color(n, NodeTraits::get_color(p)); + return n; + } +}; + +namespace detail { + +template<class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct rbtree_node_checker + : public bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> base_checker_t; + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::const_node_ptr const_node_ptr; + + typedef typename base_checker_t::return_type return_type; + + rbtree_node_checker(const NodePtrCompare& comp, ExtraChecker extra_checker) + : base_checker_t(comp, extra_checker) + {} + + void operator () (const const_node_ptr& p, + const return_type& check_return_left, const return_type& check_return_right, + return_type& check_return) + { + if (node_traits::get_color(p) == node_traits::red()) + { + if (node_traits::get_left(p)) + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_color(node_traits::get_left(p)) == node_traits::black()); + if (node_traits::get_right(p)) + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_color(node_traits::get_right(p)) == node_traits::black()); + } + base_checker_t::operator()(p, check_return_left, check_return_right, check_return); + } +}; + +} // namespace detail + +#endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! rbtree_algorithms provides basic algorithms to manipulate //! nodes forming a red-black tree. The insertion and deletion algorithms are //! based on those in Cormen, Leiserson, and Rivest, Introduction to Algorithms @@ -82,7 +118,7 @@ namespace intrusive { //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the binary search tree //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -113,6 +149,9 @@ namespace intrusive { //! <tt>static color red();</tt> template<class NodeTraits> class rbtree_algorithms + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_algorithms<NodeTraits> + #endif { public: typedef NodeTraits node_traits; @@ -124,167 +163,71 @@ class rbtree_algorithms /// @cond private: - typedef detail::tree_algorithms<NodeTraits> tree_algorithms; + typedef bstree_algorithms<NodeTraits> bstree_algo; - template<class F> - struct rbtree_node_cloner - : private detail::ebo_functor_holder<F> - { - typedef detail::ebo_functor_holder<F> base_t; + /// @endcond - rbtree_node_cloner(F f) - : base_t(f) - {} + public: - node_ptr operator()(const node_ptr & p) - { - node_ptr n = base_t::get()(p); - NodeTraits::set_color(n, NodeTraits::get_color(p)); - return n; - } - }; + //! This type is the information that will be + //! filled by insert_unique_check + typedef typename bstree_algo::insert_commit_data insert_commit_data; - struct rbtree_erase_fixup - { - void operator()(const node_ptr & to_erase, const node_ptr & successor) - { - //Swap color of y and z - color tmp(NodeTraits::get_color(successor)); - NodeTraits::set_color(successor, NodeTraits::get_color(to_erase)); - NodeTraits::set_color(to_erase, tmp); - } - }; + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - /// @endcond + //! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const const_node_ptr&) + static node_ptr get_header(const const_node_ptr & n); - public: - static node_ptr begin_node(const const_node_ptr & header) - { return tree_algorithms::begin_node(header); } + //! @copydoc ::boost::intrusive::bstree_algorithms::begin_node + static node_ptr begin_node(const const_node_ptr & header); - static node_ptr end_node(const const_node_ptr & header) - { return tree_algorithms::end_node(header); } + //! @copydoc ::boost::intrusive::bstree_algorithms::end_node + static node_ptr end_node(const const_node_ptr & header); - //! This type is the information that will be - //! filled by insert_unique_check - typedef typename tree_algorithms::insert_commit_data insert_commit_data; - - //! <b>Requires</b>: header1 and header2 must be the header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two trees. After the function header1 will contain - //! links to the second tree and header2 will have links to the first tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static void swap_tree(const node_ptr & header1, const node_ptr & header2) - { return tree_algorithms::swap_tree(header1, header2); } - - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree + static void swap_tree(const node_ptr & header1, const node_ptr & header2); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&) static void swap_nodes(const node_ptr & node1, const node_ptr & node2) { if(node1 == node2) return; - node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2)); + node_ptr header1(bstree_algo::get_header(node1)), header2(bstree_algo::get_header(node2)); swap_nodes(node1, header1, node2, header2); } - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees with header header1 and header2. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&,const node_ptr&,const node_ptr&) static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2) { if(node1 == node2) return; - tree_algorithms::swap_nodes(node1, header1, node2, header2); + bstree_algo::swap_nodes(node1, header1, node2, header2); //Swap color color c = NodeTraits::get_color(node1); NodeTraits::set_color(node1, NodeTraits::get_color(node2)); NodeTraits::set_color(node2, c); } - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&) static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) { if(node_to_be_replaced == new_node) return; - replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node); + replace_node(node_to_be_replaced, bstree_algo::get_header(node_to_be_replaced), new_node); } - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! with header "header" and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&,const node_ptr&) static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::replace_node(node_to_be_replaced, header, new_node); + bstree_algo::replace_node(node_to_be_replaced, header, new_node); NodeTraits::set_color(new_node, NodeTraits::get_color(node_to_be_replaced)); } - //! <b>Requires</b>: node is a tree node but not the header. - //! - //! <b>Effects</b>: Unlinks the node and rebalances the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - static void unlink(const node_ptr & node) + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink(const node_ptr&) + static void unlink(const node_ptr& node) { node_ptr x = NodeTraits::get_parent(node); if(x){ @@ -294,577 +237,257 @@ class rbtree_algorithms } } - //! <b>Requires</b>: header is the header of a tree. - //! - //! <b>Effects</b>: Unlinks the leftmost node from the tree, and - //! updates the header link to the new leftmost node. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header) - { return tree_algorithms::unlink_leftmost_without_rebalance(header); } - - //! <b>Requires</b>: node is a node of the tree or an node initialized - //! by init(...). - //! - //! <b>Effects</b>: Returns true if the node is initialized by init(). - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - static bool unique(const const_node_ptr & node) - { return tree_algorithms::unique(node); } - - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & node) - { return tree_algorithms::count(node); } - - //! <b>Requires</b>: header is the header node of the tree. - //! - //! <b>Effects</b>: Returns the number of nodes above the header. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t size(const const_node_ptr & header) - { return tree_algorithms::size(header); } - - //! <b>Requires</b>: p is a node from the tree except the header. - //! - //! <b>Effects</b>: Returns the next node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr next_node(const node_ptr & p) - { return tree_algorithms::next_node(p); } - - //! <b>Requires</b>: p is a node from the tree except the leftmost node. - //! - //! <b>Effects</b>: Returns the previous node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr prev_node(const node_ptr & p) - { return tree_algorithms::prev_node(p); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: After the function unique(node) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init(const node_ptr & node) - { tree_algorithms::init(node); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: Initializes the header to represent an empty tree. - //! unique(header) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance + static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::unique(const const_node_ptr&) + static bool unique(const const_node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::size(const const_node_ptr&) + static std::size_t size(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::next_node(const node_ptr&) + static node_ptr next_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(const node_ptr&) + static node_ptr prev_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::init(const node_ptr&) + static void init(const node_ptr & node); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::init_header(const node_ptr&) static void init_header(const node_ptr & header) { - tree_algorithms::init_header(header); + bstree_algo::init_header(header); NodeTraits::set_color(header, NodeTraits::red()); } - //! <b>Requires</b>: header must be the header of a tree, z a node - //! of that tree and z != header. - //! - //! <b>Effects</b>: Erases node "z" from the tree with header "header". - //! - //! <b>Complexity</b>: Amortized constant time. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree_algorithms::erase(const node_ptr&,const node_ptr&) static node_ptr erase(const node_ptr & header, const node_ptr & z) { - typename tree_algorithms::data_for_rebalance info; - tree_algorithms::erase(header, z, rbtree_erase_fixup(), info); - node_ptr x = info.x; - node_ptr x_parent = info.x_parent; - - //Rebalance rbtree - if(NodeTraits::get_color(z) != NodeTraits::red()){ - rebalance_after_erasure(header, x, x_parent); + typename bstree_algo::data_for_rebalance info; + bstree_algo::erase(header, z, info); + + color new_z_color; + if(info.y != z){ + new_z_color = NodeTraits::get_color(info.y); + NodeTraits::set_color(info.y, NodeTraits::get_color(z)); + } + else{ + new_z_color = NodeTraits::get_color(z); + } + //Rebalance rbtree if needed + if(new_z_color != NodeTraits::red()){ + rebalance_after_erasure(header, info.x, info.x_parent); } return z; } - //! <b>Requires</b>: "cloner" must be a function - //! object taking a node_ptr and returning a new cloned node of it. "disposer" must - //! take a node_ptr and shouldn't throw. - //! - //! <b>Effects</b>: First empties target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! Then, duplicates the entire tree pointed by "source_header" cloning each - //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain - //! the nodes of the target tree. If "cloner" throws, the cloned target nodes - //! are disposed using <tt>void disposer(const node_ptr &)</tt>. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + //! @copydoc ::boost::intrusive::bstree_algorithms::clone(const const_node_ptr&,const node_ptr&,Cloner,Disposer) template <class Cloner, class Disposer> static void clone (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer) { - rbtree_node_cloner<Cloner> new_cloner(cloner); - tree_algorithms::clone(source_header, target_header, new_cloner, disposer); + rbtree_node_cloner<NodeTraits, Cloner> new_cloner(cloner); + bstree_algo::clone(source_header, target_header, new_cloner, disposer); } - //! <b>Requires</b>: "disposer" must be an object function - //! taking a node_ptr parameter and shouldn't throw. - //! - //! <b>Effects</b>: Empties the target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(const node_ptr&,Disposer) template<class Disposer> - static void clear_and_dispose(const node_ptr & header, Disposer disposer) - { tree_algorithms::clear_and_dispose(header, disposer); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is - //! not less than "key" according to "comp" or "header" if that element does - //! not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + static void clear_and_dispose(const node_ptr & header, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr lower_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::lower_bound(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater - //! than "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr upper_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::upper_bound(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to - //! "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&, const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr find - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::find(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing - //! all elements that are equivalent to "key" according to "comp" or an - //! empty range that indicates the position where those elements would be - //! if they there are no equivalent elements. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> equal_range - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::equal_range(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp - , bool left_closed, bool right_closed) - { return tree_algorithms::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the upper bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + , bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + template<class KeyType, class KeyNodePtrCompare> + static std::size_t count(const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_upper_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal_upper_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal_upper_bound(h, new_node, comp); + bstree_algo::insert_equal_upper_bound(h, new_node, comp); rebalance_after_insertion(h, new_node); return new_node; } - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the lower bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_lower_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal_lower_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal_lower_bound(h, new_node, comp); + bstree_algo::insert_equal_lower_bound(h, new_node, comp); rebalance_after_insertion(h, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from - //! the "header"'s tree. - //! - //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case). - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if new_node is inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal(const node_ptr&,const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare> static node_ptr insert_equal (const node_ptr & header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp) { - tree_algorithms::insert_equal(header, hint, new_node, comp); + bstree_algo::insert_equal(header, hint, new_node, comp); rebalance_after_insertion(header, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "pos" must be a valid iterator or header (end) node. - //! "pos" must be an iterator pointing to the successor to "new_node" - //! once inserted according to the order of already inserted nodes. This function does not - //! check "pos" and this precondition must be guaranteed by the caller. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node" - //! tree invariants might be broken. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_before(const node_ptr&,const node_ptr&,const node_ptr&) static node_ptr insert_before (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node) { - tree_algorithms::insert_before(header, pos, new_node); + bstree_algo::insert_before(header, pos, new_node); rebalance_after_insertion(header, new_node); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering no less than the - //! greatest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is less than the greatest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_back(const node_ptr&,const node_ptr&) static void push_back(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_back(header, new_node); + bstree_algo::push_back(header, new_node); rebalance_after_insertion(header, new_node); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering, no greater than the - //! lowest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is greater than the lowest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_front(const node_ptr&,const node_ptr&) static void push_front(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_front(header, new_node); + bstree_algo::push_front(header, new_node); rebalance_after_insertion(header, new_node); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) - { return tree_algorithms::insert_unique_check(header, key, comp, commit_data); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! "hint" is node from the "header"'s tree. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" using "hint" as a hint to where it should be - //! inserted and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! If "hint" is the upper_bound the function has constant time - //! complexity (two comparisons in the worst case). - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic, but it is - //! amortized constant time if new_node should be inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + ,KeyNodePtrCompare comp, insert_commit_data &commit_data); + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const node_ptr &hint, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) - { return tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "commit_data" must have been obtained from a previous call to - //! "insert_unique_check". No objects should have been inserted or erased - //! from the set between the "insert_unique_check" that filled "commit_data" - //! and the call to "insert_commit". - //! - //! - //! <b>Effects</b>: Inserts new_node in the set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. + ,KeyNodePtrCompare comp, insert_commit_data &commit_data); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_commit(const node_ptr&,const node_ptr&,const insert_commit_data&) static void insert_unique_commit (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data) { - tree_algorithms::insert_unique_commit(header, new_value, commit_data); + bstree_algo::insert_unique_commit(header, new_value, commit_data); rebalance_after_insertion(header, new_value); } - //! <b>Requires</b>: "n" must be a node inserted in a tree. - //! - //! <b>Effects</b>: Returns a pointer to the header node of the tree. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - static node_ptr get_header(const node_ptr & n) - { return tree_algorithms::get_header(n); } - - /// @cond - private: - - //! <b>Requires</b>: p is a node of a tree. - //! - //! <b>Effects</b>: Returns true if p is the header of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header static bool is_header(const const_node_ptr & p) { return NodeTraits::get_color(p) == NodeTraits::red() && - tree_algorithms::is_header(p); - //return NodeTraits::get_color(p) == NodeTraits::red() && - // NodeTraits::get_parent(NodeTraits::get_parent(p)) == p; + bstree_algo::is_header(p); } - static void rebalance_after_erasure(const node_ptr & header, const node_ptr &xnode, const node_ptr &xnode_parent) + /// @cond + private: + + static void rebalance_after_erasure(const node_ptr & header, node_ptr x, node_ptr x_parent) { - node_ptr x(xnode), x_parent(xnode_parent); - while(x != NodeTraits::get_parent(header) && (x == node_ptr() || NodeTraits::get_color(x) == NodeTraits::black())){ - if(x == NodeTraits::get_left(x_parent)){ + while(1){ + if(x_parent == header || (x && NodeTraits::get_color(x) != NodeTraits::black())){ + break; + } + //Don't cache x_is_leftchild or similar because x can be null and + //equal to both x_parent_left and x_parent_right + const node_ptr x_parent_left(NodeTraits::get_left(x_parent)); + if(x == x_parent_left){ //x is left child node_ptr w = NodeTraits::get_right(x_parent); + BOOST_INTRUSIVE_INVARIANT_ASSERT(w); if(NodeTraits::get_color(w) == NodeTraits::red()){ NodeTraits::set_color(w, NodeTraits::black()); NodeTraits::set_color(x_parent, NodeTraits::red()); - tree_algorithms::rotate_left(x_parent, header); + bstree_algo::rotate_left(x_parent, w, NodeTraits::get_parent(x_parent), header); w = NodeTraits::get_right(x_parent); } - if((NodeTraits::get_left(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()) && - (NodeTraits::get_right(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black())){ + node_ptr const w_left (NodeTraits::get_left(w)); + node_ptr const w_right(NodeTraits::get_right(w)); + if((!w_left || NodeTraits::get_color(w_left) == NodeTraits::black()) && + (!w_right || NodeTraits::get_color(w_right) == NodeTraits::black())){ NodeTraits::set_color(w, NodeTraits::red()); x = x_parent; x_parent = NodeTraits::get_parent(x_parent); } else { - if(NodeTraits::get_right(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()){ - NodeTraits::set_color(NodeTraits::get_left(w), NodeTraits::black()); + if(!w_right || NodeTraits::get_color(w_right) == NodeTraits::black()){ + NodeTraits::set_color(w_left, NodeTraits::black()); NodeTraits::set_color(w, NodeTraits::red()); - tree_algorithms::rotate_right(w, header); + bstree_algo::rotate_right(w, w_left, NodeTraits::get_parent(w), header); w = NodeTraits::get_right(x_parent); } NodeTraits::set_color(w, NodeTraits::get_color(x_parent)); NodeTraits::set_color(x_parent, NodeTraits::black()); - if(NodeTraits::get_right(w)) - NodeTraits::set_color(NodeTraits::get_right(w), NodeTraits::black()); - tree_algorithms::rotate_left(x_parent, header); + const node_ptr new_wright(NodeTraits::get_right(w)); + if(new_wright) + NodeTraits::set_color(new_wright, NodeTraits::black()); + bstree_algo::rotate_left(x_parent, NodeTraits::get_right(x_parent), NodeTraits::get_parent(x_parent), header); break; } } else { // same as above, with right_ <-> left_. - node_ptr w = NodeTraits::get_left(x_parent); + node_ptr w = x_parent_left; if(NodeTraits::get_color(w) == NodeTraits::red()){ NodeTraits::set_color(w, NodeTraits::black()); NodeTraits::set_color(x_parent, NodeTraits::red()); - tree_algorithms::rotate_right(x_parent, header); + bstree_algo::rotate_right(x_parent, w, NodeTraits::get_parent(x_parent), header); w = NodeTraits::get_left(x_parent); } - if((NodeTraits::get_right(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()) && - (NodeTraits::get_left(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black())){ + node_ptr const w_left (NodeTraits::get_left(w)); + node_ptr const w_right(NodeTraits::get_right(w)); + if((!w_right || NodeTraits::get_color(w_right) == NodeTraits::black()) && + (!w_left || NodeTraits::get_color(w_left) == NodeTraits::black())){ NodeTraits::set_color(w, NodeTraits::red()); x = x_parent; x_parent = NodeTraits::get_parent(x_parent); } else { - if(NodeTraits::get_left(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()){ - NodeTraits::set_color(NodeTraits::get_right(w), NodeTraits::black()); + if(!w_left || NodeTraits::get_color(w_left) == NodeTraits::black()){ + NodeTraits::set_color(w_right, NodeTraits::black()); NodeTraits::set_color(w, NodeTraits::red()); - tree_algorithms::rotate_left(w, header); + bstree_algo::rotate_left(w, w_right, NodeTraits::get_parent(w), header); w = NodeTraits::get_left(x_parent); } NodeTraits::set_color(w, NodeTraits::get_color(x_parent)); NodeTraits::set_color(x_parent, NodeTraits::black()); - if(NodeTraits::get_left(w)) - NodeTraits::set_color(NodeTraits::get_left(w), NodeTraits::black()); - tree_algorithms::rotate_right(x_parent, header); + const node_ptr new_wleft(NodeTraits::get_left(w)); + if(new_wleft) + NodeTraits::set_color(new_wleft, NodeTraits::black()); + bstree_algo::rotate_right(x_parent, NodeTraits::get_left(x_parent), NodeTraits::get_parent(x_parent), header); break; } } @@ -873,53 +496,52 @@ class rbtree_algorithms NodeTraits::set_color(x, NodeTraits::black()); } - - static void rebalance_after_insertion(const node_ptr & header, const node_ptr &pnode) + static void rebalance_after_insertion(const node_ptr & header, node_ptr p) { - node_ptr p(pnode); NodeTraits::set_color(p, NodeTraits::red()); - while(p != NodeTraits::get_parent(header) && NodeTraits::get_color(NodeTraits::get_parent(p)) == NodeTraits::red()){ + while(1){ node_ptr p_parent(NodeTraits::get_parent(p)); - node_ptr p_parent_parent(NodeTraits::get_parent(p_parent)); - if(tree_algorithms::is_left_child(p_parent)){ - node_ptr x = NodeTraits::get_right(p_parent_parent); - if(x && NodeTraits::get_color(x) == NodeTraits::red()){ - NodeTraits::set_color(p_parent, NodeTraits::black()); - NodeTraits::set_color(p_parent_parent, NodeTraits::red()); - NodeTraits::set_color(x, NodeTraits::black()); - p = p_parent_parent; - } - else { - if(!tree_algorithms::is_left_child(p)){ - p = p_parent; - tree_algorithms::rotate_left(p, header); - } - node_ptr new_p_parent(NodeTraits::get_parent(p)); - node_ptr new_p_parent_parent(NodeTraits::get_parent(new_p_parent)); - NodeTraits::set_color(new_p_parent, NodeTraits::black()); - NodeTraits::set_color(new_p_parent_parent, NodeTraits::red()); - tree_algorithms::rotate_right(new_p_parent_parent, header); - } + const node_ptr p_grandparent(NodeTraits::get_parent(p_parent)); + if(p_parent == header || NodeTraits::get_color(p_parent) == NodeTraits::black() || p_grandparent == header){ + break; + } + + NodeTraits::set_color(p_grandparent, NodeTraits::red()); + node_ptr const p_grandparent_left (NodeTraits::get_left (p_grandparent)); + bool const p_parent_is_left_child = p_parent == p_grandparent_left; + node_ptr const x(p_parent_is_left_child ? NodeTraits::get_right(p_grandparent) : p_grandparent_left); + + if(x && NodeTraits::get_color(x) == NodeTraits::red()){ + NodeTraits::set_color(x, NodeTraits::black()); + NodeTraits::set_color(p_parent, NodeTraits::black()); + p = p_grandparent; } - else{ - node_ptr x = NodeTraits::get_left(p_parent_parent); - if(x && NodeTraits::get_color(x) == NodeTraits::red()){ - NodeTraits::set_color(p_parent, NodeTraits::black()); - NodeTraits::set_color(p_parent_parent, NodeTraits::red()); - NodeTraits::set_color(x, NodeTraits::black()); - p = p_parent_parent; + else{ //Final step + const bool p_is_left_child(NodeTraits::get_left(p_parent) == p); + if(p_parent_is_left_child){ //p_parent is left child + if(!p_is_left_child){ //p is right child + bstree_algo::rotate_left_no_parent_fix(p_parent, p); + //No need to link p and p_grandparent: + // [NodeTraits::set_parent(p, p_grandparent) + NodeTraits::set_left(p_grandparent, p)] + //as p_grandparent is not the header, another rotation is coming and p_parent + //will be the left child of p_grandparent + p_parent = p; + } + bstree_algo::rotate_right(p_grandparent, p_parent, NodeTraits::get_parent(p_grandparent), header); } - else{ - if(tree_algorithms::is_left_child(p)){ - p = p_parent; - tree_algorithms::rotate_right(p, header); + else{ //p_parent is right child + if(p_is_left_child){ //p is left child + bstree_algo::rotate_right_no_parent_fix(p_parent, p); + //No need to link p and p_grandparent: + // [NodeTraits::set_parent(p, p_grandparent) + NodeTraits::set_right(p_grandparent, p)] + //as p_grandparent is not the header, another rotation is coming and p_parent + //will be the right child of p_grandparent + p_parent = p; } - node_ptr new_p_parent(NodeTraits::get_parent(p)); - node_ptr new_p_parent_parent(NodeTraits::get_parent(new_p_parent)); - NodeTraits::set_color(new_p_parent, NodeTraits::black()); - NodeTraits::set_color(new_p_parent_parent, NodeTraits::red()); - tree_algorithms::rotate_left(new_p_parent_parent, header); + bstree_algo::rotate_left(p_grandparent, p_parent, NodeTraits::get_parent(p_grandparent), header); } + NodeTraits::set_color(p_parent, NodeTraits::black()); + break; } } NodeTraits::set_color(NodeTraits::get_parent(header), NodeTraits::black()); @@ -927,6 +549,22 @@ class rbtree_algorithms /// @endcond }; +/// @cond + +template<class NodeTraits> +struct get_algo<RbTreeAlgorithms, NodeTraits> +{ + typedef rbtree_algorithms<NodeTraits> type; +}; + +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<RbTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::rbtree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/set.hpp b/boost/intrusive/set.hpp index 9a61560d75..b8366a2e80 100644 --- a/boost/intrusive/set.hpp +++ b/boost/intrusive/set.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,12 +13,17 @@ #ifndef BOOST_INTRUSIVE_SET_HPP #define BOOST_INTRUSIVE_SET_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> + #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/rbtree.hpp> -#include <iterator> -#include <boost/move/move.hpp> +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { @@ -37,12 +42,15 @@ namespace intrusive { #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> +#endif { /// @cond - typedef rbtree_impl<Config> tree_type; + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(set_impl) typedef tree_type implementation_defined; @@ -70,1203 +78,370 @@ class set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - //static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; - - /// @cond - private: - tree_type tree_; - - protected: - node &prot_header_node(){ return tree_.prot_header_node(); } - node const &prot_header_node() const{ return tree_.prot_header_node(); } - void prot_set_size(size_type s){ tree_.prot_set_size(s); } - value_compare &prot_comp(){ return tree_.prot_comp(); } - - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare object throws. - set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::rbtree::rbtree(const value_compare &,const value_traits &) + explicit set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty set and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is std::distance(last, first). - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::rbtree::rbtree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> set_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(true, b, e, cmp, v_traits) + : tree_type(true, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::rbtree::rbtree(rbtree &&) set_impl(BOOST_RV_REF(set_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::rbtree::operator=(rbtree &&) set_impl& operator=(BOOST_RV_REF(set_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~set_impl() - {} + { return static_cast<set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::rbtree::~rbtree() + ~set_impl(); + + //! @copydoc ::boost::intrusive::rbtree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::rbtree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::rbtree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::rbtree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::rbtree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::rbtree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::rbtree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::rbtree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::rbtree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::rbtree::container_from_end_iterator(iterator) + static set_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::rbtree::container_from_end_iterator(const_iterator) + static const set_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::rbtree::container_from_iterator(iterator) + static set_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::rbtree::container_from_iterator(const_iterator) + static const set_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::rbtree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::rbtree::value_comp()const + value_compare value_comp() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static set_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &set_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const set_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static set_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const set_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &set_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the set. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two sets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(set_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::rbtree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::rbtree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::rbtree::swap + void swap(set_impl& other); + + //! @copydoc ::boost::intrusive::rbtree::clone_from template <class Cloner, class Disposer> - void clone_from(const set_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to inserts value into the set. - //! - //! <b>Returns</b>: If the value - //! is not already present inserts it and returns a pair containing the - //! iterator to the new value and true. If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const set_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::insert_unique(reference) std::pair<iterator, bool> insert(reference value) - { return tree_.insert_unique(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to to insert x into the set, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the - //! new element was inserted into the set. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique(value); } + + //! @copydoc ::boost::intrusive::rbtree::insert_unique(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_unique(hint, value); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the set, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the set. + { return tree_type::insert_unique(hint, value); } + + //! @copydoc ::boost::intrusive::rbtree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(key, key_value_comp, commit_data); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the set, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the set. + { return tree_type::insert_unique_check(key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::rbtree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const_iterator hint, const KeyType &key ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the set between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return tree_.insert_unique_commit(value, commit_data); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the set. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique_check(hint, key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::rbtree::insert_unique(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_unique(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate. "value" must not be equal to any - //! inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" or "value" is not unique tree ordering and uniqueness - //! invariants will be broken respectively. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be greater than - //! any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than or equal to the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be less - //! than any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than or equal to the the mimum inserted key tree ordering or uniqueness - //! invariants will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size()) + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_unique(b, e); } + + //! @copydoc ::boost::intrusive::rbtree::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::rbtree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::rbtree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::rbtree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::clear + void clear(); + + //! @copydoc ::boost::intrusive::rbtree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + void clear_and_dispose(Disposer disposer); + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::count(const_reference)const size_type count(const_reference value) const - { return tree_.find(value) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + { return static_cast<size_type>(this->tree_type::find(value) != this->tree_type::cend()); } + + //! @copydoc ::boost::intrusive::rbtree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp) != end(); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + { return this->tree_type::lower_bound_range(key, comp); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + { return this->tree_type::lower_bound_range(key, comp); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a set/multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const set_impl &x, const set_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::rbtree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const set_impl &x, const set_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::rbtree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::rbtree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::rbtree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::rbtree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::rbtree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y) -#else -(const set_impl<Config> &x, const set_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const set_impl<T, Options...> &x, const set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y) -#else -(const set_impl<Config> &x, const set_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y) -#else -(const set_impl<Config> &x, const set_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y) -#else -(const set_impl<Config> &x, const set_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(set_impl<T, Options...> &x, set_impl<T, Options...> &y) -#else -(set_impl<Config> &x, set_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(set_impl<T, Options...> &x, set_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c set that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_set { /// @cond - typedef set_impl - < typename make_rbtree_opt<T, + typedef typename pack_options + < rbtree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif - >::type - > implementation_defined; + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef set_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class set : public make_set<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1275,7 +450,7 @@ class set typedef typename make_set <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1291,8 +466,8 @@ class set //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - set( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit set( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1308,7 +483,7 @@ class set {} set& operator=(BOOST_RV_REF(set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static set &container_from_end_iterator(iterator end_iterator) { return static_cast<set &>(Base::container_from_end_iterator(end_iterator)); } @@ -1339,12 +514,15 @@ class set #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> +#endif { /// @cond - typedef rbtree_impl<Config> tree_type; + typedef bstree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, RbTreeAlgorithms, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(multiset_impl) typedef tree_type implementation_defined; @@ -1372,1107 +550,325 @@ class multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - //static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; - - /// @cond - private: - tree_type tree_; - - protected: - node &prot_header_node(){ return tree_.prot_header_node(); } - node const &prot_header_node() const{ return tree_.prot_header_node(); } - void prot_set_size(size_type s){ tree_.prot_set_size(s); } - value_compare &prot_comp(){ return tree_.prot_comp(); } - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. - multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::rbtree::rbtree(const value_compare &,const value_traits &) + explicit multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty multiset and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::rbtree::rbtree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> multiset_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(false, b, e, cmp, v_traits) + : tree_type(false, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::rbtree::rbtree(rbtree &&) multiset_impl(BOOST_RV_REF(multiset_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::rbtree::operator=(rbtree &&) multiset_impl& operator=(BOOST_RV_REF(multiset_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~multiset_impl() - {} + { return static_cast<multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::rbtree::~rbtree() + ~multiset_impl(); + + //! @copydoc ::boost::intrusive::rbtree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::rbtree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::rbtree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::rbtree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::rbtree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::rbtree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::rbtree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::rbtree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::rbtree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::rbtree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::rbtree::container_from_end_iterator(iterator) + static multiset_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::rbtree::container_from_end_iterator(const_iterator) + static const multiset_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::rbtree::container_from_iterator(iterator) + static multiset_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::rbtree::container_from_iterator(const_iterator) + static const multiset_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::rbtree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::rbtree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::rbtree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::rbtree::size()const + size_type size() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static multiset_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &multiset_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const multiset_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static multiset_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const multiset_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &multiset_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the multiset. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two multisets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(multiset_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::rbtree::swap + void swap(multiset_impl& other); + + //! @copydoc ::boost::intrusive::rbtree::clone_from template <class Cloner, class Disposer> - void clone_from(const multiset_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const multiset_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::insert_equal(reference) iterator insert(reference value) - { return tree_.insert_equal(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts x into the multiset, using pos as a hint to - //! where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(value); } + + //! @copydoc ::boost::intrusive::rbtree::insert_equal(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_equal(hint, value); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(hint, value); } + + //! @copydoc ::boost::intrusive::rbtree::insert_equal(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_equal(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" tree ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::rbtree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::rbtree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::rbtree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::rbtree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::clear + void clear(); + + //! @copydoc ::boost::intrusive::rbtree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) const - { return tree_.count(value); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::rbtree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.count(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::rbtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a set/multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Effects</b>: removes "value" from the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic time. - //! - //! <b>Note</b>: This static function is only usable with non-constant - //! time size containers that have stateless comparison functors. - //! - //! If the user calls - //! this function with a constant time size container or stateful comparison - //! functor a compilation error will be issued. - static void remove_node(reference value) - { tree_type::remove_node(value); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const multiset_impl &x, const multiset_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::rbtree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const multiset_impl &x, const multiset_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::rbtree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::rbtree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::rbtree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::rbtree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::rbtree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::rbtree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::rbtree::remove_node + void remove_node(reference value); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y) -#else -(const multiset_impl<Config> &x, const multiset_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y) -#else -(const multiset_impl<Config> &x, const multiset_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y) -#else -(const multiset_impl<Config> &x, const multiset_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y) -#else -(const multiset_impl<Config> &x, const multiset_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(multiset_impl<T, Options...> &x, multiset_impl<T, Options...> &y) -#else -(multiset_impl<Config> &x, multiset_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(multiset_impl<T, Options...> &x, multiset_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c multiset that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_multiset { /// @cond - typedef multiset_impl - < typename make_rbtree_opt<T, + typedef typename pack_options + < rbtree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif - >::type - > implementation_defined; + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef multiset_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -2480,14 +876,14 @@ struct make_multiset #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class multiset : public make_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -2495,7 +891,7 @@ class multiset { typedef typename make_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -2529,7 +925,7 @@ class multiset {} multiset& operator=(BOOST_RV_REF(multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static multiset &container_from_end_iterator(iterator end_iterator) { return static_cast<multiset &>(Base::container_from_end_iterator(end_iterator)); } diff --git a/boost/intrusive/set_hook.hpp b/boost/intrusive/set_hook.hpp index 2634b42eef..ce984a305e 100644 --- a/boost/intrusive/set_hook.hpp +++ b/boost/intrusive/set_hook.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,9 +14,13 @@ #ifndef BOOST_INTRUSIVE_SET_HOOK_HPP #define BOOST_INTRUSIVE_SET_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/detail/rbtree_node.hpp> #include <boost/intrusive/rbtree_algorithms.hpp> #include <boost/intrusive/options.hpp> @@ -25,20 +29,12 @@ namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer, bool OptimizeSize = false> -struct get_set_node_algo -{ - typedef rbtree_algorithms<rbtree_node_traits<VoidPointer, OptimizeSize> > type; -}; -/// @endcond - //! Helper metafunction to define a \c set_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_set_base_hook { @@ -52,12 +48,11 @@ struct make_set_base_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_set_node_algo<typename packed_options::void_pointer - ,packed_options::optimize_size> + typedef generic_hook + < rbtree_algorithms<rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> > , typename packed_options::tag , packed_options::link_mode - , detail::SetBaseHook + , RbTreeBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -76,7 +71,7 @@ struct make_set_base_hook //! unique tag. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). @@ -170,7 +165,7 @@ class set_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_set_member_hook { @@ -184,12 +179,11 @@ struct make_set_member_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_set_node_algo<typename packed_options::void_pointer - ,packed_options::optimize_size> + typedef generic_hook + < rbtree_algorithms<rbtree_node_traits<typename packed_options::void_pointer, packed_options::optimize_size> > , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -203,7 +197,7 @@ struct make_set_member_hook //! \c link_mode<> and \c optimize_size<>. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). diff --git a/boost/intrusive/sg_set.hpp b/boost/intrusive/sg_set.hpp index 9b020cc221..6c1477ad3f 100644 --- a/boost/intrusive/sg_set.hpp +++ b/boost/intrusive/sg_set.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,18 +12,22 @@ #ifndef BOOST_INTRUSIVE_SG_SET_HPP #define BOOST_INTRUSIVE_SG_SET_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/sgtree.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/move/move.hpp> -#include <iterator> +#include <boost/intrusive/sgtree.hpp> +#include <boost/static_assert.hpp> +#include <boost/move/utility_core.hpp> namespace boost { namespace intrusive { //! The class template sg_set is an intrusive container, that mimics most of -//! the interface of std::set as described in the C++ standard. +//! the interface of std::sg_set as described in the C++ standard. //! //! The template parameter \c T is the type to be managed by the container. //! The user can specify additional options and if no options are provided @@ -31,19 +35,20 @@ namespace intrusive { //! //! The container supports the following options: //! \c base_hook<>/member_hook<>/value_traits<>, -//! \c constant_time_size<>, \c size_type<> and +//! \c floating_point<>, \c size_type<> and //! \c compare<>. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool FloatingPoint, typename HeaderHolder> #endif class sg_set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public sgtree_impl<ValueTraits, Compare, SizeType, FloatingPoint, HeaderHolder> +#endif { /// @cond - typedef sgtree_impl<Config> tree_type; - //! This class is - //! movable + typedef sgtree_impl<ValueTraits, Compare, SizeType, FloatingPoint, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_set_impl) typedef tree_type implementation_defined; @@ -71,1248 +76,398 @@ class sg_set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare object throws. - sg_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::sgtree::sgtree(const value_compare &,const value_traits &) + explicit sg_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty sg_set and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is std::distance(last, first). - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::sgtree::sgtree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> sg_set_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(true, b, e, cmp, v_traits) + : tree_type(true, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::sgtree::sgtree(sgtree &&) sg_set_impl(BOOST_RV_REF(sg_set_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::sgtree::operator=(sgtree &&) sg_set_impl& operator=(BOOST_RV_REF(sg_set_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~sg_set_impl() - {} + { return static_cast<sg_set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::sgtree::~sgtree() + ~sg_set_impl(); + + //! @copydoc ::boost::intrusive::sgtree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::sgtree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::sgtree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::sgtree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::sgtree::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of sg_set. - //! - //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static sg_set_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<sg_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &sg_set_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of sg_set. - //! - //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const sg_set_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<sg_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &sg_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static sg_set_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<sg_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &sg_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const sg_set_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<sg_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &sg_set_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the sg_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the sg_set. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two sets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(sg_set_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::sgtree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::sgtree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::sgtree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::sgtree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(iterator) + static sg_set_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(const_iterator) + static const sg_set_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(iterator) + static sg_set_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(const_iterator) + static const sg_set_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::sgtree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::sgtree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::sgtree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::sgtree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::sgtree::swap + void swap(sg_set_impl& other); + + //! @copydoc ::boost::intrusive::sgtree::clone_from template <class Cloner, class Disposer> - void clone_from(const sg_set_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to inserts value into the sg_set. - //! - //! <b>Returns</b>: If the value - //! is not already present inserts it and returns a pair containing the - //! iterator to the new value and true. If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const sg_set_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::sgtree::insert_unique(reference) std::pair<iterator, bool> insert(reference value) - { return tree_.insert_unique(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to to insert x into the sg_set, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the - //! new element was inserted into the sg_set. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique(value); } + + //! @copydoc ::boost::intrusive::sgtree::insert_unique(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_unique(hint, value); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the sg_set. + { return tree_type::insert_unique(hint, value); } + + //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(key, key_value_comp, commit_data); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the sg_set. + { return tree_type::insert_unique_check(key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::sgtree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const_iterator hint, const KeyType &key ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the sg_set between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the sg_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return tree_.insert_unique_commit(value, commit_data); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the sg_set. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique_check(hint, key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::sgtree::insert_unique(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_unique(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate. "value" must not be equal to any - //! inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" or "value" is not unique tree ordering and uniqueness - //! invariants will be broken respectively. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be greater than - //! any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than or equal to the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be less - //! than any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than or equal to the the mimum inserted key tree ordering or uniqueness - //! invariants will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size()) + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_unique(b, e); } + + //! @copydoc ::boost::intrusive::sgtree::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::sgtree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::sgtree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::sgtree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::clear + void clear(); + + //! @copydoc ::boost::intrusive::sgtree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + void clear_and_dispose(Disposer disposer); + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::sgtree::count(const_reference)const size_type count(const_reference value) const - { return tree_.find(value) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + { return static_cast<size_type>(this->tree_type::find(value) != this->tree_type::cend()); } + + //! @copydoc ::boost::intrusive::sgtree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp) != end(); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + { return this->tree_type::lower_bound_range(key, comp); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + { return this->tree_type::lower_bound_range(key, comp); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! sg_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! sg_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a sg_set/sg_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } - - //! <b>Returns</b>: The balance factor (alpha) used in this tree - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - float balance_factor() const - { return tree_.balance_factor(); } - - //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0 - //! - //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances - //! the tree if the new balance factor is stricter (less) than the old factor. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - void balance_factor(float new_alpha) - { tree_.balance_factor(new_alpha); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const sg_set_impl &x, const sg_set_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const sg_set_impl &x, const sg_set_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::sgtree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::sgtree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::sgtree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::sgtree::remove_node + void remove_node(reference value); + + //! @copydoc ::boost::intrusive::sgtree::rebalance + void rebalance(); + + //! @copydoc ::boost::intrusive::sgtree::rebalance_subtree + iterator rebalance_subtree(iterator root); + + //! @copydoc ::boost::intrusive::sgtree::balance_factor() + float balance_factor() const; + + //! @copydoc ::boost::intrusive::sgtree::balance_factor(float) + void balance_factor(float new_alpha); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y) -#else -(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y) -#else -(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y) -#else -(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y) -#else -(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y) -#else -(sg_set_impl<Config> &x, sg_set_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c sg_set that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_sg_set { /// @cond - typedef sg_set_impl - < typename make_sgtree_opt<T, + typedef typename pack_options + < sgtree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif - >::type - > implementation_defined; + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef sg_set_impl + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::floating_point + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class sg_set : public make_sg_set<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type { typedef typename make_sg_set <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type Base; - BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_set) + BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_set) public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; @@ -1322,8 +477,8 @@ class sg_set //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - sg_set( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit sg_set( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1339,7 +494,7 @@ class sg_set {} sg_set& operator=(BOOST_RV_REF(sg_set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<sg_set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static sg_set &container_from_end_iterator(iterator end_iterator) { return static_cast<sg_set &>(Base::container_from_end_iterator(end_iterator)); } @@ -1365,19 +520,21 @@ class sg_set //! //! The container supports the following options: //! \c base_hook<>/member_hook<>/value_traits<>, -//! \c constant_time_size<>, \c size_type<> and +//! \c floating_point<>, \c size_type<> and //! \c compare<>. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool FloatingPoint, typename HeaderHolder> #endif class sg_multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public sgtree_impl<ValueTraits, Compare, SizeType, FloatingPoint, HeaderHolder> +#endif { /// @cond - typedef sgtree_impl<Config> tree_type; + typedef sgtree_impl<ValueTraits, Compare, SizeType, FloatingPoint, HeaderHolder> tree_type; - //Non-copyable and non-assignable BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_multiset_impl) typedef tree_type implementation_defined; /// @endcond @@ -1404,1122 +561,338 @@ class sg_multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. - sg_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::sgtree::sgtree(const value_compare &,const value_traits &) + explicit sg_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty sg_multiset and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::sgtree::sgtree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> sg_multiset_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(false, b, e, cmp, v_traits) + : tree_type(false, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::sgtree::sgtree(sgtree &&) sg_multiset_impl(BOOST_RV_REF(sg_multiset_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::sgtree::operator=(sgtree &&) sg_multiset_impl& operator=(BOOST_RV_REF(sg_multiset_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_multiset - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~sg_multiset_impl() - {} + { return static_cast<sg_multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::sgtree::~sgtree() + ~sg_multiset_impl(); + + //! @copydoc ::boost::intrusive::sgtree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::sgtree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::sgtree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::sgtree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::sgtree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::sgtree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::sgtree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::sgtree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::sgtree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::sgtree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(iterator) + static sg_multiset_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::sgtree::container_from_end_iterator(const_iterator) + static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(iterator) + static sg_multiset_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::sgtree::container_from_iterator(const_iterator) + static const sg_multiset_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::sgtree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::sgtree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::sgtree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::sgtree::size()const + size_type size() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of sg_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static sg_multiset_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<sg_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &sg_multiset_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of sg_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<sg_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &sg_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static sg_multiset_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<sg_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &sg_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const sg_multiset_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<sg_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &sg_multiset_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the sg_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the sg_multiset. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two sg_multisets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(sg_multiset_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::sgtree::swap + void swap(sg_multiset_impl& other); + + //! @copydoc ::boost::intrusive::sgtree::clone_from template <class Cloner, class Disposer> - void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the sg_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::sgtree::insert_equal(reference) iterator insert(reference value) - { return tree_.insert_equal(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts x into the sg_multiset, using pos as a hint to - //! where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(value); } + + //! @copydoc ::boost::intrusive::sgtree::insert_equal(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_equal(hint, value); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the sg_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(hint, value); } + + //! @copydoc ::boost::intrusive::sgtree::insert_equal(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_equal(b, e); } - - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" tree ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::sgtree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::sgtree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::sgtree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::sgtree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::clear + void clear(); + + //! @copydoc ::boost::intrusive::sgtree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) const - { return tree_.count(value); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::sgtree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.count(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::sgtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::sgtree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! sg_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! sg_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a sg_multiset/sg_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } - - //! <b>Returns</b>: The balance factor (alpha) used in this tree - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - float balance_factor() const - { return tree_.balance_factor(); } - - //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0 - //! - //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances - //! the tree if the new balance factor is stricter (less) than the old factor. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - void balance_factor(float new_alpha) - { tree_.balance_factor(new_alpha); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const sg_multiset_impl &x, const sg_multiset_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const sg_multiset_impl &x, const sg_multiset_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::sgtree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::sgtree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::sgtree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::sgtree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::sgtree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::sgtree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::sgtree::remove_node + void remove_node(reference value); + + //! @copydoc ::boost::intrusive::sgtree::rebalance + void rebalance(); + + //! @copydoc ::boost::intrusive::sgtree::rebalance_subtree + iterator rebalance_subtree(iterator root); + + //! @copydoc ::boost::intrusive::sgtree::balance_factor() + float balance_factor() const; + + //! @copydoc ::boost::intrusive::sgtree::balance_factor(float) + void balance_factor(float new_alpha); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y) -#else -(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y) -#else -(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y) -#else -(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y) -#else -(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y) -#else -(sg_multiset_impl<Config> &x, sg_multiset_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c sg_multiset that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_sg_multiset { /// @cond + typedef typename pack_options + < sgtree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef sg_multiset_impl - < typename make_sgtree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::floating_point + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -2527,27 +900,27 @@ struct make_sg_multiset #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class sg_multiset : public make_sg_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type { - typedef typename make_sg_multiset - <T, + typedef typename make_sg_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type Base; + BOOST_MOVABLE_BUT_NOT_COPYABLE(sg_multiset) public: @@ -2576,7 +949,7 @@ class sg_multiset {} sg_multiset& operator=(BOOST_RV_REF(sg_multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<sg_multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static sg_multiset &container_from_end_iterator(iterator end_iterator) { return static_cast<sg_multiset &>(Base::container_from_end_iterator(end_iterator)); } diff --git a/boost/intrusive/sgtree.hpp b/boost/intrusive/sgtree.hpp index f181f54005..5df70f84b5 100644 --- a/boost/intrusive/sgtree.hpp +++ b/boost/intrusive/sgtree.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -18,28 +18,31 @@ #ifndef BOOST_INTRUSIVE_SGTREE_HPP #define BOOST_INTRUSIVE_SGTREE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <algorithm> #include <cstddef> #include <functional> -#include <iterator> #include <utility> #include <cmath> #include <cstddef> #include <boost/intrusive/detail/assert.hpp> #include <boost/static_assert.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/bs_set_hook.hpp> +#include <boost/intrusive/bstree.hpp> #include <boost/intrusive/detail/tree_node.hpp> -#include <boost/intrusive/detail/ebo_functor_holder.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/options.hpp> +#include <boost/intrusive/detail/math.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> #include <boost/intrusive/sgtree_algorithms.hpp> +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/move/move.hpp> +#include <boost/move/utility_core.hpp> namespace boost { namespace intrusive { @@ -48,6 +51,12 @@ namespace intrusive { namespace detail{ +///////////////////////////////////////////////////////////// +// +// Halpha for fixed floating_point<false> option +// +///////////////////////////////////////////////////////////// + //! Returns floor(log2(n)/log2(sqrt(2))) -> floor(2*log2(n)) //! Undefined if N is 0. //! @@ -55,7 +64,7 @@ namespace detail{ inline std::size_t calculate_h_sqrt2 (std::size_t n) { std::size_t f_log2 = detail::floor_log2(n); - return (2*f_log2) + (n >= detail::sqrt2_pow_2xplus1 (f_log2)); + return (2*f_log2) + static_cast<std::size_t>(n >= detail::sqrt2_pow_2xplus1(f_log2)); } struct h_alpha_sqrt2_t @@ -68,6 +77,7 @@ struct h_alpha_sqrt2_t struct alpha_0_75_by_max_size_t { alpha_0_75_by_max_size_t(void){} + std::size_t operator()(std::size_t max_tree_size) const { const std::size_t max_tree_size_limit = ((~std::size_t(0))/std::size_t(3)); @@ -75,17 +85,26 @@ struct alpha_0_75_by_max_size_t } }; +///////////////////////////////////////////////////////////// +// +// Halpha for fixed floating_point<true> option +// +///////////////////////////////////////////////////////////// + struct h_alpha_t { - h_alpha_t(float inv_minus_logalpha) + explicit h_alpha_t(float inv_minus_logalpha) : inv_minus_logalpha_(inv_minus_logalpha) {} std::size_t operator()(std::size_t n) const { - //Returns floor(log2(1/alpha(n))) -> - // floor(log2(n)/log(1/alpha)) -> - // floor(log2(n)/(-log2(alpha))) + //////////////////////////////////////////////////////////// + // This function must return "floor(log2(1/alpha(n)))" -> + // floor(log2(n)/log(1/alpha)) -> + // floor(log2(n)/-log2(alpha)) + // floor(log2(n)*(1/-log2(alpha))) + //////////////////////////////////////////////////////////// //return static_cast<std::size_t>(std::log(float(n))*inv_minus_logalpha_); return static_cast<std::size_t>(detail::fast_log2(float(n))*inv_minus_logalpha_); } @@ -94,13 +113,13 @@ struct h_alpha_t //Since the function will be repeatedly called //precalculate constant data to avoid repeated //calls to log and division. - //This will store 1/(-std::log(alpha_)) + //This will store 1/(-std::log2(alpha_)) float inv_minus_logalpha_; }; struct alpha_by_max_size_t { - alpha_by_max_size_t(float alpha) + explicit alpha_by_max_size_t(float alpha) : alpha_(alpha) {} @@ -109,17 +128,17 @@ struct alpha_by_max_size_t private: float alpha_; - float inv_minus_logalpha_; }; -template<bool Activate> +template<bool Activate, class SizeType> struct alpha_holder { typedef boost::intrusive::detail::h_alpha_t h_alpha_t; typedef boost::intrusive::detail::alpha_by_max_size_t multiply_by_alpha_t; alpha_holder() - { set_alpha(0.7f); } + : max_tree_size_() + { set_alpha(0.70711f); } // ~1/sqrt(2) float get_alpha() const { return alpha_; } @@ -131,18 +150,19 @@ struct alpha_holder } h_alpha_t get_h_alpha_t() const - { return h_alpha_t(inv_minus_logalpha_); } + { return h_alpha_t(/*alpha_, */inv_minus_logalpha_); } multiply_by_alpha_t get_multiply_by_alpha_t() const { return multiply_by_alpha_t(alpha_); } - private: + protected: float alpha_; float inv_minus_logalpha_; + SizeType max_tree_size_; }; -template<> -struct alpha_holder<false> +template<class SizeType> +struct alpha_holder<false, SizeType> { //This specialization uses alpha = 1/sqrt(2) //without using floating point operations @@ -150,6 +170,10 @@ struct alpha_holder<false> typedef boost::intrusive::detail::h_alpha_sqrt2_t h_alpha_t; typedef boost::intrusive::detail::alpha_0_75_by_max_size_t multiply_by_alpha_t; + alpha_holder() + : max_tree_size_() + {} + float get_alpha() const { return 0.70710677f; } @@ -163,30 +187,22 @@ struct alpha_holder<false> multiply_by_alpha_t get_multiply_by_alpha_t() const { return multiply_by_alpha_t(); } + + SizeType max_tree_size_; }; } //namespace detail{ -template <class ValueTraits, class Compare, class SizeType, bool FloatingPoint> -struct sg_setopt +struct sgtree_defaults { - typedef ValueTraits value_traits; - typedef Compare compare; - typedef SizeType size_type; - static const bool floating_point = FloatingPoint; + typedef default_bstree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + static const bool floating_point = true; + typedef void header_holder_type; }; -template <class T> -struct sg_set_defaults - : pack_options - < none - , base_hook<detail::default_bs_set_hook> - , floating_point<true> - , size_type<std::size_t> - , compare<std::less<T> > - >::type -{}; - /// @endcond //! The class template sgtree is an intrusive scapegoat tree container, that @@ -205,786 +221,367 @@ struct sg_set_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool FloatingPoint, typename HeaderHolder> #endif class sgtree_impl - : private detail::clear_on_destructor_base<sgtree_impl<Config> > + /// @cond + : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, true, SgTreeAlgorithms, HeaderHolder> + , public detail::alpha_holder<FloatingPoint, SizeType> + /// @endcond { - template<class C> friend class detail::clear_on_destructor_base; public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; + typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType + , true, SgTreeAlgorithms, HeaderHolder> tree_type; + typedef tree_type implementation_defined; + /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - typedef typename pointer_traits<pointer>::element_type value_type; - typedef value_type key_type; - typedef typename pointer_traits<pointer>::reference reference; - typedef typename pointer_traits<const_pointer>::reference const_reference; - typedef typename pointer_traits<const_pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef typename Config::compare value_compare; - typedef value_compare key_compare; - typedef tree_iterator<sgtree_impl, false> iterator; - typedef tree_iterator<sgtree_impl, true> const_iterator; - typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; - typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <const node>::type const_node_ptr; - typedef sgtree_algorithms<node_traits> node_algorithms; - - static const bool floating_point = Config::floating_point; - static const bool constant_time_size = true; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::key_type key_type; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef BOOST_INTRUSIVE_IMPDEF(sgtree_algorithms<node_traits>) node_algorithms; + + static const bool constant_time_size = implementation_defined::constant_time_size; + static const bool floating_point = FloatingPoint; + static const bool stateful_value_traits = implementation_defined::stateful_value_traits; /// @cond private: - typedef detail::size_holder<true, size_type> size_traits; - typedef detail::alpha_holder<floating_point> alpha_traits; - typedef typename alpha_traits::h_alpha_t h_alpha_t; - typedef typename alpha_traits::multiply_by_alpha_t multiply_by_alpha_t; //noncopyable + typedef detail::alpha_holder<FloatingPoint, SizeType> alpha_traits; + typedef typename alpha_traits::h_alpha_t h_alpha_t; + typedef typename alpha_traits::multiply_by_alpha_t multiply_by_alpha_t; + BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree_impl) + BOOST_STATIC_ASSERT(((int)value_traits::link_mode != (int)auto_unlink)); enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; - - BOOST_STATIC_ASSERT(((int)real_value_traits::link_mode != (int)auto_unlink)); - - //BOOST_STATIC_ASSERT(( - // (int)real_value_traits::link_mode != (int)auto_unlink || - // !floating_point - // )); - - struct header_plus_alpha : public alpha_traits - { node header_; }; - - struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare> - { - node_plus_pred_t(const value_compare &comp) - : detail::ebo_functor_holder<value_compare>(comp) - {} - header_plus_alpha header_plus_alpha_; - size_traits size_traits_; - }; - - struct data_t : public sgtree_impl::value_traits - { - typedef typename sgtree_impl::value_traits value_traits; - data_t(const value_compare & comp, const value_traits &val_traits) - : value_traits(val_traits), node_plus_pred_(comp) - , max_tree_size_(0) - {} - node_plus_pred_t node_plus_pred_; - size_type max_tree_size_; - } data_; - - float priv_alpha() const - { return this->priv_alpha_traits().get_alpha(); } - - void priv_alpha(float alpha) - { return this->priv_alpha_traits().set_alpha(alpha); } - - const value_compare &priv_comp() const - { return data_.node_plus_pred_.get(); } - - value_compare &priv_comp() - { return data_.node_plus_pred_.get(); } - - const value_traits &priv_value_traits() const - { return data_; } - - value_traits &priv_value_traits() - { return data_; } - - node_ptr priv_header_ptr() - { return pointer_traits<node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_alpha_.header_); } - - const_node_ptr priv_header_ptr() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_alpha_.header_); } - - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - - size_traits &priv_size_traits() - { return data_.node_plus_pred_.size_traits_; } - - const size_traits &priv_size_traits() const - { return data_.node_plus_pred_.size_traits_; } - - alpha_traits &priv_alpha_traits() - { return data_.node_plus_pred_.header_plus_alpha_; } - - const alpha_traits &priv_alpha_traits() const - { return data_.node_plus_pred_.header_plus_alpha_; } - - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } - - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } - - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } - - h_alpha_t get_h_alpha_func() const - { return priv_alpha_traits().get_h_alpha_t(); } - - multiply_by_alpha_t get_alpha_by_max_size_func() const - { return priv_alpha_traits().get_multiply_by_alpha_t(); } + (int)value_traits::link_mode == (int)auto_unlink || + (int)value_traits::link_mode == (int)safe_link }; /// @endcond public: - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } + typedef BOOST_INTRUSIVE_IMPDEF(typename node_algorithms::insert_commit_data) insert_commit_data; - typedef typename node_algorithms::insert_commit_data insert_commit_data; - - //! <b>Effects</b>: Constructs an empty tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructorof the value_compare object throws. Basic guarantee. - sgtree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - } + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit sgtree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty tree and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee. + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> sgtree_impl( bool unique, Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) + : tree_type(cmp, v_traits) { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); if(unique) this->insert_unique(b, e); else this->insert_equal(b, e); } - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) sgtree_impl(BOOST_RV_REF(sgtree_impl) x) - : data_(::boost::move(x.priv_comp()), ::boost::move(x.priv_value_traits())) + : tree_type(::boost::move(static_cast<tree_type&>(x))), alpha_traits(x.get_alpha_traits()) + { std::swap(this->get_alpha_traits(), x.get_alpha_traits()); } + + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) + sgtree_impl& operator=(BOOST_RV_REF(sgtree_impl) x) { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - this->swap(x); + this->get_alpha_traits() = x.get_alpha_traits(); + return static_cast<sgtree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - //! <b>Effects</b>: to-do - //! - sgtree_impl& operator=(BOOST_RV_REF(sgtree_impl) x) - { this->swap(x); return *this; } + /// @cond + private: - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called), but the nodes according to - //! the value_traits template parameter are reinitialized and thus can be reused. - //! - //! <b>Complexity</b>: Linear to elements contained in *this. - //! - //! <b>Throws</b>: Nothing. - ~sgtree_impl() - {} + const alpha_traits &get_alpha_traits() const + { return *this; } - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return iterator (node_traits::get_left(this->priv_header_ptr()), this); } + alpha_traits &get_alpha_traits() + { return *this; } - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return cbegin(); } + h_alpha_t get_h_alpha_func() const + { return this->get_alpha_traits().get_h_alpha_t(); } - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return const_iterator (node_traits::get_left(this->priv_header_ptr()), this); } + multiply_by_alpha_t get_alpha_by_max_size_func() const + { return this->get_alpha_traits().get_multiply_by_alpha_t(); } - //! <b>Effects</b>: Returns an iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return iterator (this->priv_header_ptr(), this); } + /// @endcond - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return cend(); } + public: - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return const_iterator (uncast(this->priv_header_ptr()), this); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~sgtree_impl(); - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return const_reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return const_reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return const_reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return const_reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of sgtree. - //! - //! <b>Effects</b>: Returns a const reference to the sgtree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static sgtree_impl &container_from_end_iterator(iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of sgtree. - //! - //! <b>Effects</b>: Returns a const reference to the sgtree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; - //! <b>Precondition</b>: it must be a valid iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static sgtree_impl &container_from_iterator(iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; - //! <b>Precondition</b>: it must be a valid end const_iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const sgtree_impl &container_from_iterator(const_iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); - //! <b>Effects</b>: Returns the value_compare object used by the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return priv_comp(); } + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return node_algorithms::unique(this->priv_header_ptr()); } + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; - //! <b>Effects</b>: Returns the number of elements stored in the tree. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { - if(constant_time_size) - return this->priv_size_traits().get_size(); - else{ - return (size_type)node_algorithms::size(this->priv_header_ptr()); - } - } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static sgtree_impl &container_from_end_iterator(iterator end_iterator); - //! <b>Effects</b>: Swaps the contents of two sgtrees. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the comparison functor's swap call throws. + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static sgtree_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const sgtree_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree::swap void swap(sgtree_impl& other) { //This can throw using std::swap; - swap(priv_comp(), priv_comp()); - swap(priv_alpha_traits(), priv_alpha_traits()); - swap(data_.max_tree_size_, other.data_.max_tree_size_); - //These can't throw - node_algorithms::swap_tree(this->priv_header_ptr(), other.priv_header_ptr()); - if(constant_time_size){ - size_type backup = this->priv_size_traits().get_size(); - this->priv_size_traits().set_size(other.priv_size_traits().get_size()); - other.priv_size_traits().set_size(backup); - } + this->tree_type::swap(static_cast<tree_type&>(other)); + swap(this->get_alpha_traits(), other.get_alpha_traits()); } - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree before the upper bound. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::clone_from + //! Additional notes: it also copies the alpha factor from the source container. + template <class Cloner, class Disposer> + void clone_from(const sgtree_impl &src, Cloner cloner, Disposer disposer) + { + this->tree_type::clone_from(src, cloner, disposer); + this->get_alpha_traits() = src.get_alpha_traits(); + } + + //! @copydoc ::boost::intrusive::bstree::insert_equal(reference) iterator insert_equal(reference value) { - detail::key_nodeptr_comp<value_compare, sgtree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->value_comp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_ptr p = node_algorithms::insert_equal_upper_bound - (this->priv_header_ptr(), to_insert, key_node_comp + (this->tree_type::header_ptr(), to_insert, key_node_comp , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; - return iterator(p, this); + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; + return iterator(p, this->priv_value_traits_ptr()); } - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator. - //! - //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case) - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference) iterator insert_equal(const_iterator hint, reference value) { - detail::key_nodeptr_comp<value_compare, sgtree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->value_comp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_ptr p = node_algorithms::insert_equal - (this->priv_header_ptr(), hint.pointed_node(), to_insert, key_node_comp + (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; - return iterator(p, this); + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; + return iterator(p, this->priv_value_traits_ptr()); } - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a each element of a range into the tree - //! before the upper bound of the key of each element. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator) template<class Iterator> void insert_equal(Iterator b, Iterator e) { - iterator end(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end, *b); + this->insert_equal(iend, *b); } - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree if the value - //! is not already present. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_unique(reference) std::pair<iterator, bool> insert_unique(reference value) { insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), commit_data); + std::pair<iterator, bool> ret = insert_unique_check(value, this->value_comp(), commit_data); if(!ret.second) return ret; return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true); } - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator - //! - //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint - //! to where it will be inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time (two comparisons in the worst case) - //! if t is inserted immediately before hint. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference) iterator insert_unique(const_iterator hint, reference value) { insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), commit_data); + std::pair<iterator, bool> ret = insert_unique_check(hint, value, this->value_comp(), commit_data); if(!ret.second) return ret.first; return insert_unique_commit(value, commit_data); } - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Tries to insert each element of a range into the tree. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - template<class Iterator> - void insert_unique(Iterator b, Iterator e) - { - if(this->empty()){ - iterator end(this->end()); - for (; b != e; ++b) - this->insert_unique(end, *b); - } - else{ - for (; b != e; ++b) - this->insert_unique(*b); - } - } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - comp(key_value_comp, this); + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + comp(key_value_comp, &this->get_value_traits()); std::pair<node_ptr, bool> ret = (node_algorithms::insert_unique_check - (this->priv_header_ptr(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); + (this->tree_type::header_ptr(), key, comp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); } - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check (const_iterator hint, const KeyType &key ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - comp(key_value_comp, this); + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + comp(key_value_comp, &this->get_value_traits()); std::pair<node_ptr, bool> ret = (node_algorithms::insert_unique_check - (this->priv_header_ptr(), hint.pointed_node(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); + (this->tree_type::header_ptr(), hint.pointed_node(), key, comp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); } - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the container between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. + //! @copydoc ::boost::intrusive::bstree::insert_unique_commit iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_algorithms::insert_unique_commit - ( this->priv_header_ptr(), to_insert, commit_data + ( this->tree_type::header_ptr(), to_insert, commit_data , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; - return iterator(to_insert, this); + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; + return iterator(to_insert, this->priv_value_traits_ptr()); } - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the tree before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" tree ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. + //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator) + template<class Iterator> + void insert_unique(Iterator b, Iterator e) + { + if(this->empty()){ + iterator iend(this->end()); + for (; b != e; ++b) + this->insert_unique(iend, *b); + } + else{ + for (; b != e; ++b) + this->insert_unique(*b); + } + } + + //! @copydoc ::boost::intrusive::bstree::insert_before iterator insert_before(const_iterator pos, reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_ptr p = node_algorithms::insert_before - ( this->priv_header_ptr(), pos.pointed_node(), to_insert + ( this->tree_type::header_ptr(), pos.pointed_node(), to_insert , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; - return iterator(p, this); + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; + return iterator(p, this->priv_value_traits_ptr()); } - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. + //! @copydoc ::boost::intrusive::bstree::push_back void push_back(reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_algorithms::push_back - ( this->priv_header_ptr(), to_insert + ( this->tree_type::header_ptr(), to_insert , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; } - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the tree in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key tree ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. + //! @copydoc ::boost::intrusive::bstree::push_front void push_front(reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - std::size_t max_tree_size = (std::size_t)data_.max_tree_size_; + std::size_t max_tree_size = (std::size_t)this->max_tree_size_; node_algorithms::push_front - ( this->priv_header_ptr(), to_insert + ( this->tree_type::header_ptr(), to_insert , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size); - this->priv_size_traits().increment(); - data_.max_tree_size_ = (size_type)max_tree_size; + this->tree_type::sz_traits().increment(); + this->max_tree_size_ = (size_type)max_tree_size; } - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) iterator erase(const_iterator i) { const_iterator ret(i); @@ -992,53 +589,26 @@ class sgtree_impl node_ptr to_erase(i.pointed_node()); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); - std::size_t max_tree_size = data_.max_tree_size_; + std::size_t max_tree_size = this->max_tree_size_; node_algorithms::erase - ( this->priv_header_ptr(), to_erase, (std::size_t)this->size() + ( this->tree_type::header_ptr(), to_erase, (std::size_t)this->size() , max_tree_size, this->get_alpha_by_max_size_func()); - data_.max_tree_size_ = (size_type)max_tree_size; - this->priv_size_traits().decrement(); + this->max_tree_size_ = (size_type)max_tree_size; + this->tree_type::sz_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); return ret.unconst(); } - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) iterator erase(const_iterator b, const_iterator e) { size_type n; return private_erase(b, e, n); } - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) size_type erase(const_reference value) - { return this->erase(value, priv_comp()); } + { return this->erase(value, this->value_comp()); } - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> size_type erase(const KeyType& key, KeyValueCompare comp /// @cond @@ -1052,23 +622,13 @@ class sgtree_impl return n; } - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> iterator erase_and_dispose(const_iterator i, Disposer disposer) { node_ptr to_erase(i.pointed_node()); iterator ret(this->erase(i)); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(this->get_value_traits().to_value_ptr(to_erase)); return ret; } @@ -1078,35 +638,12 @@ class sgtree_impl { return this->erase_and_dispose(const_iterator(i), disposer); } #endif - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) { size_type n; return private_erase(b, e, n, disposer); } - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) template<class Disposer> size_type erase_and_dispose(const_reference value, Disposer disposer) { @@ -1116,20 +653,7 @@ class sgtree_impl return n; } - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer /// @cond @@ -1143,535 +667,136 @@ class sgtree_impl return n; } - //! <b>Effects</b>: Erases all of the elements. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::clear void clear() { - if(safemode_or_autounlink){ - this->clear_and_dispose(detail::null_disposer()); - } - else{ - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } + tree_type::clear(); + this->max_tree_size_ = 0; } - //! <b>Effects</b>: Erases all of the elements calling disposer(p) for - //! each node to be erased. - //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)), - //! where N is the number of elements in the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. Calls N times to disposer functor. + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose template<class Disposer> void clear_and_dispose(Disposer disposer) { - node_algorithms::clear_and_dispose(this->priv_header_ptr() - , detail::node_disposer<Disposer, sgtree_impl>(disposer, this)); - this->priv_size_traits().set_size(0); + tree_type::clear_and_dispose(disposer); + this->max_tree_size_ = 0; } - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count(const_reference value) const - { return this->count(value, priv_comp()); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const; - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType &key, KeyValueCompare comp) const - { - std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); - return std::distance(ret.first, ret.second); - } + size_type count(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator lower_bound(const_reference value) - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator lower_bound(const_reference value) const - { return this->lower_bound(value, priv_comp()); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + iterator lower_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator upper_bound(const_reference value) - { return this->upper_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + iterator upper_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator upper_bound(const_reference value) const - { return this->upper_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator find(const_reference value) - { return this->find(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } + iterator find(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator find(const_reference value) const - { return this->find(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - return const_iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } + const_iterator find(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<iterator,iterator> equal_range(const_reference value) - { return this->equal_range(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return this->equal_range(value, priv_comp()); } + equal_range(const_reference value) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + equal_range(const KeyType& key, KeyValueCompare comp) const; - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator,const_iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator,const_iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { - detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const sgtree_impl &src, Cloner cloner, Disposer disposer) - { - this->clear_and_dispose(disposer); - if(!src.empty()){ - detail::exception_disposer<sgtree_impl, Disposer> - rollback(*this, disposer); - node_algorithms::clone - (src.priv_header_ptr() - ,this->priv_header_ptr() - ,detail::node_cloner<Cloner, sgtree_impl>(cloner, this) - ,detail::node_disposer<Disposer, sgtree_impl>(disposer, this)); - this->priv_size_traits().set_size(src.priv_size_traits().get_size()); - this->priv_comp() = src.priv_comp(); - rollback.release(); - } - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { - node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance - (this->priv_header_ptr())); - if(!to_be_disposed) - return 0; - this->priv_size_traits().decrement(); - if(safemode_or_autounlink)//If this is commented does not work with normal_link - node_algorithms::init(to_be_disposed); - return get_real_value_traits().to_value_ptr(to_be_disposed); - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { - node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this) - , this->priv_header_ptr() - , get_real_value_traits().to_node_ptr(with_this)); - if(safemode_or_autounlink) - node_algorithms::init(replace_this.pointed_node()); - } + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return iterator (value_traits::to_node_ptr(value), 0); - } + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); - } + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return iterator (value_traits::to_node_ptr(value), this); } + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); } + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); - //! <b>Requires</b>: value shall not be in a tree. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { node_algorithms::init(value_traits::to_node_ptr(value)); } + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { node_algorithms::rebalance(this->priv_header_ptr()); } + //! @copydoc ::boost::intrusive::bstree::rebalance + void rebalance(); - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this); } + //! @copydoc ::boost::intrusive::bstree::rebalance_subtree + iterator rebalance_subtree(iterator root); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Returns</b>: The balance factor (alpha) used in this tree //! @@ -1679,7 +804,7 @@ class sgtree_impl //! //! <b>Complexity</b>: Constant. float balance_factor() const - { return this->priv_alpha(); } + { return this->get_alpha_traits().get_alpha(); } //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0 //! @@ -1697,41 +822,14 @@ class sgtree_impl //The alpha factor CAN't be changed if the fixed, floating operation-less //1/sqrt(2) alpha factor option is activated BOOST_STATIC_ASSERT((floating_point)); - float old_alpha = this->priv_alpha(); - this->priv_alpha(new_alpha); + float old_alpha = this->get_alpha_traits().get_alpha(); + this->get_alpha_traits().set_alpha(new_alpha); if(new_alpha < old_alpha){ - data_.max_tree_size_ = this->size(); + this->max_tree_size_ = this->size(); this->rebalance(); } } -/* - //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect, - //! if x is not in such a tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This static function is only usable with the "safe mode" - //! hook and non-constant time size lists. Otherwise, the user must use - //! the non-static "erase(reference )" member. If the user calls - //! this function with a non "safe mode" or constant time size list - //! a compilation error will be issued. - template<class T> - static void remove_node(T& value) - { - //This function is only usable for safe mode hooks and non-constant - //time lists. - //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size))); - BOOST_STATIC_ASSERT((!constant_time_size)); - BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value)); - node_ptr to_remove(value_traits::to_node_ptr(value)); - node_algorithms::unlink_and_rebalance(to_remove); - if(safemode_or_autounlink) - node_algorithms::init(to_remove); - } -*/ /// @cond private: @@ -1750,230 +848,110 @@ class sgtree_impl return b.unconst(); } /// @endcond - - private: - static sgtree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) - { - header_plus_alpha *r = detail::parent_from_member<header_plus_alpha, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &header_plus_alpha::header_); - node_plus_pred_t *n = detail::parent_from_member - <node_plus_pred_t, header_plus_alpha>(r, &node_plus_pred_t::header_plus_alpha_); - data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_); - sgtree_impl *scapegoat = detail::parent_from_member<sgtree_impl, data_t>(d, &sgtree_impl::data_); - return *scapegoat; - } - - static sgtree_impl &priv_container_from_iterator(const const_iterator &it) - { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator< -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -bool operator== -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ - typedef sgtree_impl<Config> tree_type; - typedef typename tree_type::const_iterator const_iterator; +bool operator< (const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); - if(tree_type::constant_time_size && x.size() != y.size()){ - return false; - } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } -} +template<class T, class ...Options> +bool operator==(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y) -#else -(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(sgtree_impl<T, Options...> &x, sgtree_impl<T, Options...> &y) -#else -(sgtree_impl<Config> &x, sgtree_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(sgtree_impl<T, Options...> &x, sgtree_impl<T, Options...> &y); -/// @cond -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#else +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +//! Helper metafunction to define a \c sgtree that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif -struct make_sgtree_opt +struct make_sgtree { + /// @cond typedef typename pack_options - < sg_set_defaults<T>, + < sgtree_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type packed_options; + typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; - typedef sg_setopt + typedef sgtree_impl < value_traits , typename packed_options::compare , typename packed_options::size_type , packed_options::floating_point - > type; -}; -/// @endcond - -//! Helper metafunction to define a \c sgtree that yields to the same type when the -//! same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class ...Options> -#else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#endif -struct make_sgtree -{ - /// @cond - typedef sgtree_impl - < typename make_sgtree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class sgtree : public make_sgtree<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type { typedef typename make_sgtree <T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type Base; - BOOST_MOVABLE_BUT_NOT_COPYABLE(sgtree) public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::reverse_iterator reverse_iterator; + typedef typename Base::const_reverse_iterator const_reverse_iterator; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - sgtree( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit sgtree( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1989,18 +967,23 @@ class sgtree {} sgtree& operator=(BOOST_RV_REF(sgtree) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<sgtree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static sgtree &container_from_end_iterator(iterator end_iterator) { return static_cast<sgtree &>(Base::container_from_end_iterator(end_iterator)); } static const sgtree &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const sgtree &>(Base::container_from_end_iterator(end_iterator)); } + + static sgtree &container_from_iterator(iterator it) + { return static_cast<sgtree &>(Base::container_from_iterator(it)); } + + static const sgtree &container_from_iterator(const_iterator it) + { return static_cast<const sgtree &>(Base::container_from_iterator(it)); } }; #endif - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/sgtree_algorithms.hpp b/boost/intrusive/sgtree_algorithms.hpp index bad1c325a0..cb5f71cffd 100644 --- a/boost/intrusive/sgtree_algorithms.hpp +++ b/boost/intrusive/sgtree_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -17,14 +17,17 @@ #ifndef BOOST_INTRUSIVE_SGTREE_ALGORITHMS_HPP #define BOOST_INTRUSIVE_SGTREE_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> -#include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> + namespace boost { @@ -36,7 +39,7 @@ namespace intrusive { //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the binary search tree //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -57,6 +60,9 @@ namespace intrusive { //! <tt>static void set_right(node_ptr n, node_ptr right);</tt> template<class NodeTraits> class sgtree_algorithms + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_algorithms<NodeTraits> + #endif { public: typedef typename NodeTraits::node node; @@ -67,611 +73,208 @@ class sgtree_algorithms /// @cond private: - typedef detail::tree_algorithms<NodeTraits> tree_algorithms; + typedef bstree_algorithms<NodeTraits> bstree_algo; - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } /// @endcond public: - static node_ptr begin_node(const const_node_ptr & header) - { return tree_algorithms::begin_node(header); } - - static node_ptr end_node(const const_node_ptr & header) - { return tree_algorithms::end_node(header); } - //! This type is the information that will be //! filled by insert_unique_check struct insert_commit_data - : tree_algorithms::insert_commit_data + : bstree_algo::insert_commit_data { std::size_t depth; }; - //! <b>Requires</b>: header1 and header2 must be the header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two trees. After the function header1 will contain - //! links to the second tree and header2 will have links to the first tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static void swap_tree(const node_ptr & header1, const node_ptr & header2) - { return tree_algorithms::swap_tree(header1, header2); } - - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & node2) - { - if(node1 == node2) - return; + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const const_node_ptr&) + static node_ptr get_header(const const_node_ptr & n); - node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2)); - swap_nodes(node1, header1, node2, header2); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::begin_node + static node_ptr begin_node(const const_node_ptr & header); - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees with header header1 and header2. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2) - { tree_algorithms::swap_nodes(node1, header1, node2, header2); } - - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) - { - if(node_to_be_replaced == new_node) - return; - replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::end_node + static node_ptr end_node(const const_node_ptr & header); - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! with header "header" and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) - { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); } - - //! <b>Requires</b>: node is a tree node but not the header. - //! - //! <b>Effects</b>: Unlinks the node and rebalances the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - static void unlink(const node_ptr & node) - { - node_ptr x = NodeTraits::get_parent(node); - if(x){ - while(!is_header(x)) - x = NodeTraits::get_parent(x); - tree_algorithms::erase(x, node); - } - } + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree + static void swap_tree(const node_ptr & header1, const node_ptr & header2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & node2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&,const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node); + + //Unlink is not possible since tree metadata is needed to update the tree + //!static void unlink(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance + static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header); - //! <b>Requires</b>: header is the header of a tree. - //! - //! <b>Effects</b>: Unlinks the leftmost node from the tree, and - //! updates the header link to the new leftmost node. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header) - { return tree_algorithms::unlink_leftmost_without_rebalance(header); } - - //! <b>Requires</b>: node is a node of the tree or an node initialized - //! by init(...). - //! - //! <b>Effects</b>: Returns true if the node is initialized by init(). - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - static bool unique(const const_node_ptr & node) - { return tree_algorithms::unique(node); } - - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & node) - { return tree_algorithms::count(node); } - - //! <b>Requires</b>: header is the header node of the tree. - //! - //! <b>Effects</b>: Returns the number of nodes above the header. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t size(const const_node_ptr & header) - { return tree_algorithms::size(header); } - - //! <b>Requires</b>: p is a node from the tree except the header. - //! - //! <b>Effects</b>: Returns the next node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr next_node(const node_ptr & p) - { return tree_algorithms::next_node(p); } - - //! <b>Requires</b>: p is a node from the tree except the leftmost node. - //! - //! <b>Effects</b>: Returns the previous node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr prev_node(const node_ptr & p) - { return tree_algorithms::prev_node(p); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: After the function unique(node) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init(const node_ptr & node) - { tree_algorithms::init(node); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: Initializes the header to represent an empty tree. - //! unique(header) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init_header(const node_ptr & header) - { tree_algorithms::init_header(header); } - - //! <b>Requires</b>: header must be the header of a tree, z a node - //! of that tree and z != header. - //! - //! <b>Effects</b>: Erases node "z" from the tree with header "header". - //! - //! <b>Complexity</b>: Amortized constant time. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree_algorithms::unique(const const_node_ptr&) + static bool unique(const const_node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::size(const const_node_ptr&) + static std::size_t size(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::next_node(const node_ptr&) + static node_ptr next_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(const node_ptr&) + static node_ptr prev_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::init(const node_ptr&) + static void init(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::init_header(const node_ptr&) + static void init_header(const node_ptr & header); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::erase(const node_ptr&,const node_ptr&) template<class AlphaByMaxSize> static node_ptr erase(const node_ptr & header, const node_ptr & z, std::size_t tree_size, std::size_t &max_tree_size, AlphaByMaxSize alpha_by_maxsize) { - //typename tree_algorithms::data_for_rebalance info; - tree_algorithms::erase(header, z); + //typename bstree_algo::data_for_rebalance info; + bstree_algo::erase(header, z); --tree_size; if (tree_size > 0 && tree_size < alpha_by_maxsize(max_tree_size)){ - tree_algorithms::rebalance(header); + bstree_algo::rebalance(header); max_tree_size = tree_size; } return z; } - //! <b>Requires</b>: "cloner" must be a function - //! object taking a node_ptr and returning a new cloned node of it. "disposer" must - //! take a node_ptr and shouldn't throw. - //! - //! <b>Effects</b>: First empties target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! Then, duplicates the entire tree pointed by "source_header" cloning each - //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain - //! the nodes of the target tree. If "cloner" throws, the cloned target nodes - //! are disposed using <tt>void disposer(const node_ptr &)</tt>. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::clone(const const_node_ptr&,const node_ptr&,Cloner,Disposer) template <class Cloner, class Disposer> static void clone - (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer) - { - tree_algorithms::clone(source_header, target_header, cloner, disposer); - } + (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer); - //! <b>Requires</b>: "disposer" must be an object function - //! taking a node_ptr parameter and shouldn't throw. - //! - //! <b>Effects</b>: Empties the target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + //! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(const node_ptr&,Disposer) template<class Disposer> - static void clear_and_dispose(const node_ptr & header, Disposer disposer) - { tree_algorithms::clear_and_dispose(header, disposer); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is - //! not less than "key" according to "comp" or "header" if that element does - //! not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + static void clear_and_dispose(const node_ptr & header, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr lower_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::lower_bound(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater - //! than "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr upper_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::upper_bound(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to - //! "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&, const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr find - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::find(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing - //! all elements that are equivalent to "key" according to "comp" or an - //! empty range that indicates the position where those elements would be - //! if they there are no equivalent elements. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> equal_range - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::equal_range(header, key, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp - , bool left_closed, bool right_closed) - { return tree_algorithms::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the upper bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + , bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + template<class KeyType, class KeyNodePtrCompare> + static std::size_t count(const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_upper_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare, class H_Alpha> static node_ptr insert_equal_upper_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::insert_equal_upper_bound(h, new_node, comp, &depth); + bstree_algo::insert_equal_upper_bound(h, new_node, comp, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); return new_node; } - //! <b>Requires</b>: "h" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the lower bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_lower_bound(const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare, class H_Alpha> static node_ptr insert_equal_lower_bound (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::insert_equal_lower_bound(h, new_node, comp, &depth); + bstree_algo::insert_equal_lower_bound(h, new_node, comp, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from - //! the "header"'s tree. - //! - //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case). - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if new_node is inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal(const node_ptr&,const node_ptr&,const node_ptr&,NodePtrCompare) template<class NodePtrCompare, class H_Alpha> static node_ptr insert_equal (const node_ptr & header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::insert_equal(header, hint, new_node, comp, &depth); + bstree_algo::insert_equal(header, hint, new_node, comp, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. - template<class KeyType, class KeyNodePtrCompare> - static std::pair<node_ptr, bool> insert_unique_check - (const const_node_ptr & header, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) - { - std::size_t depth; - std::pair<node_ptr, bool> ret = - tree_algorithms::insert_unique_check(header, key, comp, commit_data, &depth); - commit_data.depth = depth; - return ret; - } - - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "pos" must be a valid iterator or header (end) node. - //! "pos" must be an iterator pointing to the successor to "new_node" - //! once inserted according to the order of already inserted nodes. This function does not - //! check "pos" and this precondition must be guaranteed by the caller. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node" - //! tree invariants might be broken. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_before(const node_ptr&,const node_ptr&,const node_ptr&) template<class H_Alpha> static node_ptr insert_before (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::insert_before(header, pos, new_node, &depth); + bstree_algo::insert_before(header, pos, new_node, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering no less than the - //! greatest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is less than the greatest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_back(const node_ptr&,const node_ptr&) template<class H_Alpha> static void push_back(const node_ptr & header, const node_ptr & new_node ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::push_back(header, new_node, &depth); + bstree_algo::push_back(header, new_node, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering, no greater than the - //! lowest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is greater than the lowest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_front(const node_ptr&,const node_ptr&) template<class H_Alpha> static void push_front(const node_ptr & header, const node_ptr & new_node ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { std::size_t depth; - tree_algorithms::push_front(header, new_node, &depth); + bstree_algo::push_front(header, new_node, &depth); rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! "hint" is node from the "header"'s tree. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" using "hint" as a hint to where it should be - //! inserted and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! If "hint" is the upper_bound the function has constant time - //! complexity (two comparisons in the worst case). - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic, but it is - //! amortized constant time if new_node should be inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, bool> insert_unique_check + (const const_node_ptr & header, const KeyType &key + ,KeyNodePtrCompare comp, insert_commit_data &commit_data) + { + std::size_t depth; + std::pair<node_ptr, bool> ret = + bstree_algo::insert_unique_check(header, key, comp, commit_data, &depth); + commit_data.depth = depth; + return ret; + } + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, bool> insert_unique_check (const const_node_ptr & header, const node_ptr &hint, const KeyType &key @@ -679,83 +282,36 @@ class sgtree_algorithms { std::size_t depth; std::pair<node_ptr, bool> ret = - tree_algorithms::insert_unique_check + bstree_algo::insert_unique_check (header, hint, key, comp, commit_data, &depth); commit_data.depth = depth; return ret; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "commit_data" must have been obtained from a previous call to - //! "insert_unique_check". No objects should have been inserted or erased - //! from the set between the "insert_unique_check" that filled "commit_data" - //! and the call to "insert_commit". - //! - //! - //! <b>Effects</b>: Inserts new_node in the set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_commit(const node_ptr&,const node_ptr&,const insert_commit_data&) template<class H_Alpha> static void insert_unique_commit (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size) { - tree_algorithms::insert_unique_commit(header, new_value, commit_data); + bstree_algo::insert_unique_commit(header, new_value, commit_data); rebalance_after_insertion(new_value, commit_data.depth, tree_size+1, h_alpha, max_tree_size); } - //! <b>Requires</b>: header must be the header of a tree. - //! - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - static void rebalance(const node_ptr & header) - { tree_algorithms::rebalance(header); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header + static bool is_header(const const_node_ptr & p); + + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header + static void rebalance(const node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::rebalance_subtree static node_ptr rebalance_subtree(const node_ptr & old_root) - { return tree_algorithms::rebalance_subtree(old_root); } - - //! <b>Requires</b>: "n" must be a node inserted in a tree. - //! - //! <b>Effects</b>: Returns a pointer to the header node of the tree. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - static node_ptr get_header(const node_ptr & n) - { return tree_algorithms::get_header(n); } + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED /// @cond private: - //! <b>Requires</b>: p is a node of a tree. - //! - //! <b>Effects</b>: Returns true if p is the header of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static bool is_header(const const_node_ptr & p) - { return tree_algorithms::is_header(p); } - template<class H_Alpha> static void rebalance_after_insertion (const node_ptr &x, std::size_t depth @@ -764,7 +320,12 @@ class sgtree_algorithms if(tree_size > max_tree_size) max_tree_size = tree_size; - if(tree_size != 1 && depth > h_alpha(tree_size)){ + if(tree_size > 2 && //Nothing to do with only the root + //Check if the root node is unbalanced + //Scapegoat paper depth counts root depth as zero and "depth" counts root as 1, + //but since "depth" is the depth of the ancestor of x, i == depth + depth > h_alpha(tree_size)){ + //Find the first non height-balanced node //as described in the section 4.2 of the paper. //This method is the alternative method described @@ -773,32 +334,42 @@ class sgtree_algorithms //than the weight balanced method. node_ptr s = x; std::size_t size = 1; - - for(std::size_t i = 1; true; ++i){ - bool rebalance = false; - if(i == depth){ - BOOST_INTRUSIVE_INVARIANT_ASSERT(tree_size == count(s)); - rebalance = true; - } - else if(i > h_alpha(size)){ - node_ptr s_parent = NodeTraits::get_parent(s); - node_ptr s_parent_left = NodeTraits::get_left(s_parent); - size += 1 + tree_algorithms::count - ( s_parent_left == s ? NodeTraits::get_right(s_parent) : s_parent_left ); - s = s_parent; - rebalance = true; - } - if(rebalance){ - rebalance_subtree(s); - break; + for(std::size_t ancestor = 1; ancestor != depth; ++ancestor){ + const node_ptr s_parent = NodeTraits::get_parent(s); + const node_ptr s_parent_left = NodeTraits::get_left(s_parent); + //Obtain parent's size (previous size + parent + sibling tree) + const node_ptr s_sibling = s_parent_left == s ? NodeTraits::get_right(s_parent) : s_parent_left; + size += 1 + bstree_algo::subtree_size(s_sibling); + s = s_parent; + if(ancestor > h_alpha(size)){ //is 's' scapegoat? + bstree_algo::rebalance_subtree(s); + return; } } + //The whole tree must be rebuilt + max_tree_size = tree_size; + bstree_algo::rebalance_subtree(NodeTraits::get_parent(s)); } } - /// @endcond }; +/// @cond + +template<class NodeTraits> +struct get_algo<SgTreeAlgorithms, NodeTraits> +{ + typedef sgtree_algorithms<NodeTraits> type; +}; + +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<SgTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/slist.hpp b/boost/intrusive/slist.hpp index d7fc1316b1..4698730d8d 100644 --- a/boost/intrusive/slist.hpp +++ b/boost/intrusive/slist.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,64 +14,82 @@ #ifndef BOOST_INTRUSIVE_SLIST_HPP #define BOOST_INTRUSIVE_SLIST_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <boost/static_assert.hpp> -#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/intrusive_fwd.hpp> + +#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/slist_hook.hpp> #include <boost/intrusive/circular_slist_algorithms.hpp> #include <boost/intrusive/linear_slist_algorithms.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/intrusive/options.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <iterator> +#include <boost/intrusive/detail/get_value_traits.hpp> +#include <boost/intrusive/detail/is_stateful_value_traits.hpp> +#include <boost/intrusive/detail/default_header_holder.hpp> +#include <boost/intrusive/detail/uncast.hpp> +#include <boost/intrusive/detail/mpl.hpp> +#include <boost/intrusive/detail/slist_iterator.hpp> +#include <boost/intrusive/detail/array_initializer.hpp> +#include <boost/intrusive/detail/exception_disposer.hpp> +#include <boost/intrusive/detail/equal_to_value.hpp> +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> +#include <boost/intrusive/detail/simple_disposers.hpp> +#include <boost/intrusive/detail/size_holder.hpp> + +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> + #include <functional> #include <algorithm> #include <cstddef> //std::size_t #include <utility> //std::pair -#include <boost/move/move.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class SizeType, bool ConstantTimeSize, bool Linear, bool CacheLast> -struct slistopt +template<class HeaderHolder, class NodePtr, bool> +struct header_holder_plus_last { - typedef ValueTraits value_traits; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; - static const bool linear = Linear; - static const bool cache_last = CacheLast; + HeaderHolder header_holder_; + NodePtr last_; }; -template<class Node, class NodePtr, bool> -struct root_plus_last +template<class HeaderHolder, class NodePtr> +struct header_holder_plus_last<HeaderHolder, NodePtr, false> { - Node root_; - NodePtr last_; + HeaderHolder header_holder_; }; -template<class Node, class NodePtr> -struct root_plus_last<Node, NodePtr, false> +struct default_slist_hook_applier +{ template <class T> struct apply{ typedef typename T::default_slist_hook type; }; }; + +template<> +struct is_default_hook_tag<default_slist_hook_applier> +{ static const bool value = true; }; + +struct slist_defaults { - Node root_; + typedef default_slist_hook_applier proto_value_traits; + static const bool constant_time_size = true; + static const bool linear = false; + typedef std::size_t size_type; + static const bool cache_last = false; + typedef void header_holder_type; +}; + +struct slist_bool_flags +{ + static const std::size_t linear_pos = 1u; + static const std::size_t constant_time_size_pos = 2u; + static const std::size_t cache_last_pos = 4u; }; -template <class T> -struct slist_defaults - : pack_options - < none - , base_hook<detail::default_slist_hook> - , constant_time_size<true> - , linear<false> - , size_type<std::size_t> - , cache_last<false> - >::type -{}; /// @endcond @@ -101,49 +119,41 @@ struct slist_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif class slist_impl - : private detail::clear_on_destructor_base<slist_impl<Config> > { - template<class C> friend class detail::clear_on_destructor_base; //Public typedefs public: - typedef typename Config::value_traits value_traits; - /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; - /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; + typedef ValueTraits value_traits; + typedef typename value_traits::pointer pointer; + typedef typename value_traits::const_pointer const_pointer; typedef typename pointer_traits<pointer>::element_type value_type; typedef typename pointer_traits<pointer>::reference reference; typedef typename pointer_traits<const_pointer>::reference const_reference; typedef typename pointer_traits<pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef slist_iterator<slist_impl, false> iterator; - typedef slist_iterator<slist_impl, true> const_iterator; - typedef typename real_value_traits::node_traits node_traits; + typedef SizeType size_type; + typedef slist_iterator<value_traits, false> iterator; + typedef slist_iterator<value_traits, true> const_iterator; + typedef typename value_traits::node_traits node_traits; typedef typename node_traits::node node; typedef typename node_traits::node_ptr node_ptr; typedef typename node_traits::const_node_ptr const_node_ptr; + typedef HeaderHolder header_holder_type; + + static const bool constant_time_size = 0 != (BoolFlags & slist_bool_flags::constant_time_size_pos); + static const bool stateful_value_traits = detail::is_stateful_value_traits<value_traits>::value; + static const bool linear = 0 != (BoolFlags & slist_bool_flags::linear_pos); + static const bool cache_last = 0 != (BoolFlags & slist_bool_flags::cache_last_pos); + static const bool has_container_from_iterator = + detail::is_same< header_holder_type, detail::default_header_holder< node_traits > >::value; typedef typename detail::if_c - < Config::linear + < linear , linear_slist_algorithms<node_traits> , circular_slist_algorithms<node_traits> >::type node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; - static const bool linear = Config::linear; - static const bool cache_last = Config::cache_last; - /// @cond private: typedef detail::size_holder<constant_time_size, size_type> size_traits; @@ -151,16 +161,14 @@ class slist_impl //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(slist_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); + BOOST_STATIC_ASSERT(!(constant_time_size && ((int)value_traits::link_mode == (int)auto_unlink))); //Linear singly linked lists are incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(linear && ((int)real_value_traits::link_mode == (int)auto_unlink))); + BOOST_STATIC_ASSERT(!(linear && ((int)value_traits::link_mode == (int)auto_unlink))); //A list with cached last node is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(cache_last && ((int)real_value_traits::link_mode == (int)auto_unlink))); + BOOST_STATIC_ASSERT(!(cache_last && ((int)value_traits::link_mode == (int)auto_unlink))); node_ptr get_end_node() { return node_ptr(linear ? node_ptr() : this->get_root_node()); } @@ -171,10 +179,10 @@ class slist_impl (linear ? const_node_ptr() : this->get_root_node()); } node_ptr get_root_node() - { return pointer_traits<node_ptr>::pointer_to(data_.root_plus_size_.root_); } + { return data_.root_plus_size_.header_holder_.get_node(); } const_node_ptr get_root_node() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.root_plus_size_.root_); } + { return data_.root_plus_size_.header_holder_.get_node(); } node_ptr get_last_node() { return this->get_last_node(detail::bool_<cache_last>()); } @@ -186,10 +194,17 @@ class slist_impl { return this->set_last_node(n, detail::bool_<cache_last>()); } static node_ptr get_last_node(detail::bool_<false>) - { return node_ptr(); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return node_ptr(); + } static void set_last_node(const node_ptr &, detail::bool_<false>) - {} + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + } node_ptr get_last_node(detail::bool_<true>) { return node_ptr(data_.root_plus_size_.last_); } @@ -200,9 +215,6 @@ class slist_impl void set_last_node(const node_ptr & n, detail::bool_<true>) { data_.root_plus_size_.last_ = n; } - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - void set_default_constructed_state() { node_algorithms::init_header(this->get_root_node()); @@ -212,16 +224,17 @@ class slist_impl } } + typedef header_holder_plus_last<header_holder_type, node_ptr, cache_last> header_holder_plus_last_t; struct root_plus_size : public size_traits - , public root_plus_last<node, node_ptr, cache_last> + , public header_holder_plus_last_t {}; struct data_t : public slist_impl::value_traits { typedef typename slist_impl::value_traits value_traits; - data_t(const value_traits &val_traits) + explicit data_t(const value_traits &val_traits) : value_traits(val_traits) {} @@ -234,58 +247,71 @@ class slist_impl const size_traits &priv_size_traits() const { return data_.root_plus_size_; } - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } - - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } - - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } - const value_traits &priv_value_traits() const { return data_; } value_traits &priv_value_traits() { return data_; } - protected: - node &prot_root_node() - { return data_.root_plus_size_.root_; } + typedef typename boost::intrusive::value_traits_pointers + <ValueTraits>::const_value_traits_ptr const_value_traits_ptr; - node const &prot_root_node() const - { return data_.root_plus_size_.root_; } - - void prot_set_size(size_type s) - { data_.root_plus_size_.set_size(s); } + const_value_traits_ptr priv_value_traits_ptr() const + { return pointer_traits<const_value_traits_ptr>::pointer_to(this->priv_value_traits()); } /// @endcond public: - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } + ///@cond + + //! <b>Requires</b>: f and before_l belong to another slist. + //! + //! <b>Effects</b>: Transfers the range [f, before_l] to this + //! list, after the element pointed by prev_pos. + //! No destructors or copy constructors are called. + //! + //! <b>Throws</b>: Nothing. + //! + //! <b>Complexity</b>: Linear to the number of elements transferred + //! if constant_time_size is true. Constant-time otherwise. + //! + //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this + //! list. Iterators of this list and all the references are not invalidated. + //! + //! <b>Warning</b>: Experimental function, don't use it! + slist_impl( const node_ptr & f, const node_ptr & before_l + , size_type n, const value_traits &v_traits = value_traits()) + : data_(v_traits) + { + if(n){ + this->priv_size_traits().set_size(n); + if(cache_last){ + this->set_last_node(before_l); + } + node_traits::set_next(this->get_root_node(), f); + node_traits::set_next(before_l, this->get_end_node()); + } + else{ + this->set_default_constructed_state(); + } + } - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } + ///@endcond - public: //! <b>Effects</b>: constructs an empty list. //! //! <b>Complexity</b>: Constant //! //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks). - slist_impl(const value_traits &v_traits = value_traits()) + explicit slist_impl(const value_traits &v_traits = value_traits()) : data_(v_traits) { this->set_default_constructed_state(); } //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. //! - //! <b>Effects</b>: Constructs a list equal to [first,last). + //! <b>Effects</b>: Constructs a list equal to [b ,e). //! //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called. //! @@ -296,6 +322,7 @@ class slist_impl : data_(v_traits) { this->set_default_constructed_state(); + //nothrow, no need to rollback to release elements on exception this->insert_after(this->cbefore_begin(), b, e); } @@ -306,6 +333,7 @@ class slist_impl { this->priv_size_traits().set_size(size_type(0)); node_algorithms::init_header(this->get_root_node()); + //nothrow, no need to rollback to release elements on exception this->swap(x); } @@ -324,7 +352,12 @@ class slist_impl //! <b>Complexity</b>: Linear to the number of elements in the list, if //! it's a safe-mode or auto-unlink value. Otherwise constant. ~slist_impl() - {} + { + if(is_safe_autounlink<ValueTraits::link_mode>::value){ + this->clear(); + node_algorithms::init(this->get_root_node()); + } + } //! <b>Effects</b>: Erases all the elements of the container. //! @@ -363,7 +396,7 @@ class slist_impl ++it; if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); } this->set_default_constructed_state(); } @@ -380,7 +413,7 @@ class slist_impl //! <b>Note</b>: Does not affect the validity of iterators and references. void push_front(reference value) { - node_ptr to_insert = get_real_value_traits().to_node_ptr(value); + node_ptr to_insert = priv_value_traits().to_node_ptr(value); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert)); if(cache_last){ @@ -406,7 +439,14 @@ class slist_impl void push_back(reference value) { BOOST_STATIC_ASSERT((cache_last)); - this->insert_after(const_iterator(this->get_last_node(), this), value); + node_ptr n = priv_value_traits().to_node_ptr(value); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n)); + node_algorithms::link_after(this->get_last_node(), n); + if(cache_last){ + this->set_last_node(n); + } + this->priv_size_traits().increment(); } //! <b>Effects</b>: Erases the first element of the list. @@ -438,7 +478,7 @@ class slist_impl this->priv_size_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); if(cache_last){ if(this->empty()){ this->set_last_node(this->get_root_node()); @@ -452,7 +492,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. reference front() - { return *this->get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } + { return *this->priv_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); } //! <b>Effects</b>: Returns a const_reference to the first element of the list. //! @@ -460,7 +500,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. const_reference front() const - { return *this->get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); } + { return *this->priv_value_traits().to_value_ptr(detail::uncast(node_traits::get_next(this->get_root_node()))); } //! <b>Effects</b>: Returns a reference to the last element of the list. //! @@ -473,7 +513,7 @@ class slist_impl reference back() { BOOST_STATIC_ASSERT((cache_last)); - return *this->get_real_value_traits().to_value_ptr(this->get_last_node()); + return *this->priv_value_traits().to_value_ptr(this->get_last_node()); } //! <b>Effects</b>: Returns a const_reference to the last element of the list. @@ -487,7 +527,7 @@ class slist_impl const_reference back() const { BOOST_STATIC_ASSERT((cache_last)); - return *this->get_real_value_traits().to_value_ptr(this->get_last_node()); + return *this->priv_value_traits().to_value_ptr(this->get_last_node()); } //! <b>Effects</b>: Returns an iterator to the first element contained in the list. @@ -496,7 +536,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. iterator begin() - { return iterator (node_traits::get_next(this->get_root_node()), this); } + { return iterator (node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. //! @@ -504,7 +544,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. const_iterator begin() const - { return const_iterator (node_traits::get_next(this->get_root_node()), this); } + { return const_iterator (node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. //! @@ -512,7 +552,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. const_iterator cbegin() const - { return const_iterator(node_traits::get_next(this->get_root_node()), this); } + { return const_iterator(node_traits::get_next(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns an iterator to the end of the list. //! @@ -520,7 +560,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. iterator end() - { return iterator(this->get_end_node(), this); } + { return iterator(this->get_end_node(), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the end of the list. //! @@ -528,7 +568,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. const_iterator end() const - { return const_iterator(uncast(this->get_end_node()), this); } + { return const_iterator(detail::uncast(this->get_end_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns a const_iterator to the end of the list. //! @@ -545,7 +585,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. iterator before_begin() - { return iterator(this->get_root_node(), this); } + { return iterator(this->get_root_node(), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns an iterator that points to a position //! before the first element. Equivalent to "end()" @@ -554,7 +594,7 @@ class slist_impl //! //! <b>Complexity</b>: Constant. const_iterator before_begin() const - { return const_iterator(uncast(this->get_root_node()), this); } + { return const_iterator(detail::uncast(this->get_root_node()), this->priv_value_traits_ptr()); } //! <b>Effects</b>: Returns an iterator that points to a position //! before the first element. Equivalent to "end()" @@ -573,9 +613,13 @@ class slist_impl //! //! <b>Note</b>: This function is present only if cached_last<> option is true. iterator last() - { return iterator (this->get_last_node(), this); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return iterator (this->get_last_node(), this->priv_value_traits_ptr()); + } - //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. + //! <b>Effects</b>: Returns a const_iterator to the last element contained in the list. //! //! <b>Throws</b>: Nothing. //! @@ -583,9 +627,13 @@ class slist_impl //! //! <b>Note</b>: This function is present only if cached_last<> option is true. const_iterator last() const - { return const_iterator (this->get_last_node(), this); } + { + //This function shall not be used if cache_last is not true + BOOST_INTRUSIVE_INVARIANT_ASSERT(cache_last); + return const_iterator (this->get_last_node(), this->priv_value_traits_ptr()); + } - //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list. + //! <b>Effects</b>: Returns a const_iterator to the last element contained in the list. //! //! <b>Throws</b>: Nothing. //! @@ -593,7 +641,7 @@ class slist_impl //! //! <b>Note</b>: This function is present only if cached_last<> option is true. const_iterator clast() const - { return const_iterator(this->get_last_node(), this); } + { return const_iterator(this->get_last_node(), this->priv_value_traits_ptr()); } //! <b>Precondition</b>: end_iterator must be a valid end iterator //! of slist. @@ -733,7 +781,7 @@ class slist_impl //! <b>Note</b>: Does not affect the validity of iterators and references. iterator insert_after(const_iterator prev_p, reference value) { - node_ptr n = get_real_value_traits().to_node_ptr(value); + node_ptr n = priv_value_traits().to_node_ptr(value); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n)); node_ptr prev_n(prev_p.pointed_node()); @@ -742,14 +790,14 @@ class slist_impl this->set_last_node(n); } this->priv_size_traits().increment(); - return iterator (n, this); + return iterator (n, this->priv_value_traits_ptr()); } //! <b>Requires</b>: Dereferencing iterator must yield //! an lvalue of type value_type and prev_p must point to an element //! contained by the list or to the end node. //! - //! <b>Effects</b>: Inserts the [first, last) + //! <b>Effects</b>: Inserts the [f, l) //! after the position prev_p. //! //! <b>Throws</b>: Nothing. @@ -758,10 +806,25 @@ class slist_impl //! //! <b>Note</b>: Does not affect the validity of iterators and references. template<class Iterator> - void insert_after(const_iterator prev_p, Iterator first, Iterator last) + void insert_after(const_iterator prev_p, Iterator f, Iterator l) { - for (; first != last; ++first) - prev_p = this->insert_after(prev_p, *first); + //Insert first nodes avoiding cache and size checks + size_type count = 0; + node_ptr prev_n(prev_p.pointed_node()); + for (; f != l; ++f, ++count){ + const node_ptr n = priv_value_traits().to_node_ptr(*f); + if(safemode_or_autounlink) + BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n)); + node_algorithms::link_after(prev_n, n); + prev_n = n; + } + //Now fix special cases if needed + if(cache_last && (this->get_last_node() == prev_p.pointed_node())){ + this->set_last_node(prev_n); + } + if(constant_time_size){ + this->priv_size_traits().increase(count); + } } //! <b>Requires</b>: value must be an lvalue and p must point to an element @@ -812,7 +875,7 @@ class slist_impl iterator erase_after(const_iterator prev) { return this->erase_after_and_dispose(prev, detail::null_disposer()); } - //! <b>Effects</b>: Erases the range (before_first, last) from + //! <b>Effects</b>: Erases the range (before_f, l) from //! the list. No destructors are called. //! //! <b>Returns</b>: the first element remaining beyond the removed elements, @@ -825,26 +888,26 @@ class slist_impl //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase_after(const_iterator before_first, const_iterator last) + iterator erase_after(const_iterator before_f, const_iterator l) { if(safemode_or_autounlink || constant_time_size){ - return this->erase_after_and_dispose(before_first, last, detail::null_disposer()); + return this->erase_after_and_dispose(before_f, l, detail::null_disposer()); } else{ - node_ptr bfp = before_first.pointed_node(); - node_ptr lp = last.pointed_node(); + const node_ptr bfp = before_f.pointed_node(); + const node_ptr lp = l.pointed_node(); if(cache_last){ if(lp == this->get_end_node()){ this->set_last_node(bfp); } } node_algorithms::unlink_after(bfp, lp); - return last.unconst(); + return l.unconst(); } } - //! <b>Effects</b>: Erases the range (before_first, last) from - //! the list. n must be std::distance(before_first, last) - 1. + //! <b>Effects</b>: Erases the range (before_f, l) from + //! the list. n must be std::distance(before_f, l) - 1. //! No destructors are called. //! //! <b>Returns</b>: the first element remaining beyond the removed elements, @@ -853,19 +916,19 @@ class slist_impl //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: constant-time if link_mode is normal_link. - //! Linear to the elements (last - before_first) otherwise. + //! Linear to the elements (l - before_f) otherwise. //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase_after(const_iterator before_first, const_iterator last, difference_type n) + iterator erase_after(const_iterator before_f, const_iterator l, size_type n) { - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_first), last) == difference_type(n)); + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance((++const_iterator(before_f)).pointed_node(), l.pointed_node()) == n); if(safemode_or_autounlink){ - return this->erase_after(before_first, last); + return this->erase_after(before_f, l); } else{ - node_ptr bfp = before_first.pointed_node(); - node_ptr lp = last.pointed_node(); + const node_ptr bfp = before_f.pointed_node(); + const node_ptr lp = l.pointed_node(); if(cache_last){ if((lp == this->get_end_node())){ this->set_last_node(bfp); @@ -873,9 +936,9 @@ class slist_impl } node_algorithms::unlink_after(bfp, lp); if(constant_time_size){ - this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n); + this->priv_size_traits().decrease(n); } - return last.unconst(); + return l.unconst(); } } @@ -894,7 +957,7 @@ class slist_impl iterator erase(const_iterator i) { return this->erase_after(this->previous(i)); } - //! <b>Requires</b>: first and last must be valid iterator to elements in *this. + //! <b>Requires</b>: f and l must be valid iterator to elements in *this. //! //! <b>Effects</b>: Erases the range pointed by b and e. //! No destructors are called. @@ -904,15 +967,15 @@ class slist_impl //! //! <b>Throws</b>: Nothing. //! - //! <b>Complexity</b>: Linear to the elements before last. + //! <b>Complexity</b>: Linear to the elements before l. //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased elements. - iterator erase(const_iterator first, const_iterator last) - { return this->erase_after(this->previous(first), last); } + iterator erase(const_iterator f, const_iterator l) + { return this->erase_after(this->previous(f), l); } - //! <b>Effects</b>: Erases the range [first, last) from - //! the list. n must be std::distance(first, last). + //! <b>Effects</b>: Erases the range [f, l) from + //! the list. n must be std::distance(f, l). //! No destructors are called. //! //! <b>Returns</b>: the first element remaining beyond the removed elements, @@ -920,13 +983,13 @@ class slist_impl //! //! <b>Throws</b>: Nothing. //! - //! <b>Complexity</b>: linear to the elements before first if link_mode is normal_link - //! and constant_time_size is activated. Linear to the elements before last otherwise. + //! <b>Complexity</b>: linear to the elements before f if link_mode is normal_link + //! and constant_time_size is activated. Linear to the elements before l otherwise. //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased element. - iterator erase(const_iterator first, const_iterator last, difference_type n) - { return this->erase_after(this->previous(first), last, n); } + iterator erase(const_iterator f, const_iterator l, size_type n) + { return this->erase_after(this->previous(f), l, n); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -956,7 +1019,7 @@ class slist_impl } if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); this->priv_size_traits().decrement(); return it.unconst(); } @@ -975,7 +1038,7 @@ class slist_impl node_algorithms::unlink_after(prev_n); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(real_value_traits::to_value_ptr(to_erase)); + disposer(value_traits::to_value_ptr(to_erase)); return it.unconst(); } @@ -986,7 +1049,7 @@ class slist_impl //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! - //! <b>Effects</b>: Erases the range (before_first, last) from + //! <b>Effects</b>: Erases the range (before_f, l) from //! the list. //! Disposer::operator()(pointer) is called for the removed elements. //! @@ -995,13 +1058,13 @@ class slist_impl //! //! <b>Throws</b>: Nothing. //! - //! <b>Complexity</b>: Lineal to the elements (last - before_first + 1). + //! <b>Complexity</b>: Lineal to the elements (l - before_f + 1). //! //! <b>Note</b>: Invalidates the iterators to the erased element. template<class Disposer> - iterator erase_after_and_dispose(const_iterator before_first, const_iterator last, Disposer disposer) + iterator erase_after_and_dispose(const_iterator before_f, const_iterator l, Disposer disposer) { - node_ptr bfp(before_first.pointed_node()), lp(last.pointed_node()); + node_ptr bfp(before_f.pointed_node()), lp(l.pointed_node()); node_ptr fp(node_traits::get_next(bfp)); node_algorithms::unlink_after(bfp, lp); while(fp != lp){ @@ -1009,13 +1072,13 @@ class slist_impl fp = node_traits::get_next(fp); if(safemode_or_autounlink) node_algorithms::init(to_erase); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(priv_value_traits().to_value_ptr(to_erase)); this->priv_size_traits().decrement(); } if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){ this->set_last_node(bfp); } - return last.unconst(); + return l.unconst(); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. @@ -1043,7 +1106,7 @@ class slist_impl { return this->erase_and_dispose(const_iterator(i), disposer); } #endif - //! <b>Requires</b>: first and last must be valid iterator to elements in *this. + //! <b>Requires</b>: f and l must be valid iterator to elements in *this. //! Disposer::operator()(pointer) shouldn't throw. //! //! <b>Effects</b>: Erases the range pointed by b and e. @@ -1056,13 +1119,13 @@ class slist_impl //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Linear to the number of erased elements plus linear - //! to the elements before first. + //! to the elements before f. //! //! <b>Note</b>: Invalidates the iterators (but not the references) to the //! erased elements. template<class Disposer> - iterator erase_and_dispose(const_iterator first, const_iterator last, Disposer disposer) - { return this->erase_after_and_dispose(this->previous(first), last, disposer); } + iterator erase_and_dispose(const_iterator f, const_iterator l, Disposer disposer) + { return this->erase_after_and_dispose(this->previous(f), l, disposer); } //! <b>Requires</b>: Dereferencing iterator must yield //! an lvalue of type value_type. @@ -1121,23 +1184,23 @@ class slist_impl //! //! <b>Complexity</b>: In general, linear to the elements contained in x. //! Constant-time if cache_last<> option is true and also constant-time if - //! linear<> option is true "this" is empty and "last" is not used. + //! linear<> option is true "this" is empty and "l" is not used. //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. //! - //! <b>Additional note</b>: If the optional parameter "last" is provided, it will be + //! <b>Additional note</b>: If the optional parameter "l" is provided, it will be //! assigned to the last spliced element or prev if x is empty. //! This iterator can be used as new "prev" iterator for a new splice_after call. //! that will splice new values after the previously spliced values. - void splice_after(const_iterator prev, slist_impl &x, const_iterator *last = 0) + void splice_after(const_iterator prev, slist_impl &x, const_iterator *l = 0) { if(x.empty()){ - if(last) *last = prev; + if(l) *l = prev; } else if(linear && this->empty()){ this->swap(x); - if(last) *last = this->previous(this->cend()); + if(l) *l = this->previous(this->cend()); } else{ const_iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active @@ -1150,9 +1213,9 @@ class slist_impl } } node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n); - this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size()); + this->priv_size_traits().increase(x.priv_size_traits().get_size()); x.priv_size_traits().set_size(size_type(0)); - if(last) *last = last_x; + if(l) *l = last_x; } } @@ -1176,10 +1239,10 @@ class slist_impl } //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end(). + //! before_begin(), and before_f and before_l belong to x and + //! ++before_f != x.end() && before_l != x.end(). //! - //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this + //! <b>Effects</b>: Transfers the range (before_f, before_l] from list x to this //! list, after the element pointed by prev_pos. //! No destructors or copy constructors are called. //! @@ -1190,21 +1253,21 @@ class slist_impl //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last) + void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l) { if(constant_time_size) - this->splice_after(prev_pos, x, before_first, before_last, std::distance(before_first, before_last)); + this->splice_after(prev_pos, x, before_f, before_l, node_algorithms::distance(before_f.pointed_node(), before_l.pointed_node())); else this->priv_splice_after - (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node()); + (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node()); } //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end() and - //! n == std::distance(before_first, before_last). + //! before_begin(), and before_f and before_l belong to x and + //! ++before_f != x.end() && before_l != x.end() and + //! n == std::distance(before_f, before_l). //! - //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this + //! <b>Effects</b>: Transfers the range (before_f, before_l] from list x to this //! list, after the element pointed by p. No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. @@ -1213,16 +1276,14 @@ class slist_impl //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last, difference_type n) + void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_f, const_iterator before_l, size_type n) { - if(n){ - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_first, before_last) == n); - this->priv_splice_after - (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node()); - if(constant_time_size){ - this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n); - x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n); - } + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_algorithms::distance(before_f.pointed_node(), before_l.pointed_node()) == n); + this->priv_splice_after + (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node()); + if(constant_time_size){ + this->priv_size_traits().increase(n); + x.priv_size_traits().decrease(n); } } @@ -1243,12 +1304,12 @@ class slist_impl //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. //! - //! <b>Additional note</b>: If the optional parameter "last" is provided, it will be + //! <b>Additional note</b>: If the optional parameter "l" is provided, it will be //! assigned to the last spliced element or prev if x is empty. //! This iterator can be used as new "prev" iterator for a new splice_after call. //! that will splice new values after the previously spliced values. - void splice(const_iterator it, slist_impl &x, const_iterator *last = 0) - { this->splice_after(this->previous(it), x, last); } + void splice(const_iterator it, slist_impl &x, const_iterator *l = 0) + { this->splice_after(this->previous(it), x, l); } //! <b>Requires</b>: it p must be a valid iterator of *this. //! elem must point to an element contained in list @@ -1268,43 +1329,43 @@ class slist_impl { return this->splice_after(this->previous(pos), x, x.previous(elem)); } //! <b>Requires</b>: pos must be a dereferenceable iterator in *this - //! and first and last belong to x and first and last a valid range on x. + //! and f and f belong to x and f and f a valid range on x. //! - //! <b>Effects</b>: Transfers the range [first, last) from list x to this + //! <b>Effects</b>: Transfers the range [f, l) from list x to this //! list, before the element pointed by pos. //! No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. //! - //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last + //! <b>Complexity</b>: Linear to the sum of elements before pos, f, and l //! plus linear to the number of elements transferred if constant_time_size is true. - //! Linear to the sum of elements before first, and last + //! Linear to the sum of elements before f, and l //! plus linear to the number of elements transferred if constant_time_size is true //! if cache_last<> is true and pos == end() //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last) - { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last)); } + void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l) + { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l)); } //! <b>Requires</b>: pos must be a dereferenceable iterator in *this - //! and first and last belong to x and first and last a valid range on x. - //! n == std::distance(first, last). + //! and f and l belong to x and f and l a valid range on x. + //! n == std::distance(f, l). //! - //! <b>Effects</b>: Transfers the range [first, last) from list x to this + //! <b>Effects</b>: Transfers the range [f, l) from list x to this //! list, before the element pointed by pos. //! No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. //! - //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last. - //! Linear to the sum of elements before first and last + //! <b>Complexity</b>: Linear to the sum of elements before pos, f, and l. + //! Linear to the sum of elements before f and l //! if cache_last<> is true and pos == end(). //! //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this //! list. Iterators of this list and all the references are not invalidated. - void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last, difference_type n) - { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last), n); } + void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l, size_type n) + { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l), n); } //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>. //! The sort is stable, that is, the relative order of equivalent elements is preserved. @@ -1402,14 +1463,14 @@ class slist_impl //! //! <b>Note</b>: Iterators and references are not invalidated. //! - //! <b>Additional note</b>: If optional "last" argument is passed, it is assigned + //! <b>Additional note</b>: If optional "l" argument is passed, it is assigned //! to an iterator to the last transferred value or end() is x is empty. template<class Predicate> - void merge(slist_impl& x, Predicate p, const_iterator *last = 0) + void merge(slist_impl& x, Predicate p, const_iterator *l = 0) { const_iterator e(this->cend()), ex(x.cend()), bb(this->cbefore_begin()), bb_next; - if(last) *last = e.unconst(); + if(l) *l = e.unconst(); while(!x.empty()){ const_iterator ibx_next(x.cbefore_begin()), ibx(ibx_next++); while (++(bb_next = bb) != e && !p(*ibx_next, *bb_next)){ @@ -1417,7 +1478,7 @@ class slist_impl } if(bb_next == e){ //Now transfer the rest to the end of the container - this->splice_after(bb, x, last); + this->splice_after(bb, x, l); break; } else{ @@ -1426,7 +1487,7 @@ class slist_impl ibx = ibx_next; ++n; } while(++(ibx_next = ibx) != ex && p(*ibx_next, *bb_next)); this->splice_after(bb, x, x.before_begin(), ibx, n); - if(last) *last = ibx; + if(l) *l = ibx; } } } @@ -1499,7 +1560,20 @@ class slist_impl //! and iterators to elements that are not removed remain valid. template<class Pred> void remove_if(Pred pred) - { this->remove_and_dispose_if(pred, detail::null_disposer()); } + { + const node_ptr bbeg = this->get_root_node(); + typename node_algorithms::stable_partition_info info; + node_algorithms::stable_partition + (bbeg, this->get_end_node(), detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); + //After cache last is set, slist invariants are preserved... + if(cache_last){ + this->set_last_node(info.new_last_node); + } + //...so erase can be safely called + this->erase_after( const_iterator(bbeg, this->priv_value_traits_ptr()) + , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) + , info.num_1st_partition); + } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1516,20 +1590,18 @@ class slist_impl template<class Pred, class Disposer> void remove_and_dispose_if(Pred pred, Disposer disposer) { - const_iterator bcur(this->before_begin()), cur(this->begin()), e(this->end()); - - while(cur != e){ - if (pred(*cur)){ - cur = this->erase_after_and_dispose(bcur, disposer); - } - else{ - bcur = cur; - ++cur; - } - } + const node_ptr bbeg = this->get_root_node(); + typename node_algorithms::stable_partition_info info; + node_algorithms::stable_partition + (bbeg, this->get_end_node(), detail::key_nodeptr_comp<Pred, value_traits>(pred, &this->priv_value_traits()), info); + //After cache last is set, slist invariants are preserved... if(cache_last){ - this->set_last_node(bcur.pointed_node()); + this->set_last_node(info.new_last_node); } + //...so erase can be safely called + this->erase_after_and_dispose( const_iterator(bbeg, this->priv_value_traits_ptr()) + , const_iterator(info.beg_2st_partition, this->priv_value_traits_ptr()) + , disposer); } //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent @@ -1623,8 +1695,7 @@ class slist_impl static iterator s_iterator_to(reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value))); - return iterator (value_traits::to_node_ptr(value), 0); + return iterator (value_traits::to_node_ptr(value), const_value_traits_ptr()); } //! <b>Requires</b>: value must be a const reference to a value inserted in a list. @@ -1641,8 +1712,8 @@ class slist_impl static const_iterator s_iterator_to(const_reference value) { BOOST_STATIC_ASSERT((!stateful_value_traits)); - //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value)))); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); + reference r =*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value)); + return const_iterator(value_traits::to_node_ptr(r), const_value_traits_ptr()); } //! <b>Requires</b>: value must be a reference to a value inserted in a list. @@ -1656,8 +1727,8 @@ class slist_impl //! <b>Note</b>: Iterators and references are not invalidated. iterator iterator_to(reference value) { - //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value))); - return iterator (value_traits::to_node_ptr(value), this); + BOOST_INTRUSIVE_INVARIANT_ASSERT(linear || !node_algorithms::inited(this->priv_value_traits().to_node_ptr(value))); + return iterator (this->priv_value_traits().to_node_ptr(value), this->priv_value_traits_ptr()); } //! <b>Requires</b>: value must be a const reference to a value inserted in a list. @@ -1671,8 +1742,9 @@ class slist_impl //! <b>Note</b>: Iterators and references are not invalidated. const_iterator iterator_to(const_reference value) const { - //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value)))); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); + reference r =*pointer_traits<pointer>::const_cast_from(pointer_traits<const_pointer>::pointer_to(value)); + BOOST_INTRUSIVE_INVARIANT_ASSERT (linear || !node_algorithms::inited(this->priv_value_traits().to_node_ptr(r))); + return const_iterator(this->priv_value_traits().to_node_ptr(r), this->priv_value_traits_ptr()); } //! <b>Returns</b>: The iterator to the element before i in the list. @@ -1721,18 +1793,19 @@ class slist_impl const_iterator previous(const_iterator prev_from, const_iterator i) const { if(cache_last && (i.pointed_node() == this->get_end_node())){ - return const_iterator(uncast(this->get_last_node()), this); + return const_iterator(detail::uncast(this->get_last_node()), this->priv_value_traits_ptr()); } return const_iterator (node_algorithms::get_previous_node - (prev_from.pointed_node(), i.pointed_node()), this); + (prev_from.pointed_node(), i.pointed_node()), this->priv_value_traits_ptr()); } + ///@cond + //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end(). + //! before_begin(), and f and before_l belong to another slist. //! - //! <b>Effects</b>: Transfers the range (before_first, before_last] to this + //! <b>Effects</b>: Transfers the range [f, before_l] to this //! list, after the element pointed by prev_pos. //! No destructors or copy constructors are called. //! @@ -1741,67 +1814,117 @@ class slist_impl //! <b>Complexity</b>: Linear to the number of elements transferred //! if constant_time_size is true. Constant-time otherwise. //! - //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this - //! list. Iterators of this list and all the references are not invalidated. - void incorporate_after(const_iterator prev_from, const node_ptr & first, const node_ptr & before_last) + //! <b>Note</b>: Iterators of values obtained from the list that owned f and before_l now + //! point to elements of this list. Iterators of this list and all the references are not invalidated. + //! + //! <b>Warning</b>: Experimental function, don't use it! + void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l) { if(constant_time_size) - this->incorporate_after(prev_from, first, before_last, std::distance(first, before_last)+1); + this->incorporate_after(prev_pos, f, before_l, node_algorithms::distance(f.pointed_node(), before_l.pointed_node())+1); else - this->priv_incorporate_after - (prev_from.pointed_node(), first, before_last); + this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l); } //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be - //! before_begin(), and before_first and before_last belong to x and - //! ++before_first != x.end() && before_last != x.end() and - //! n == std::distance(first, before_last) + 1. + //! before_begin(), and f and before_l belong to another slist. + //! n == std::distance(f, before_l) + 1. //! - //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this - //! list, after the element pointed by p. No destructors or copy constructors are called. + //! <b>Effects</b>: Transfers the range [f, before_l] to this + //! list, after the element pointed by prev_pos. + //! No destructors or copy constructors are called. //! //! <b>Throws</b>: Nothing. //! //! <b>Complexity</b>: Constant time. //! - //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this - //! list. Iterators of this list and all the references are not invalidated. - void incorporate_after(const_iterator prev_pos, const node_ptr & first, const node_ptr & before_last, difference_type n) + //! <b>Note</b>: Iterators of values obtained from the list that owned f and before_l now + //! point to elements of this list. Iterators of this list and all the references are not invalidated. + //! + //! <b>Warning</b>: Experimental function, don't use it! + void incorporate_after(const_iterator prev_pos, const node_ptr & f, const node_ptr & before_l, size_type n) { if(n){ - BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(iterator(first, this), iterator(before_last, this))+1 == n); - this->priv_incorporate_after(prev_pos.pointed_node(), first, before_last); + BOOST_INTRUSIVE_INVARIANT_ASSERT(n > 0); + BOOST_INTRUSIVE_INVARIANT_ASSERT + (size_type(std::distance + ( iterator(f, this->priv_value_traits_ptr()) + , iterator(before_l, this->priv_value_traits_ptr()))) + +1 == n); + this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l); if(constant_time_size){ - this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n); + this->priv_size_traits().increase(n); } } } - private: - void priv_splice_after(const node_ptr & prev_pos_n, slist_impl &x, const node_ptr & before_first_n, const node_ptr & before_last_n) + ///@endcond + + //! <b>Effects</b>: Asserts the integrity of the container. + //! + //! <b>Complexity</b>: Linear time. + //! + //! <b>Note</b>: The method has no effect when asserts are turned off (e.g., with NDEBUG). + //! Experimental function, interface might change in future versions. + void check() const { - if (before_first_n != before_last_n && prev_pos_n != before_first_n && prev_pos_n != before_last_n) + const_node_ptr header_ptr = get_root_node(); + // header's next is never null + BOOST_INTRUSIVE_INVARIANT_ASSERT(node_traits::get_next(header_ptr)); + if (node_traits::get_next(header_ptr) == header_ptr) { - if(cache_last){ - if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ - this->set_last_node(before_last_n); - } - if(node_traits::get_next(before_last_n) == x.get_end_node()){ - x.set_last_node(before_first_n); - } + if (constant_time_size) + BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == 0); + return; + } + size_t node_count = 0; + const_node_ptr p = header_ptr; + while (true) + { + const_node_ptr next_p = node_traits::get_next(p); + if (!linear) + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p); + } + else + { + BOOST_INTRUSIVE_INVARIANT_ASSERT(next_p != header_ptr); + } + if ((!linear && next_p == header_ptr) || (linear && !next_p)) + { + if (cache_last) + BOOST_INTRUSIVE_INVARIANT_ASSERT(get_last_node() == p); + break; + } + p = next_p; + ++node_count; + } + if (constant_time_size) + BOOST_INTRUSIVE_INVARIANT_ASSERT(this->priv_size_traits().get_size() == node_count); + } + + private: + void priv_splice_after(const node_ptr & prev_pos_n, slist_impl &x, const node_ptr & before_f_n, const node_ptr & before_l_n) + { + if (cache_last && (before_f_n != before_l_n)){ + if(prev_pos_n == this->get_last_node()){ + this->set_last_node(before_l_n); + } + if(&x != this && node_traits::get_next(before_l_n) == x.get_end_node()){ + x.set_last_node(before_f_n); } - node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n); } + node_algorithms::transfer_after(prev_pos_n, before_f_n, before_l_n); } - void priv_incorporate_after(const node_ptr & prev_pos_n, const node_ptr & first_n, const node_ptr & before_last_n) + void priv_incorporate_after(const node_ptr & prev_pos_n, const node_ptr & first_n, const node_ptr & before_l_n) { if(cache_last){ - if(node_traits::get_next(prev_pos_n) == this->get_end_node()){ - this->set_last_node(before_last_n); + if(prev_pos_n == this->get_last_node()){ + this->set_last_node(before_l_n); } } - node_algorithms::incorporate_after(prev_pos_n, first_n, before_last_n); + node_algorithms::incorporate_after(prev_pos_n, first_n, before_l_n); } void priv_reverse(detail::bool_<false>) @@ -1816,9 +1939,9 @@ class slist_impl void priv_shift_backwards(size_type n, detail::bool_<false>) { - node_ptr last = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n); - if(cache_last && last){ - this->set_last_node(last); + node_ptr l = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n); + if(cache_last && l){ + this->set_last_node(l); } } @@ -1837,9 +1960,9 @@ class slist_impl void priv_shift_forward(size_type n, detail::bool_<false>) { - node_ptr last = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n); - if(cache_last && last){ - this->set_last_node(last); + node_ptr l = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n); + if(cache_last && l){ + this->set_last_node(l); } } @@ -1906,8 +2029,12 @@ class slist_impl //Obtaining the container from the end iterator is not possible with linear //singly linked lists (because "end" is represented by the null pointer) BOOST_STATIC_ASSERT(!linear); - root_plus_size *r = detail::parent_from_member<root_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), (&root_plus_size::root_)); + BOOST_STATIC_ASSERT((has_container_from_iterator)); + node_ptr p = end_iterator.pointed_node(); + header_holder_type* h = header_holder_type::get_holder(p); + header_holder_plus_last_t* hpl = detail::parent_from_member< header_holder_plus_last_t, header_holder_type> + (h, &header_holder_plus_last_t::header_holder_); + root_plus_size* r = static_cast< root_plus_size* >(hpl); data_t *d = detail::parent_from_member<data_t, root_plus_size> ( r, &data_t::root_plus_size_); slist_impl *s = detail::parent_from_member<slist_impl, data_t>(d, &slist_impl::data_); @@ -1918,29 +2045,31 @@ class slist_impl #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline bool operator< #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif bool operator== #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { - typedef slist_impl<Config> slist_type; + typedef slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> slist_type; typedef typename slist_type::const_iterator const_iterator; const bool C = slist_type::constant_time_size; if(C && x.size() != y.size()){ @@ -1970,65 +2099,70 @@ bool operator== #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline bool operator!= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { return !(x == y); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline bool operator> #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { return y < x; } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline bool operator<= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { return !(y < x); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline bool operator>= #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y) #else -(const slist_impl<Config> &x, const slist_impl<Config> &y) +( const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, const slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { return !(x < y); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class SizeType, std::size_t BoolFlags, typename HeaderHolder> #endif inline void swap #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) (slist_impl<T, Options...> &x, slist_impl<T, Options...> &y) #else -(slist_impl<Config> &x, slist_impl<Config> &y) +( slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &x +, slist_impl<ValueTraits, SizeType, BoolFlags, HeaderHolder> &y) #endif { x.swap(y); } @@ -2037,30 +2171,30 @@ inline void swap #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none, class O3 = none, class O4 = none, class O5 = none> +template<class T, class O1 = void, class O2 = void, class O3 = void, class O4 = void, class O5 = void, class O6 = void> #endif struct make_slist { /// @cond typedef typename pack_options - < slist_defaults<T>, + < slist_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5 + O1, O2, O3, O4, O5, O6 #else Options... #endif >::type packed_options; typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; typedef slist_impl - < - slistopt - < value_traits - , typename packed_options::size_type - , packed_options::constant_time_size - , packed_options::linear - , packed_options::cache_last - > + < value_traits + , typename packed_options::size_type + , (std::size_t(packed_options::linear)*slist_bool_flags::linear_pos) + |(std::size_t(packed_options::constant_time_size)*slist_bool_flags::constant_time_size_pos) + |(std::size_t(packed_options::cache_last)*slist_bool_flags::cache_last_pos) + , header_holder_type > implementation_defined; /// @endcond typedef implementation_defined type; @@ -2070,14 +2204,14 @@ struct make_slist #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4, class O5> +template<class T, class O1, class O2, class O3, class O4, class O5, class O6> #else template<class T, class ...Options> #endif class slist : public make_slist<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5 + O1, O2, O3, O4, O5, O6 #else Options... #endif @@ -2086,25 +2220,33 @@ class slist typedef typename make_slist <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5 + O1, O2, O3, O4, O5, O6 #else Options... #endif >::type Base; - typedef typename Base::real_value_traits real_value_traits; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value)); BOOST_MOVABLE_BUT_NOT_COPYABLE(slist) public: typedef typename Base::value_traits value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::size_type size_type; + typedef typename Base::node_ptr node_ptr; - slist(const value_traits &v_traits = value_traits()) + explicit slist(const value_traits &v_traits = value_traits()) : Base(v_traits) {} + struct incorporate_t{}; + + slist( const node_ptr & f, const node_ptr & before_l + , size_type n, const value_traits &v_traits = value_traits()) + : Base(f, before_l, n, v_traits) + {} + template<class Iterator> slist(Iterator b, Iterator e, const value_traits &v_traits = value_traits()) : Base(b, e, v_traits) @@ -2115,7 +2257,7 @@ class slist {} slist& operator=(BOOST_RV_REF(slist) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<slist &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static slist &container_from_end_iterator(iterator end_iterator) { return static_cast<slist &>(Base::container_from_end_iterator(end_iterator)); } diff --git a/boost/intrusive/slist_hook.hpp b/boost/intrusive/slist_hook.hpp index cd94a7e7aa..18b59ed792 100644 --- a/boost/intrusive/slist_hook.hpp +++ b/boost/intrusive/slist_hook.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,9 +14,13 @@ #ifndef BOOST_INTRUSIVE_SLIST_HOOK_HPP #define BOOST_INTRUSIVE_SLIST_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/detail/slist_node.hpp> #include <boost/intrusive/circular_slist_algorithms.hpp> #include <boost/intrusive/link_mode.hpp> @@ -26,21 +30,12 @@ namespace boost { namespace intrusive { -/// @cond -template<class VoidPointer> -struct get_slist_node_algo -{ - typedef circular_slist_algorithms<slist_node_traits<VoidPointer> > type; -}; - -/// @endcond - //! Helper metafunction to define a \c slist_base_hook that yields to the same //! type when the same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_slist_base_hook { @@ -54,11 +49,11 @@ struct make_slist_base_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_slist_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < circular_slist_algorithms<slist_node_traits<typename packed_options::void_pointer> > , typename packed_options::tag , packed_options::link_mode - , detail::SlistBaseHook + , SlistBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -80,7 +75,7 @@ struct make_slist_base_hook //! \c auto_unlink or \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else @@ -168,7 +163,7 @@ class slist_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none> +template<class O1 = void, class O2 = void, class O3 = void> #endif struct make_slist_member_hook { @@ -182,11 +177,11 @@ struct make_slist_member_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_slist_node_algo<typename packed_options::void_pointer> + typedef generic_hook + < circular_slist_algorithms<slist_node_traits<typename packed_options::void_pointer> > , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -203,7 +198,7 @@ struct make_slist_member_hook //! \c auto_unlink or \c safe_link). //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else diff --git a/boost/intrusive/splay_set.hpp b/boost/intrusive/splay_set.hpp index e7f3b9470b..cefc7926a2 100644 --- a/boost/intrusive/splay_set.hpp +++ b/boost/intrusive/splay_set.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,12 +12,16 @@ #ifndef BOOST_INTRUSIVE_SPLAY_SET_HPP #define BOOST_INTRUSIVE_SPLAY_SET_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/splaytree.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/move/move.hpp> -#include <iterator> +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { @@ -36,14 +40,15 @@ namespace intrusive { #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class splay_set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public splaytree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, HeaderHolder> +#endif { /// @cond - typedef splaytree_impl<Config> tree_type; - //! This class is - //! movable + typedef splaytree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(splay_set_impl) typedef tree_type implementation_defined; @@ -71,1233 +76,408 @@ class splay_set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare object throws. - splay_set_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::splaytree::splaytree(const value_compare &,const value_traits &) + explicit splay_set_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty splay_set and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise amortized N * log N, where N is std::distance(last, first). - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::splaytree::splaytree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> splay_set_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(true, b, e, cmp, v_traits) + : tree_type(true, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::splaytree::splaytree(splaytree &&) splay_set_impl(BOOST_RV_REF(splay_set_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::splaytree::operator=(splaytree &&) splay_set_impl& operator=(BOOST_RV_REF(splay_set_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the splay_set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~splay_set_impl() - {} + { return static_cast<splay_set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::splaytree::~splaytree() + ~splay_set_impl(); + + //! @copydoc ::boost::intrusive::splaytree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::splaytree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::splaytree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::splaytree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::splaytree::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of splay_set. - //! - //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static splay_set_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<splay_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &splay_set_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of splay_set. - //! - //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const splay_set_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<splay_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &splay_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static splay_set_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<splay_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &splay_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const splay_set_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<splay_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &splay_set_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the splay_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the splay_set. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two splay_sets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(splay_set_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::splaytree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::splaytree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::splaytree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::splaytree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::splaytree::container_from_end_iterator(iterator) + static splay_set_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::splaytree::container_from_end_iterator(const_iterator) + static const splay_set_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::splaytree::container_from_iterator(iterator) + static splay_set_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::splaytree::container_from_iterator(const_iterator) + static const splay_set_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::splaytree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::splaytree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::splaytree::empty()const + bool empty() const; + + //! @copydoc ::boost::intrusive::splaytree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::splaytree::swap + void swap(splay_set_impl& other); + + //! @copydoc ::boost::intrusive::splaytree::clone_from template <class Cloner, class Disposer> - void clone_from(const splay_set_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to inserts value into the splay_set. - //! - //! <b>Returns</b>: If the value - //! is not already present inserts it and returns a pair containing the - //! iterator to the new value and true. If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const splay_set_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::splaytree::insert_unique(reference) std::pair<iterator, bool> insert(reference value) - { return tree_.insert_unique(value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to to insert x into the splay_set, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the - //! new element was inserted into the splay_set. - //! - //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique(value); } + + //! @copydoc ::boost::intrusive::splaytree::insert_unique(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_unique(hint, value); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the splay_set. + { return tree_type::insert_unique(hint, value); } + + //! @copydoc ::boost::intrusive::splaytree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(key, key_value_comp, commit_data); } - - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the splay_set. + { return tree_type::insert_unique_check(key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::splaytree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_check (const_iterator hint, const KeyType &key ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); } - - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the splay_set between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the splay_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return tree_.insert_unique_commit(value, commit_data); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the splay_set. - //! - //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_unique_check(hint, key, key_value_comp, commit_data); } + + //! @copydoc ::boost::intrusive::splaytree::insert_unique(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_unique(b, e); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is amortized - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size()) + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_unique(b, e); } + + //! @copydoc ::boost::intrusive::splaytree::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::splaytree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::splaytree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::splaytree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). Basic guarantee. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::clear + void clear(); + + //! @copydoc ::boost::intrusive::splaytree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) - { return tree_.find(value) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + void clear_and_dispose(Disposer disposer); + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::splaytree::count(const_reference)const + size_type count(const_reference value) const + { return static_cast<size_type>(this->tree_type::find(value) != this->tree_type::cend()); } + + //! @copydoc ::boost::intrusive::splaytree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count_dont_splay(const_reference value)const - { return tree_.find_dont_splay(value) != end(); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + size_type count(const KeyType& key, KeyValueCompare comp) const + { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::splaytree::count(const_reference)const + size_type count(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count_dont_splay(const KeyType& key, KeyValueCompare comp)const - { return tree_.find_dont_splay(key, comp) != end(); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound_dont_splay(const_reference value) const - { return tree_.lower_bound_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound_dont_splay(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound_dont_splay(const_reference value) const - { return tree_.upper_bound_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound_dont_splay(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find_dont_splay(const_reference value) const - { return tree_.find_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.find_dont_splay(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + { return this->tree_type::lower_bound_range(key, comp); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const_reference value) const - { return tree_.equal_range_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + equal_range(const_reference value) const + { return this->tree_type::lower_bound_range(value); } + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range_dont_splay(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const + { return this->tree_type::lower_bound_range(key, comp); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator, const_iterator> - bounded_range_dont_splay_dont_splay - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range_dont_splay(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range_dont_splay - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range_dont_splay(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! splay_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! splay_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a splay_set/multisplay_set. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Requires</b>: i must be a valid iterator of *this. - //! - //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i - //! is placed as the root of the tree, improving future searches of this value. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - void splay_up(iterator i) - { tree_.splay_up(i); } - - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element - //! with a key equivalent to value the element is placed as the root of the - //! tree. If the element is not present returns the last node compared with the key. - //! If the tree is empty, end() is returned. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty. - //! - //! <b>Throws</b>: If the comparison functor throws. - template<class KeyType, class KeyNodePtrCompare> - iterator splay_down(const KeyType &key, KeyNodePtrCompare comp) - { return tree_.splay_down(key, comp); } - - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element - //! with a key equivalent to value the element is placed as the root of the - //! tree. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty. - //! - //! <b>Throws</b>: If the predicate throws. - iterator splay_down(const value_type &value) - { return tree_.splay_down(value); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const splay_set_impl &x, const splay_set_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::splaytree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const splay_set_impl &x, const splay_set_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::splaytree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::splaytree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::splaytree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::splaytree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::splaytree::remove_node + void remove_node(reference value); + + //! @copydoc ::boost::intrusive::splaytree::splay_up(iterator) + void splay_up(iterator i); + + //! @copydoc ::boost::intrusive::splaytree::splay_down(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator splay_down(const KeyType &key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::splay_down(const_reference) + iterator splay_down(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::rebalance + void rebalance(); + + //! @copydoc ::boost::intrusive::splaytree::rebalance_subtree + iterator rebalance_subtree(iterator root); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y) -#else -(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y) -#else -(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y) -#else -(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y) -#else -(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(splay_set_impl<T, Options...> &x, splay_set_impl<T, Options...> &y) -#else -(splay_set_impl<Config> &x, splay_set_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(splay_set_impl<T, Options...> &x, splay_set_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c splay_set that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_splay_set { /// @cond + typedef typename pack_options + < splaytree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef splay_set_impl - < typename make_splaytree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class splay_set : public make_splay_set<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type { typedef typename make_splay_set <T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type Base; - BOOST_MOVABLE_BUT_NOT_COPYABLE(splay_set) + BOOST_MOVABLE_BUT_NOT_COPYABLE(splay_set) public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; @@ -1307,8 +487,8 @@ class splay_set //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - splay_set( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splay_set( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -1324,7 +504,7 @@ class splay_set {} splay_set& operator=(BOOST_RV_REF(splay_set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<splay_set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static splay_set &container_from_end_iterator(iterator end_iterator) { return static_cast<splay_set &>(Base::container_from_end_iterator(end_iterator)); } @@ -1355,14 +535,16 @@ class splay_set #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class splay_multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public splaytree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, HeaderHolder> +#endif { /// @cond - typedef splaytree_impl<Config> tree_type; + typedef splaytree_impl<ValueTraits, Compare, SizeType, ConstantTimeSize, HeaderHolder> tree_type; - //Movable BOOST_MOVABLE_BUT_NOT_COPYABLE(splay_multiset_impl) typedef tree_type implementation_defined; /// @endcond @@ -1389,1111 +571,341 @@ class splay_multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = tree_type::constant_time_size; public: - //! <b>Effects</b>: Constructs an empty splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. - splay_multiset_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, v_traits) + //! @copydoc ::boost::intrusive::splaytree::splaytree(const value_compare &,const value_traits &) + explicit splay_multiset_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty splay_multiset and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise amortized N * log N, where N is the distance between first and last. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. + //! @copydoc ::boost::intrusive::splaytree::splaytree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> splay_multiset_impl( Iterator b, Iterator e , const value_compare &cmp = value_compare() , const value_traits &v_traits = value_traits()) - : tree_(false, b, e, cmp, v_traits) + : tree_type(false, b, e, cmp, v_traits) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::splaytree::splaytree(splaytree &&) splay_multiset_impl(BOOST_RV_REF(splay_multiset_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::splaytree::operator=(splaytree &&) splay_multiset_impl& operator=(BOOST_RV_REF(splay_multiset_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~splay_multiset_impl() - {} + { return static_cast<splay_multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::splaytree::~splaytree() + ~splay_multiset_impl(); + + //! @copydoc ::boost::intrusive::splaytree::begin() + iterator begin(); + + //! @copydoc ::boost::intrusive::splaytree::begin()const + const_iterator begin() const; + + //! @copydoc ::boost::intrusive::splaytree::cbegin()const + const_iterator cbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::end() + iterator end(); + + //! @copydoc ::boost::intrusive::splaytree::end()const + const_iterator end() const; + + //! @copydoc ::boost::intrusive::splaytree::cend()const + const_iterator cend() const; + + //! @copydoc ::boost::intrusive::splaytree::rbegin() + reverse_iterator rbegin(); + + //! @copydoc ::boost::intrusive::splaytree::rbegin()const + const_reverse_iterator rbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::crbegin()const + const_reverse_iterator crbegin() const; + + //! @copydoc ::boost::intrusive::splaytree::rend() + reverse_iterator rend(); + + //! @copydoc ::boost::intrusive::splaytree::rend()const + const_reverse_iterator rend() const; + + //! @copydoc ::boost::intrusive::splaytree::crend()const + const_reverse_iterator crend() const; + + //! @copydoc ::boost::intrusive::splaytree::container_from_end_iterator(iterator) + static splay_multiset_impl &container_from_end_iterator(iterator end_iterator); + + //! @copydoc ::boost::intrusive::splaytree::container_from_end_iterator(const_iterator) + static const splay_multiset_impl &container_from_end_iterator(const_iterator end_iterator); + + //! @copydoc ::boost::intrusive::splaytree::container_from_iterator(iterator) + static splay_multiset_impl &container_from_iterator(iterator it); + + //! @copydoc ::boost::intrusive::splaytree::container_from_iterator(const_iterator) + static const splay_multiset_impl &container_from_iterator(const_iterator it); + + //! @copydoc ::boost::intrusive::splaytree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::splaytree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::splaytree::empty()const + bool empty() const; - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } - - //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } - - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } - - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } - - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } - - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of splay_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static splay_multiset_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<splay_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &splay_multiset_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of splay_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const splay_multiset_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<splay_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &splay_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static splay_multiset_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<splay_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &splay_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const splay_multiset_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<splay_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &splay_multiset_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns the value_compare object used by the splay_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } - - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } - - //! <b>Effects</b>: Returns the number of elements stored in the splay_multiset. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } - - //! <b>Effects</b>: Swaps the contents of two splay_multisets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(splay_multiset_impl& other) - { tree_.swap(other.tree_); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + //! @copydoc ::boost::intrusive::splaytree::size()const + size_type size() const; + + //! @copydoc ::boost::intrusive::splaytree::swap + void swap(splay_multiset_impl& other); + + //! @copydoc ::boost::intrusive::splaytree::clone_from template <class Cloner, class Disposer> - void clone_from(const splay_multiset_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the splay_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + void clone_from(const splay_multiset_impl &src, Cloner cloner, Disposer disposer); + + #endif //#ifdef BOOST_iNTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::splaytree::insert_equal(reference) iterator insert(reference value) - { return tree_.insert_equal(this->end(), value); } - - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts x into the splay_multiset, using pos as a hint to - //! where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(value); } + + //! @copydoc ::boost::intrusive::splaytree::insert_equal(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_equal(hint, value); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the splay_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + { return tree_type::insert_equal(hint, value); } + + //! @copydoc ::boost::intrusive::splaytree::insert_equal(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_equal(b, e); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } - - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is amortized - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } - - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } - - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + { tree_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::splaytree::insert_before + iterator insert_before(const_iterator pos, reference value); + + //! @copydoc ::boost::intrusive::splaytree::push_back + void push_back(reference value); + + //! @copydoc ::boost::intrusive::splaytree::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::splaytree::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is amortized - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + size_type erase_and_dispose(const_reference value, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::clear + void clear(); + + //! @copydoc ::boost::intrusive::splaytree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) - { return tree_.count(value); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. - template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) - { return tree_.count(key, comp); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count_dont_splay(const_reference value) const - { return tree_.count_dont_splay(value); } - - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + void clear_and_dispose(Disposer disposer); + + //! @copydoc ::boost::intrusive::splaytree::count(const_reference) + size_type count(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.count_dont_splay(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } - - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound_dont_splay(const_reference value) const - { return tree_.lower_bound_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator lower_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound_dont_splay(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const_reference) + iterator upper_bound(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound_dont_splay(const_reference value) const - { return tree_.upper_bound_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator upper_bound(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound_dont_splay(key, comp); } - - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::find(const_reference) + iterator find(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } - - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find_dont_splay(const_reference value) const - { return tree_.find_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + iterator find(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::find(const_reference)const + const_iterator find(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.find_dont_splay(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + const_iterator find(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } - - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const_reference value) const - { return tree_.equal_range_dont_splay(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + equal_range(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range_dont_splay(key, comp); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + equal_range(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator, const_iterator> - bounded_range_dont_splay - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range_dont_splay(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::splaytree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range_dont_splay - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range_dont_splay(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } - - //! <b>Requires</b>: value shall not be in a set/splay_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } - - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Requires</b>: i must be a valid iterator of *this. - //! - //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i - //! is placed as the root of the tree, improving future searches of this value. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - void splay_up(iterator i) - { tree_.splay_up(i); } - - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element - //! with a key equivalent to value the element is placed as the root of the - //! tree. If the element is not present returns the last node compared with the key. - //! If the tree is empty, end() is returned. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty. - //! - //! <b>Throws</b>: If the comparison functor throws. - template<class KeyType, class KeyNodePtrCompare> - iterator splay_down(const KeyType &key, KeyNodePtrCompare comp) - { return tree_.splay_down(key, comp); } - - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element - //! with a key equivalent to value the element is placed as the root of the - //! tree. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty. - //! - //! <b>Throws</b>: If the predicate throws. - iterator splay_down(const value_type &value) - { return tree_.splay_down(value); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - /// @cond - friend bool operator==(const splay_multiset_impl &x, const splay_multiset_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::splaytree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - friend bool operator<(const splay_multiset_impl &x, const splay_multiset_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + //! @copydoc ::boost::intrusive::splaytree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::splaytree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::splaytree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::splaytree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::splaytree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::splaytree::remove_node + void remove_node(reference value); + + //! @copydoc ::boost::intrusive::splaytree::splay_up(iterator) + void splay_up(iterator i); + + //! @copydoc ::boost::intrusive::splaytree::splay_down(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + iterator splay_down(const KeyType &key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::splaytree::splay_down(const_reference) + iterator splay_down(const_reference value); + + //! @copydoc ::boost::intrusive::splaytree::rebalance + void rebalance(); + + //! @copydoc ::boost::intrusive::splaytree::rebalance_subtree + iterator rebalance_subtree(iterator root); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y) -#else -(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y) -#else -(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y) -#else -(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y) -#else -(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(splay_multiset_impl<T, Options...> &x, splay_multiset_impl<T, Options...> &y) -#else -(splay_multiset_impl<Config> &x, splay_multiset_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(splay_multiset_impl<T, Options...> &x, splay_multiset_impl<T, Options...> &y); + +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c splay_multiset that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_splay_multiset { /// @cond + typedef typename pack_options + < splaytree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef splay_multiset_impl - < typename make_splaytree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -2501,27 +913,27 @@ struct make_splay_multiset #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class splay_multiset : public make_splay_multiset<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type { - typedef typename make_splay_multiset - <T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + typedef typename make_splay_multiset<T, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type Base; + BOOST_MOVABLE_BUT_NOT_COPYABLE(splay_multiset) public: @@ -2533,8 +945,8 @@ class splay_multiset //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - splay_multiset( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splay_multiset( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} @@ -2550,7 +962,7 @@ class splay_multiset {} splay_multiset& operator=(BOOST_RV_REF(splay_multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<splay_multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static splay_multiset &container_from_end_iterator(iterator end_iterator) { return static_cast<splay_multiset &>(Base::container_from_end_iterator(end_iterator)); } diff --git a/boost/intrusive/splay_set_hook.hpp b/boost/intrusive/splay_set_hook.hpp deleted file mode 100644 index c8698c65b0..0000000000 --- a/boost/intrusive/splay_set_hook.hpp +++ /dev/null @@ -1,292 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 -// -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) -// -// See http://www.boost.org/libs/intrusive for documentation. -// -///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP -#define BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP - -#include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_node.hpp> -#include <boost/intrusive/splaytree_algorithms.hpp> -#include <boost/intrusive/options.hpp> -#include <boost/intrusive/detail/generic_hook.hpp> - -namespace boost { -namespace intrusive { - -/// @cond -template<class VoidPointer> -struct get_splay_set_node_algo -{ - typedef splaytree_algorithms<tree_node_traits<VoidPointer> > type; -}; -/// @endcond - -//! Helper metafunction to define a \c splay_set_base_hook that yields to the same -//! type when the same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class ...Options> -#else -template<class O1 = none, class O2 = none, class O3 = none> -#endif -struct make_splay_set_base_hook -{ - /// @cond - typedef typename pack_options - < hook_defaults, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 - #else - Options... - #endif - >::type packed_options; - - typedef detail::generic_hook - < get_splay_set_node_algo<typename packed_options::void_pointer> - , typename packed_options::tag - , packed_options::link_mode - , detail::SplaySetBaseHook - > implementation_defined; - /// @endcond - typedef implementation_defined type; -}; - -//! Derive a class from splay_set_base_hook in order to store objects in -//! in a splay_set/splay_multiset. splay_set_base_hook holds the data necessary to maintain -//! the splay_set/splay_multiset and provides an appropriate value_traits class for splay_set/splay_multiset. -//! -//! The hook admits the following options: \c tag<>, \c void_pointer<>, -//! \c link_mode<> and \c optimize_size<>. -//! -//! \c tag<> defines a tag to identify the node. -//! The same tag value can be used in different classes, but if a class is -//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its -//! unique tag. -//! -//! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. -//! -//! \c link_mode<> will specify the linking mode of the hook (\c normal_link, -//! \c auto_unlink or \c safe_link). -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class ...Options> -#else -template<class O1, class O2, class O3> -#endif -class splay_set_base_hook - : public make_splay_set_base_hook< - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 - #else - Options... - #endif - >::type -{ - #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) - public: - //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link - //! initializes the node to an unlinked state. - //! - //! <b>Throws</b>: Nothing. - splay_set_base_hook(); - - //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link - //! initializes the node to an unlinked state. The argument is ignored. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Rationale</b>: Providing a copy-constructor - //! makes classes using the hook STL-compliant without forcing the - //! user to do some additional work. \c swap can be used to emulate - //! move-semantics. - splay_set_base_hook(const splay_set_base_hook& ); - - //! <b>Effects</b>: Empty function. The argument is ignored. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Rationale</b>: Providing an assignment operator - //! makes classes using the hook STL-compliant without forcing the - //! user to do some additional work. \c swap can be used to emulate - //! move-semantics. - splay_set_base_hook& operator=(const splay_set_base_hook& ); - - //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does - //! nothing (ie. no code is generated). If link_mode is \c safe_link and the - //! object is stored in a set an assertion is raised. If link_mode is - //! \c auto_unlink and \c is_linked() is true, the node is unlinked. - //! - //! <b>Throws</b>: Nothing. - ~splay_set_base_hook(); - - //! <b>Effects</b>: Swapping two nodes swaps the position of the elements - //! related to those nodes in one or two containers. That is, if the node - //! this is part of the element e1, the node x is part of the element e2 - //! and both elements are included in the containers s1 and s2, then after - //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 - //! at the position of e1. If one element is not in a container, then - //! after the swap-operation the other element is not in a container. - //! Iterators to e1 and e2 related to those nodes are invalidated. - //! - //! <b>Complexity</b>: Constant - //! - //! <b>Throws</b>: Nothing. - void swap_nodes(splay_set_base_hook &other); - - //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink. - //! - //! <b>Returns</b>: true, if the node belongs to a container, false - //! otherwise. This function can be used to test whether \c set::iterator_to - //! will return a valid iterator. - //! - //! <b>Complexity</b>: Constant - bool is_linked() const; - - //! <b>Effects</b>: Removes the node if it's inserted in a container. - //! This function is only allowed if link_mode is \c auto_unlink. - //! - //! <b>Throws</b>: Nothing. - void unlink(); - #endif -}; - -//! Helper metafunction to define a \c splay_set_member_hook that yields to the same -//! type when the same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class ...Options> -#else -template<class O1 = none, class O2 = none, class O3 = none> -#endif -struct make_splay_set_member_hook -{ - /// @cond - typedef typename pack_options - < hook_defaults, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 - #else - Options... - #endif - >::type packed_options; - - typedef detail::generic_hook - < get_splay_set_node_algo<typename packed_options::void_pointer> - , member_tag - , packed_options::link_mode - , detail::NoBaseHook - > implementation_defined; - /// @endcond - typedef implementation_defined type; -}; - -//! Put a public data member splay_set_member_hook in order to store objects of this -//! class in a splay_set/splay_multiset. splay_set_member_hook holds the data -//! necessary for maintaining the splay_set/splay_multiset and provides an appropriate -//! value_traits class for splay_set/splay_multiset. -//! -//! The hook admits the following options: \c void_pointer<>, -//! \c link_mode<> and \c optimize_size<>. -//! -//! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. -//! -//! \c link_mode<> will specify the linking mode of the hook (\c normal_link, -//! \c auto_unlink or \c safe_link). -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class ...Options> -#else -template<class O1, class O2, class O3> -#endif -class splay_set_member_hook - : public make_splay_set_member_hook< - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3 - #else - Options... - #endif - >::type -{ - #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) - public: - //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link - //! initializes the node to an unlinked state. - //! - //! <b>Throws</b>: Nothing. - splay_set_member_hook(); - - //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link - //! initializes the node to an unlinked state. The argument is ignored. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Rationale</b>: Providing a copy-constructor - //! makes classes using the hook STL-compliant without forcing the - //! user to do some additional work. \c swap can be used to emulate - //! move-semantics. - splay_set_member_hook(const splay_set_member_hook& ); - - //! <b>Effects</b>: Empty function. The argument is ignored. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Rationale</b>: Providing an assignment operator - //! makes classes using the hook STL-compliant without forcing the - //! user to do some additional work. \c swap can be used to emulate - //! move-semantics. - splay_set_member_hook& operator=(const splay_set_member_hook& ); - - //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does - //! nothing (ie. no code is generated). If link_mode is \c safe_link and the - //! object is stored in a set an assertion is raised. If link_mode is - //! \c auto_unlink and \c is_linked() is true, the node is unlinked. - //! - //! <b>Throws</b>: Nothing. - ~splay_set_member_hook(); - - //! <b>Effects</b>: Swapping two nodes swaps the position of the elements - //! related to those nodes in one or two containers. That is, if the node - //! this is part of the element e1, the node x is part of the element e2 - //! and both elements are included in the containers s1 and s2, then after - //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1 - //! at the position of e1. If one element is not in a container, then - //! after the swap-operation the other element is not in a container. - //! Iterators to e1 and e2 related to those nodes are invalidated. - //! - //! <b>Complexity</b>: Constant - //! - //! <b>Throws</b>: Nothing. - void swap_nodes(splay_set_member_hook &other); - - //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink. - //! - //! <b>Returns</b>: true, if the node belongs to a container, false - //! otherwise. This function can be used to test whether \c set::iterator_to - //! will return a valid iterator. - //! - //! <b>Complexity</b>: Constant - bool is_linked() const; - - //! <b>Effects</b>: Removes the node if it's inserted in a container. - //! This function is only allowed if link_mode is \c auto_unlink. - //! - //! <b>Throws</b>: Nothing. - void unlink(); - #endif -}; - -} //namespace intrusive -} //namespace boost - -#include <boost/intrusive/detail/config_end.hpp> - -#endif //BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP diff --git a/boost/intrusive/splaytree.hpp b/boost/intrusive/splaytree.hpp index a1c5209dc1..67046426c8 100644 --- a/boost/intrusive/splaytree.hpp +++ b/boost/intrusive/splaytree.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,54 +12,42 @@ #ifndef BOOST_INTRUSIVE_SPLAYTREE_HPP #define BOOST_INTRUSIVE_SPLAYTREE_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> +#include <cstddef> #include <functional> -#include <iterator> #include <utility> -#include <cstddef> -#include <algorithm> -#include <boost/intrusive/detail/assert.hpp> + #include <boost/static_assert.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/splay_set_hook.hpp> +#include <boost/intrusive/bstree.hpp> #include <boost/intrusive/detail/tree_node.hpp> -#include <boost/intrusive/detail/ebo_functor_holder.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/intrusive/detail/utilities.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/options.hpp> +#include <boost/intrusive/detail/function_detector.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> #include <boost/intrusive/splaytree_algorithms.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/move/move.hpp> - +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> +#include <boost/move/utility_core.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize> -struct splaysetopt +struct splaytree_defaults { - typedef ValueTraits value_traits; - typedef Compare compare; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; + typedef default_bstree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + typedef void header_holder_type; }; -template <class T> -struct splay_set_defaults - : pack_options - < none - , base_hook<detail::default_splay_set_hook> - , constant_time_size<true> - , size_type<std::size_t> - , compare<std::less<T> > - >::type -{}; - /// @endcond //! The class template splaytree is an intrusive splay tree container that @@ -78,1261 +66,386 @@ struct splay_set_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class splaytree_impl - : private detail::clear_on_destructor_base<splaytree_impl<Config> > + /// @cond + : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, SplayTreeAlgorithms, HeaderHolder> + /// @endcond { - template<class C> friend class detail::clear_on_destructor_base; public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; + typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType + , ConstantTimeSize, SplayTreeAlgorithms + , HeaderHolder> tree_type; + typedef tree_type implementation_defined; /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - typedef typename pointer_traits<pointer>::element_type value_type; - typedef typename pointer_traits<pointer>::reference reference; - typedef typename pointer_traits<const_pointer>::reference const_reference; - typedef typename pointer_traits<pointer>::difference_type difference_type; - typedef typename Config::size_type size_type; - typedef value_type key_type; - typedef typename Config::compare value_compare; - typedef value_compare key_compare; - typedef tree_iterator<splaytree_impl, false> iterator; - typedef tree_iterator<splaytree_impl, true> const_iterator; - typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; - typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <const node>::type const_node_ptr; - typedef splaytree_algorithms<node_traits> node_algorithms; - - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::key_type key_type; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef typename implementation_defined::node_algorithms node_algorithms; + + static const bool constant_time_size = implementation_defined::constant_time_size; /// @cond private: - typedef detail::size_holder<constant_time_size, size_type> size_traits; //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(splaytree_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; - - //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); - - struct header_plus_size : public size_traits - { node header_; }; - - struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare> - { - node_plus_pred_t(const value_compare &comp) - : detail::ebo_functor_holder<value_compare>(comp) - {} - header_plus_size header_plus_size_; - }; - - struct data_t : public splaytree_impl::value_traits - { - typedef typename splaytree_impl::value_traits value_traits; - data_t(const value_compare & comp, const value_traits &val_traits) - : value_traits(val_traits), node_plus_pred_(comp) - {} - node_plus_pred_t node_plus_pred_; - } data_; - - const value_compare &priv_comp() const - { return data_.node_plus_pred_.get(); } - - value_compare &priv_comp() - { return data_.node_plus_pred_.get(); } - - const value_traits &priv_value_traits() const - { return data_; } - - value_traits &priv_value_traits() - { return data_; } - - node_ptr priv_header_ptr() - { return pointer_traits<node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } - - const_node_ptr priv_header_ptr() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_size_.header_); } - - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - - size_traits &priv_size_traits() - { return data_.node_plus_pred_.header_plus_size_; } - - const size_traits &priv_size_traits() const - { return data_.node_plus_pred_.header_plus_size_; } - - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } - - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } - - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } - /// @endcond public: - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - typedef typename node_algorithms::insert_commit_data insert_commit_data; + typedef typename implementation_defined::insert_commit_data insert_commit_data; - //! <b>Effects</b>: Constructs an empty tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructorof the value_compare object throws. Basic guarantee. - splaytree_impl( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - } + //! @copydoc ::boost::intrusive::bstree::bstree(const value_compare &,const value_traits &) + explicit splaytree_impl( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) + {} - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. - //! cmp must be a comparison function that induces a strict weak ordering. - //! - //! <b>Effects</b>: Constructs an empty tree and inserts elements from - //! [b, e). - //! - //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise amortized N * log N, where N is the distance between first and last. - //! - //! <b>Throws</b>: If value_traits::node_traits::node - //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee. + //! @copydoc ::boost::intrusive::bstree::bstree(bool,Iterator,Iterator,const value_compare &,const value_traits &) template<class Iterator> - splaytree_impl ( bool unique, Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, v_traits) + splaytree_impl( bool unique, Iterator b, Iterator e + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits) { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); if(unique) this->insert_unique(b, e); else this->insert_equal(b, e); } - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) splaytree_impl(BOOST_RV_REF(splaytree_impl) x) - : data_(::boost::move(x.priv_comp()), ::boost::move(x.priv_value_traits())) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - this->swap(x); - } + : tree_type(::boost::move(static_cast<tree_type&>(x))) + {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) splaytree_impl& operator=(BOOST_RV_REF(splaytree_impl) x) - { this->swap(x); return *this; } - - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called), but the nodes according to - //! the value_traits template parameter are reinitialized and thus can be reused. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~splaytree_impl() - {} + { return static_cast<splaytree_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return iterator(node_algorithms::begin_node(this->priv_header_ptr()), this); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~splaytree_impl(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return cbegin(); } + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return const_iterator(node_algorithms::begin_node(this->priv_header_ptr()), this); } + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; - //! <b>Effects</b>: Returns an iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return iterator (this->priv_header_ptr(), this); } + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return cend(); } + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return const_iterator (uncast(this->priv_header_ptr()), this); } + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return const_reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return const_reverse_iterator(end()); } + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return const_reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return const_reverse_iterator(begin()); } + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of splaytree. - //! - //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static splaytree_impl &container_from_end_iterator(iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of splaytree. - //! - //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static splaytree_impl &container_from_end_iterator(iterator end_iterator); - //! <b>Precondition</b>: it must be a valid iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static splaytree_impl &container_from_iterator(iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator); - //! <b>Precondition</b>: it must be a valid end const_iterator - //! of rbtree. - //! - //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const splaytree_impl &container_from_iterator(const_iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static splaytree_impl &container_from_iterator(iterator it); - //! <b>Effects</b>: Returns the value_compare object used by the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return priv_comp(); } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const splaytree_impl &container_from_iterator(const_iterator it); - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return this->cbegin() == this->cend(); } + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; - //! <b>Effects</b>: Returns the number of elements stored in the tree. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { - if(constant_time_size){ - return this->priv_size_traits().get_size(); - } - else{ - return (size_type)node_algorithms::size(this->priv_header_ptr()); - } - } + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; - //! <b>Effects</b>: Swaps the contents of two splaytrees. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the comparison functor's swap call throws. - void swap(splaytree_impl& other) - { - //This can throw - using std::swap; - swap(priv_comp(), priv_comp()); - //These can't throw - node_algorithms::swap_tree(this->priv_header_ptr(), other.priv_header_ptr()); - if(constant_time_size){ - size_type backup = this->priv_size_traits().get_size(); - this->priv_size_traits().set_size(other.priv_size_traits().get_size()); - other.priv_size_traits().set_size(backup); - } - } + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree before the lower bound. - //! - //! <b>Complexity</b>: Average complexity for insert element is amortized - //! logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(reference value) - { - detail::key_nodeptr_comp<value_compare, splaytree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret (node_algorithms::insert_equal_lower_bound - (this->priv_header_ptr(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator. - //! - //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case) - //! - //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_equal(const_iterator hint, reference value) - { - detail::key_nodeptr_comp<value_compare, splaytree_impl> - key_node_comp(priv_comp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - iterator ret(node_algorithms::insert_equal - (this->priv_header_ptr(), hint.pointed_node(), to_insert, key_node_comp), this); - this->priv_size_traits().increment(); - return ret; - } + //! @copydoc ::boost::intrusive::bstree::swap + void swap(splaytree_impl& other); - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a each element of a range into the tree - //! before the upper bound of the key of each element. - //! - //! <b>Complexity</b>: Insert range is in general amortized O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - template<class Iterator> - void insert_equal(Iterator b, Iterator e) - { - if(this->empty()){ - iterator end(this->end()); - for (; b != e; ++b) - this->insert_equal(end, *b); - } - } + //! @copydoc ::boost::intrusive::bstree::clone_from + template <class Cloner, class Disposer> + void clone_from(const splaytree_impl &src, Cloner cloner, Disposer disposer); - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the tree if the value - //! is not already present. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - std::pair<iterator, bool> insert_unique(reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), commit_data); - if(!ret.second) - return ret; - return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true); - } + //! @copydoc ::boost::intrusive::bstree::insert_equal(reference) + iterator insert_equal(reference value); - //! <b>Requires</b>: value must be an lvalue, and "hint" must be - //! a valid iterator - //! - //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint - //! to where it will be inserted. - //! - //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized - //! constant time (two comparisons in the worst case) - //! if t is inserted immediately before hint. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. - iterator insert_unique(const_iterator hint, reference value) - { - insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), commit_data); - if(!ret.second) - return ret.first; - return insert_unique_commit(value, commit_data); - } + //! @copydoc ::boost::intrusive::bstree::insert_equal(const_iterator,reference) + iterator insert_equal(const_iterator hint, reference value); - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Tries to insert each element of a range into the tree. - //! - //! <b>Complexity</b>: Insert range is in general amortized O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::bstree::insert_equal(Iterator,Iterator) template<class Iterator> - void insert_unique(Iterator b, Iterator e) - { - for (; b != e; ++b) - this->insert_unique(*b); - } + void insert_equal(Iterator b, Iterator e); - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + //! @copydoc ::boost::intrusive::bstree::insert_unique(reference) + std::pair<iterator, bool> insert_unique(reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique(const_iterator,reference) + iterator insert_unique(const_iterator hint, reference value); + + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check - (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - (node_algorithms::insert_unique_check - (this->priv_header_ptr(), key, comp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } + (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data); - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. The difference is that - //! key_value_comp compares an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the container, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the container. + //! @copydoc ::boost::intrusive::bstree::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,insert_commit_data&) template<class KeyType, class KeyValueCompare> std::pair<iterator, bool> insert_unique_check (const_iterator hint, const KeyType &key - ,KeyValueCompare key_value_comp, insert_commit_data &commit_data) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - comp(key_value_comp, this); - std::pair<node_ptr, bool> ret = - node_algorithms::insert_unique_check - (this->priv_header_ptr(), hint.pointed_node(), key, comp, commit_data); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); - } + ,KeyValueCompare key_value_comp, insert_commit_data &commit_data); - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the container between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the avl_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) - { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::insert_unique_commit - (this->priv_header_ptr(), to_insert, commit_data); - this->priv_size_traits().increment(); - return iterator(to_insert, this); - } + //! @copydoc ::boost::intrusive::bstree::insert_unique_commit + iterator insert_unique_commit(reference value, const insert_commit_data &commit_data); - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { - const_iterator ret(i); - ++ret; - node_ptr to_erase(i.pointed_node()); - if(safemode_or_autounlink) - BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); - node_algorithms::erase(this->priv_header_ptr(), to_erase); - this->priv_size_traits().decrement(); - if(safemode_or_autounlink) - node_algorithms::init(to_erase); - return ret.unconst(); - } + //! @copydoc ::boost::intrusive::bstree::insert_unique(Iterator,Iterator) + template<class Iterator> + void insert_unique(Iterator b, Iterator e); - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is amortized - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { size_type n; return private_erase(b, e, n); } + //! @copydoc ::boost::intrusive::bstree::insert_before + iterator insert_before(const_iterator pos, reference value); - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return this->erase(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::push_back + void push_back(reference value); - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n); - return n; - } + //! @copydoc ::boost::intrusive::bstree::push_front + void push_front(reference value); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { - node_ptr to_erase(i.pointed_node()); - iterator ret(this->erase(i)); - disposer(get_real_value_traits().to_value_ptr(to_erase)); - return ret; - } + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::bstree::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::bstree::erase(const_reference) + size_type erase(const_reference value); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::bstree::erase(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + size_type erase(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is amortized - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { size_type n; return private_erase(b, e, n, disposer); } + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { - std::pair<iterator,iterator> p = this->equal_range(value); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } + size_type erase_and_dispose(const_reference value, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: Amortized O(log(size() + N). - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::bstree::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { - std::pair<iterator,iterator> p = this->equal_range(key, comp); - size_type n; - private_erase(p.first, p.second, n, disposer); - return n; - } + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); - //! <b>Effects</b>: Erases all of the elements. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { - if(safemode_or_autounlink){ - this->clear_and_dispose(detail::null_disposer()); - } - else{ - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - } + //! @copydoc ::boost::intrusive::bstree::clear + void clear(); - //! <b>Effects</b>: Erases all of the elements calling disposer(p) for - //! each node to be erased. - //! <b>Complexity</b>: Amortized O(log(size() + N)), - //! where N is the number of elements in the container. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. Calls N times to disposer functor. + //! @copydoc ::boost::intrusive::bstree::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { - node_algorithms::clear_and_dispose(this->priv_header_ptr() - , detail::node_disposer<Disposer, splaytree_impl>(disposer, this)); - this->priv_size_traits().set_size(0); - } + void clear_and_dispose(Disposer disposer); - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count(const_reference value) - { return this->count(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + //! Additional note: non-const function, splaying is performed. + size_type count(const_reference value); - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const + //! Additional note: non-const function, splaying is performed. template<class KeyType, class KeyValueCompare> - size_type count(const KeyType &key, KeyValueCompare comp) - { - std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); - return std::distance(ret.first, ret.second); - } + size_type count(const KeyType &key, KeyValueCompare comp); - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count_dont_splay(const_reference value) const - { return this->count_dont_splay(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + //! Additional note: const function, no splaying is performed + size_type count(const_reference value) const; - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const + //! Additional note: const function, no splaying is performed template<class KeyType, class KeyValueCompare> - size_type count_dont_splay(const KeyType &key, KeyValueCompare comp) const - { - std::pair<const_iterator, const_iterator> ret = this->equal_range_dont_splay(key, comp); - return std::distance(ret.first, ret.second); - } + size_type count(const KeyType &key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator lower_bound(const_reference value) - { return this->lower_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + //! Additional note: non-const function, splaying is performed. + iterator lower_bound(const_reference value); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator lower_bound_dont_splay(const_reference value) const - { return this->lower_bound_dont_splay(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + //! Additional note: const function, no splaying is performed + const_iterator lower_bound(const_reference value) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "key" template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + iterator lower_bound(const KeyType &key, KeyValueCompare comp); - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const + //! Additional note: const function, no splaying is performed template<class KeyType, class KeyValueCompare> - const_iterator lower_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp, false), this); - } + const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator upper_bound(const_reference value) - { return this->upper_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "value" + iterator upper_bound(const_reference value); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + //! Additional note: const function, no splaying is performed + const_iterator upper_bound(const_reference value) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator upper_bound_dont_splay(const_reference value) const - { return this->upper_bound_dont_splay(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "key" + template<class KeyType, class KeyValueCompare> + iterator upper_bound(const KeyType &key, KeyValueCompare comp); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const + //! Additional note: const function, no splaying is performed template<class KeyType, class KeyValueCompare> - const_iterator upper_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::upper_bound_dont_splay - (this->priv_header_ptr(), key, key_node_comp, false), this); - } + const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator find(const_reference value) - { return this->find(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "value" + iterator find(const_reference value); - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - template<class KeyType, class KeyValueCompare> - iterator find(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + //! Additional note: const function, no splaying is performed + const_iterator find(const_reference value) const; - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator find_dont_splay(const_reference value) const - { return this->find_dont_splay(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "key" + template<class KeyType, class KeyValueCompare> + iterator find(const KeyType &key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const + //! Additional note: const function, no splaying is performed template<class KeyType, class KeyValueCompare> - const_iterator find_dont_splay(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - return const_iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp, false), this); - } + const_iterator find(const KeyType &key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<iterator,iterator> equal_range(const_reference value) - { return this->equal_range(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "value" + std::pair<iterator, iterator> equal_range(const_reference value); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Amortized logarithmic. - //! - //! <b>Throws</b>: Nothing. - template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const + //! Additional note: const function, no splaying is performed + std::pair<const_iterator, const_iterator> equal_range(const_reference value) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const_reference value) const - { return this->equal_range_dont_splay(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) + //! Additional note: non-const function, splaying is performed for the first + //! element of the equal range of "key" + template<class KeyType, class KeyValueCompare> + std::pair<iterator, iterator> equal_range(const KeyType &key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const + //! Additional note: const function, no splaying is performed template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - equal_range_dont_splay(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp, false)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + std::pair<const_iterator, const_iterator> equal_range(const KeyType &key, KeyValueCompare comp) const; - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator,const_iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return this->bounded_range_dont_splay(lower_value, upper_value, priv_comp(), left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> bounded_range + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; + + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator,const_iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed, false)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const splaytree_impl &src, Cloner cloner, Disposer disposer) - { - this->clear_and_dispose(disposer); - if(!src.empty()){ - detail::exception_disposer<splaytree_impl, Disposer> - rollback(*this, disposer); - node_algorithms::clone - (src.priv_header_ptr() - ,this->priv_header_ptr() - ,detail::node_cloner<Cloner, splaytree_impl>(cloner, this) - ,detail::node_disposer<Disposer, splaytree_impl>(disposer, this)); - this->priv_size_traits().set_size(src.priv_size_traits().get_size()); - this->priv_comp() = src.priv_comp(); - rollback.release(); - } - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { - node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance - (this->priv_header_ptr())); - if(!to_be_disposed) - return 0; - this->priv_size_traits().decrement(); - if(safemode_or_autounlink)//If this is commented does not work with normal_link - node_algorithms::init(to_be_disposed); - return get_real_value_traits().to_value_ptr(to_be_disposed); - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); + + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; + + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); + + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); + + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); + + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Requires</b>: i must be a valid iterator of *this. //! - //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i + //! <b>Effects</b>: Rearranges the container so that the element pointed by i //! is placed as the root of the tree, improving future searches of this value. //! //! <b>Complexity</b>: Amortized logarithmic. //! //! <b>Throws</b>: Nothing. void splay_up(iterator i) - { return node_algorithms::splay_up(i.pointed_node(), this->priv_header_ptr()); } + { return node_algorithms::splay_up(i.pointed_node(), tree_type::header_ptr()); } - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element + //! <b>Effects</b>: Rearranges the container so that if *this stores an element //! with a key equivalent to value the element is placed as the root of the //! tree. If the element is not present returns the last node compared with the key. //! If the tree is empty, end() is returned. @@ -1345,13 +458,13 @@ class splaytree_impl template<class KeyType, class KeyValueCompare> iterator splay_down(const KeyType &key, KeyValueCompare comp) { - detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl> - key_node_comp(comp, this); - node_ptr r = node_algorithms::splay_down(this->priv_header_ptr(), key, key_node_comp); - return iterator(r, this); + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(comp, &this->get_value_traits()); + node_ptr r = node_algorithms::splay_down(tree_type::header_ptr(), key, key_node_comp); + return iterator(r, this->priv_value_traits_ptr()); } - //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element + //! <b>Effects</b>: Rearranges the container so that if *this stores an element //! with a key equivalent to value the element is placed as the root of the //! tree. //! @@ -1360,402 +473,127 @@ class splaytree_impl //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty. //! //! <b>Throws</b>: If the predicate throws. - iterator splay_down(const value_type &value) - { return this->splay_down(value, priv_comp()); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { - node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this) - , this->priv_header_ptr() - , get_real_value_traits().to_node_ptr(with_this)); - if(safemode_or_autounlink) - node_algorithms::init(replace_this.pointed_node()); - } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return iterator (value_traits::to_node_ptr(value), 0); - } + iterator splay_down(const_reference value) + { return this->splay_down(value, this->value_comp()); } - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); - } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::rebalance + void rebalance(); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return iterator (value_traits::to_node_ptr(value), this); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); } - - //! <b>Requires</b>: value shall not be in a tree. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { node_algorithms::init(value_traits::to_node_ptr(value)); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { node_algorithms::rebalance(this->priv_header_ptr()); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this); } - -/* - //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect, - //! if x is not in such a tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This static function is only usable with the "safe mode" - //! hook and non-constant time size lists. Otherwise, the user must use - //! the non-static "erase(reference )" member. If the user calls - //! this function with a non "safe mode" or constant time size list - //! a compilation error will be issued. - template<class T> - static void remove_node(T& value) - { - //This function is only usable for safe mode hooks and non-constant - //time lists. - //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size))); - BOOST_STATIC_ASSERT((!constant_time_size)); - BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value)); - node_ptr to_remove(value_traits::to_node_ptr(value)); - node_algorithms::unlink_and_rebalance(to_remove); - if(safemode_or_autounlink) - node_algorithms::init(to_remove); - } -*/ - - /// @cond - private: - template<class Disposer> - iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer) - { - for(n = 0; b != e; ++n) - this->erase_and_dispose(b++, disposer); - return b.unconst(); - } - - iterator private_erase(const_iterator b, const_iterator e, size_type &n) - { - for(n = 0; b != e; ++n) - this->erase(b++); - return b.unconst(); - } - /// @endcond - - private: - static splaytree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) - { - header_plus_size *r = detail::parent_from_member<header_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &header_plus_size::header_); - node_plus_pred_t *n = detail::parent_from_member - <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_); - data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_); - splaytree_impl *rb = detail::parent_from_member<splaytree_impl, data_t>(d, &splaytree_impl::data_); - return *rb; - } - - static splaytree_impl &priv_container_from_iterator(const const_iterator &it) - { return priv_container_from_end_iterator(it.end_iterator_from_it()); } + //! @copydoc ::boost::intrusive::bstree::rebalance_subtree + iterator rebalance_subtree(iterator root); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator< -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -bool operator== -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ - typedef splaytree_impl<Config> tree_type; - typedef typename tree_type::const_iterator const_iterator; - - if(tree_type::constant_time_size && x.size() != y.size()){ - return false; - } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } -} +bool operator< (const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator==(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ return y < x; } +bool operator!= (const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator>(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y) -#else -(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator<=(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(splaytree_impl<T, Options...> &x, splaytree_impl<T, Options...> &y) -#else -(splaytree_impl<Config> &x, splaytree_impl<Config> &y) -#endif -{ x.swap(y); } +bool operator>=(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y); -/// @cond - -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#else template<class T, class ...Options> -#endif -struct make_splaytree_opt -{ - typedef typename pack_options - < splay_set_defaults<T>, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type packed_options; - typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; +void swap(splaytree_impl<T, Options...> &x, splaytree_impl<T, Options...> &y); - typedef splaysetopt - < value_traits - , typename packed_options::compare - , typename packed_options::size_type - , packed_options::constant_time_size - > type; -}; -/// @endcond +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) //! Helper metafunction to define a \c splaytree that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_splaytree { /// @cond + typedef typename pack_options + < splaytree_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef splaytree_impl - < typename make_splaytree_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class splaytree : public make_splaytree<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type { typedef typename make_splaytree <T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif >::type Base; BOOST_MOVABLE_BUT_NOT_COPYABLE(splaytree) public: typedef typename Base::value_compare value_compare; typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::reverse_iterator reverse_iterator; + typedef typename Base::const_reverse_iterator const_reverse_iterator; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - splaytree( const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + explicit splaytree( const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, v_traits) {} template<class Iterator> splaytree( bool unique, Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const value_traits &v_traits = value_traits()) + , const value_compare &cmp = value_compare() + , const value_traits &v_traits = value_traits()) : Base(unique, b, e, cmp, v_traits) {} @@ -1764,18 +602,23 @@ class splaytree {} splaytree& operator=(BOOST_RV_REF(splaytree) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<splaytree &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static splaytree &container_from_end_iterator(iterator end_iterator) { return static_cast<splaytree &>(Base::container_from_end_iterator(end_iterator)); } static const splaytree &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const splaytree &>(Base::container_from_end_iterator(end_iterator)); } + + static splaytree &container_from_iterator(iterator it) + { return static_cast<splaytree &>(Base::container_from_iterator(it)); } + + static const splaytree &container_from_iterator(const_iterator it) + { return static_cast<const splaytree &>(Base::container_from_iterator(it)); } }; #endif - } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/splaytree_algorithms.hpp b/boost/intrusive/splaytree_algorithms.hpp index 8155648983..c49714a1d7 100644 --- a/boost/intrusive/splaytree_algorithms.hpp +++ b/boost/intrusive/splaytree_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -12,8 +12,9 @@ // The implementation of splay trees is based on the article and code published // in C++ Users Journal "Implementing Splay Trees in C++" (September 1, 2005). // -// The code has been modified and (supposely) improved by Ion Gaztanaga. -// Here is the header of the file used as base code: +// The splay code has been modified and (supposedly) improved by Ion Gaztanaga. +// +// Here is the copyright notice of the original file containing the splay code: // // splay_tree.h -- implementation of a STL compatible splay tree. // @@ -24,35 +25,23 @@ // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // -// Please send questions, comments, complaints, performance data, etc to -// ralf.mattethat@teknologisk.dk -// -// Requirements for element type -// * must be copy-constructible -// * destructor must not throw exception -// -// Methods marked with note A only throws an exception if the evaluation of the -// predicate throws an exception. If an exception is thrown the call has no -// effect on the containers state -// -// Methods marked with note B only throws an exception if the coppy constructor -// or assignment operator of the predicate throws an exception. If an exception -// is thrown the call has no effect on the containers state -// -// iterators are only invalidated, if the element pointed to by the iterator -// is deleted. The same goes for element references -// +///////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP #define BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> -#include <boost/intrusive/detail/assert.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/intrusive/pointer_traits.hpp> +#include <boost/intrusive/detail/assert.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/detail/uncast.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> + #include <cstddef> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> namespace boost { namespace intrusive { @@ -61,33 +50,70 @@ namespace intrusive { namespace detail { template<class NodeTraits> -struct splaydown_rollback +struct splaydown_assemble_and_fix_header { typedef typename NodeTraits::node_ptr node_ptr; - splaydown_rollback( const node_ptr *pcur_subtree, const node_ptr & header - , const node_ptr & leftmost , const node_ptr & rightmost) - : pcur_subtree_(pcur_subtree) , header_(header) - , leftmost_(leftmost) , rightmost_(rightmost) + + splaydown_assemble_and_fix_header(const node_ptr & t, const node_ptr & header, const node_ptr &leftmost, const node_ptr &rightmost) + : t_(t) + , null_node_(header) + , l_(null_node_) + , r_(null_node_) + , leftmost_(leftmost) + , rightmost_(rightmost) {} - void release() - { pcur_subtree_ = 0; } + ~splaydown_assemble_and_fix_header() + { + this->assemble(); + + //Now recover the original header except for the + //splayed root node. + //"t_" is the current root and "null_node_" is the header node + NodeTraits::set_parent(null_node_, t_); + NodeTraits::set_parent(t_, null_node_); + //Recover leftmost/rightmost pointers + NodeTraits::set_left (null_node_, leftmost_); + NodeTraits::set_right(null_node_, rightmost_); + } - ~splaydown_rollback() + private: + + void assemble() { - if(pcur_subtree_){ - //Exception can only be thrown by comp, but - //tree invariants still hold. *pcur_subtree is the current root - //so link it to the header. - NodeTraits::set_parent(*pcur_subtree_, header_); - NodeTraits::set_parent(header_, *pcur_subtree_); - //Recover leftmost/rightmost pointers - NodeTraits::set_left (header_, leftmost_); - NodeTraits::set_right(header_, rightmost_); + //procedure assemble; + // left(r), right(l) := right(t), left(t); + // left(t), right(t) := right(null), left(null); + //end assemble; + { // left(r), right(l) := right(t), left(t); + + node_ptr const old_t_left = NodeTraits::get_left(t_); + node_ptr const old_t_right = NodeTraits::get_right(t_); + NodeTraits::set_right(l_, old_t_left); + NodeTraits::set_left (r_, old_t_right); + if(old_t_left){ + NodeTraits::set_parent(old_t_left, l_); + } + if(old_t_right){ + NodeTraits::set_parent(old_t_right, r_); + } + } + { // left(t), right(t) := right(null), left(null); + node_ptr const null_right = NodeTraits::get_right(null_node_); + node_ptr const null_left = NodeTraits::get_left(null_node_); + NodeTraits::set_left (t_, null_right); + NodeTraits::set_right(t_, null_left); + if(null_right){ + NodeTraits::set_parent(null_right, t_); + } + if(null_left){ + NodeTraits::set_parent(null_left, t_); + } } } - const node_ptr *pcur_subtree_; - node_ptr header_, leftmost_, rightmost_; + + public: + node_ptr t_, null_node_, l_, r_, leftmost_, rightmost_; }; } //namespace detail { @@ -100,14 +126,14 @@ struct splaydown_rollback //! by Daniel Dominic Sleator and Robert Endre Tarjan //! AT&T Bell Laboratories, Murray Hill, NJ //! Journal of the ACM, Vol 32, no 3, July 1985, pp 652-686 - +//! //! splaytree_algorithms is configured with a NodeTraits class, which encapsulates the //! information about the node to be manipulated. NodeTraits must support the //! following interface: //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the binary search tree //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -128,10 +154,13 @@ struct splaydown_rollback //! <tt>static void set_right(node_ptr n, node_ptr right);</tt> template<class NodeTraits> class splaytree_algorithms + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_algorithms<NodeTraits> + #endif { /// @cond private: - typedef detail::tree_algorithms<NodeTraits> tree_algorithms; + typedef bstree_algorithms<NodeTraits> bstree_algo; /// @endcond public: @@ -142,611 +171,344 @@ class splaytree_algorithms //! This type is the information that will be //! filled by insert_unique_check - typedef typename tree_algorithms::insert_commit_data insert_commit_data; - - /// @cond - private: - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - /// @endcond + typedef typename bstree_algo::insert_commit_data insert_commit_data; public: - static node_ptr begin_node(const const_node_ptr & header) - { return tree_algorithms::begin_node(header); } - - static node_ptr end_node(const const_node_ptr & header) - { return tree_algorithms::end_node(header); } - - //! <b>Requires</b>: node is a node of the tree or an node initialized - //! by init(...). - //! - //! <b>Effects</b>: Returns true if the node is initialized by init(). - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - static bool unique(const const_node_ptr & node) - { return tree_algorithms::unique(node); } - - static void unlink(const node_ptr & node) - { tree_algorithms::unlink(node); } - - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & node2) - { - if(node1 == node2) - return; + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const const_node_ptr&) + static node_ptr get_header(const const_node_ptr & n); - node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2)); - swap_nodes(node1, header1, node2, header2); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::begin_node + static node_ptr begin_node(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::end_node + static node_ptr end_node(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree + static void swap_tree(const node_ptr & header1, const node_ptr & header2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & node2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&,const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink(const node_ptr&) + static void unlink(const node_ptr & node); - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees with header header1 and header2. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2) - { tree_algorithms::swap_nodes(node1, header1, node2, header2); } - - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance + static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::unique(const const_node_ptr&) + static bool unique(const const_node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::size(const const_node_ptr&) + static std::size_t size(const const_node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::next_node(const node_ptr&) + static node_ptr next_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(const node_ptr&) + static node_ptr prev_node(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::init(const node_ptr&) + static void init(const node_ptr & node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::init_header(const node_ptr&) + static void init_header(const node_ptr & header); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::erase(const node_ptr&,const node_ptr&) + //! Additional notes: the previous node of z is splayed to speed up range deletions. + static void erase(const node_ptr & header, const node_ptr & z) { - if(node_to_be_replaced == new_node) - return; - replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node); + //posibility 1 + if(NodeTraits::get_left(z)){ + splay_up(bstree_algo::prev_node(z), header); + } + /* + //possibility 2 + if(NodeTraits::get_left(z)){ + node_ptr l = NodeTraits::get_left(z); + splay_up(l, header); + }*/ + /* + if(NodeTraits::get_left(z)){ + node_ptr l = bstree_algo::prev_node(z); + splay_up_impl(l, z); + }*/ + /* + //possibility 4 + splay_up(z, header); + */ + bstree_algo::erase(header, z); } - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! with header "header" and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) - { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); } - - //! <b>Requires</b>: p is a node from the tree except the header. - //! - //! <b>Effects</b>: Returns the next node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr next_node(const node_ptr & p) - { return tree_algorithms::next_node(p); } - - //! <b>Requires</b>: p is a node from the tree except the leftmost node. - //! - //! <b>Effects</b>: Returns the previous node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr prev_node(const node_ptr & p) - { return tree_algorithms::prev_node(p); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: After the function unique(node) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init(const node_ptr & node) - { tree_algorithms::init(node); } - - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: Initializes the header to represent an empty tree. - //! unique(header) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init_header(const node_ptr & header) - { tree_algorithms::init_header(header); } - - //! <b>Requires</b>: "disposer" must be an object function - //! taking a node_ptr parameter and shouldn't throw. - //! - //! <b>Effects</b>: Empties the target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::clone(const const_node_ptr&,const node_ptr&,Cloner,Disposer) + template <class Cloner, class Disposer> + static void clone + (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer); + + //! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(const node_ptr&,Disposer) template<class Disposer> - static void clear_and_dispose(const node_ptr & header, Disposer disposer) - { tree_algorithms::clear_and_dispose(header, disposer); } - - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & node) - { return tree_algorithms::count(node); } - - //! <b>Requires</b>: header is the header node of the tree. - //! - //! <b>Effects</b>: Returns the number of nodes above the header. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t size(const const_node_ptr & header) - { return tree_algorithms::size(header); } - - //! <b>Requires</b>: header1 and header2 must be the header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two trees. After the function header1 will contain - //! links to the second tree and header2 will have links to the first tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static void swap_tree(const node_ptr & header1, const node_ptr & header2) - { return tree_algorithms::swap_tree(header1, header2); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "commit_data" must have been obtained from a previous call to - //! "insert_unique_check". No objects should have been inserted or erased - //! from the set between the "insert_unique_check" that filled "commit_data" - //! and the call to "insert_commit". - //! - //! - //! <b>Effects</b>: Inserts new_node in the set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - static void insert_unique_commit - (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data) - { tree_algorithms::insert_unique_commit(header, new_value, commit_data); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares KeyType with a node_ptr. - //! - //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the - //! tree according to "comp" and obtains the needed information to realize - //! a constant-time node insertion if there is no equivalent node. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing a node_ptr to the already present node - //! and false. If there is not equivalent key can be inserted returns true - //! in the returned pair's boolean and fills "commit_data" that is meant to - //! be used with the "insert_commit" function to achieve a constant-time - //! insertion function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a node is expensive and the user does not want to have two equivalent nodes - //! in the tree: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the node and this function offers the possibility to use that part - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the node and use - //! "insert_commit" to insert the node in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_unique_commit" only - //! if no more objects are inserted or erased from the set. + static void clear_and_dispose(const node_ptr & header, Disposer disposer); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional notes: an element with key `key` is splayed. template<class KeyType, class KeyNodePtrCompare> - static std::pair<node_ptr, bool> insert_unique_check - (const node_ptr & header, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) + static std::size_t count + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - splay_down(header, key, comp); - return tree_algorithms::insert_unique_check(header, key, comp, commit_data); + std::pair<node_ptr, node_ptr> ret = equal_range(header, key, comp); + std::size_t n = 0; + while(ret.first != ret.second){ + ++n; + ret.first = next_node(ret.first); + } + return n; } + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed template<class KeyType, class KeyNodePtrCompare> - static std::pair<node_ptr, bool> insert_unique_check - (const node_ptr & header, const node_ptr &hint, const KeyType &key - ,KeyNodePtrCompare comp, insert_commit_data &commit_data) + static std::size_t count + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::count(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional notes: the first node of the range is splayed. + template<class KeyType, class KeyNodePtrCompare> + static node_ptr lower_bound + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - splay_down(header, key, comp); - return tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data); + splay_down(detail::uncast(header), key, comp); + node_ptr y = bstree_algo::lower_bound(header, key, comp); + //splay_up(y, detail::uncast(header)); + return y; } - static bool is_header(const const_node_ptr & p) - { return tree_algorithms::is_header(p); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to - //! "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed + template<class KeyType, class KeyNodePtrCompare> + static node_ptr lower_bound + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::lower_bound(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional notes: the first node of the range is splayed. + template<class KeyType, class KeyNodePtrCompare> + static node_ptr upper_bound + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { + splay_down(detail::uncast(header), key, comp); + node_ptr y = bstree_algo::upper_bound(header, key, comp); + //splay_up(y, detail::uncast(header)); + return y; + } + + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed + template<class KeyType, class KeyNodePtrCompare> + static node_ptr upper_bound + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::upper_bound(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&, const KeyType&,KeyNodePtrCompare) + //! Additional notes: the found node of the lower bound is splayed. template<class KeyType, class KeyNodePtrCompare> static node_ptr find - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true) + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - if(splay) - splay_down(uncast(header), key, comp); - node_ptr end = uncast(header); - node_ptr y = lower_bound(header, key, comp, false); - node_ptr r = (y == end || comp(key, y)) ? end : y; - return r; + splay_down(detail::uncast(header), key, comp); + return bstree_algo::find(header, key, comp); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing - //! all elements that are equivalent to "key" according to "comp" or an - //! empty range that indicates the position where those elements would be - //! if they there are no equivalent elements. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&, const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed + template<class KeyType, class KeyNodePtrCompare> + static node_ptr find + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::find(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional notes: the first node of the range is splayed. template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> equal_range - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true) + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) { - //if(splay) - //splay_down(uncast(header), key, comp); - std::pair<node_ptr, node_ptr> ret = - tree_algorithms::equal_range(header, key, comp); + splay_down(detail::uncast(header), key, comp); + std::pair<node_ptr, node_ptr> ret = bstree_algo::equal_range(header, key, comp); + //splay_up(ret.first, detail::uncast(header)); + return ret; + } - if(splay) - splay_up(ret.first, uncast(header)); + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, node_ptr> equal_range + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::equal_range(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional notes: the first node of the range is splayed. + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, node_ptr> lower_bound_range + (const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { + splay_down(detail::uncast(header), key, comp); + std::pair<node_ptr, node_ptr> ret = bstree_algo::lower_bound_range(header, key, comp); + //splay_up(ret.first, detail::uncast(header)); return ret; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + //! Additional note: no splaying is performed + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, node_ptr> lower_bound_range + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + { return bstree_algo::lower_bound_range(header, key, comp); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) + //! Additional notes: the first node of the range is splayed. template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range - (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp - , bool left_closed, bool right_closed, bool splay = true) + (const node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp + , bool left_closed, bool right_closed) { + splay_down(detail::uncast(header), lower_key, comp); std::pair<node_ptr, node_ptr> ret = - tree_algorithms::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); - - if(splay) - splay_up(ret.first, uncast(header)); + bstree_algo::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); + //splay_up(ret.first, detail::uncast(header)); return ret; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is - //! not less than "key" according to "comp" or "header" if that element does - //! not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) + //! Additional note: no splaying is performed template<class KeyType, class KeyNodePtrCompare> - static node_ptr lower_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true) + static std::pair<node_ptr, node_ptr> bounded_range + (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp + , bool left_closed, bool right_closed) + { return bstree_algo::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); } + + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_upper_bound(const node_ptr&,const node_ptr&,NodePtrCompare) + //! Additional note: the inserted node is splayed + template<class NodePtrCompare> + static node_ptr insert_equal_upper_bound + (const node_ptr & header, const node_ptr & new_node, NodePtrCompare comp) { - //if(splay) - //splay_down(uncast(header), key, comp); - node_ptr y = tree_algorithms::lower_bound(header, key, comp); - if(splay) - splay_up(y, uncast(header)); - return y; + splay_down(header, new_node, comp); + return bstree_algo::insert_equal_upper_bound(header, new_node, comp); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater - //! than "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - template<class KeyType, class KeyNodePtrCompare> - static node_ptr upper_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true) + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal_lower_bound(const node_ptr&,const node_ptr&,NodePtrCompare) + //! Additional note: the inserted node is splayed + template<class NodePtrCompare> + static node_ptr insert_equal_lower_bound + (const node_ptr & header, const node_ptr & new_node, NodePtrCompare comp) { - //if(splay) - //splay_down(uncast(header), key, comp); - node_ptr y = tree_algorithms::upper_bound(header, key, comp); - if(splay) - splay_up(y, uncast(header)); - return y; + splay_down(header, new_node, comp); + return bstree_algo::insert_equal_lower_bound(header, new_node, comp); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from - //! the "header"'s tree. - //! - //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to - //! where it will be inserted. If "hint" is the upper_bound - //! the insertion takes constant time (two comparisons in the worst case). - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if new_node is inserted immediately before "hint". - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_equal(const node_ptr&,const node_ptr&,const node_ptr&,NodePtrCompare) + //! Additional note: the inserted node is splayed template<class NodePtrCompare> static node_ptr insert_equal (const node_ptr & header, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp) { splay_down(header, new_node, comp); - return tree_algorithms::insert_equal(header, hint, new_node, comp); + return bstree_algo::insert_equal(header, hint, new_node, comp); } - - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "pos" must be a valid iterator or header (end) node. - //! "pos" must be an iterator pointing to the successor to "new_node" - //! once inserted according to the order of already inserted nodes. This function does not - //! check "pos" and this precondition must be guaranteed by the caller. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node" - //! tree invariants might be broken. + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_before(const node_ptr&,const node_ptr&,const node_ptr&) + //! Additional note: the inserted node is splayed static node_ptr insert_before (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node) { - tree_algorithms::insert_before(header, pos, new_node); + bstree_algo::insert_before(header, pos, new_node); splay_up(new_node, header); return new_node; } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering no less than the - //! greatest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is less than the greatest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_back(const node_ptr&,const node_ptr&) + //! Additional note: the inserted node is splayed static void push_back(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_back(header, new_node); + bstree_algo::push_back(header, new_node); splay_up(new_node, header); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! "new_node" must be, according to the used ordering, no greater than the - //! lowest inserted key. - //! - //! <b>Effects</b>: Inserts new_node into the tree before "pos". - //! - //! <b>Complexity</b>: Constant-time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: If "new_node" is greater than the lowest inserted key - //! tree invariants are broken. This function is slightly faster than - //! using "insert_before". + //! @copydoc ::boost::intrusive::bstree_algorithms::push_front(const node_ptr&,const node_ptr&) + //! Additional note: the inserted node is splayed static void push_front(const node_ptr & header, const node_ptr & new_node) { - tree_algorithms::push_front(header, new_node); + bstree_algo::push_front(header, new_node); splay_up(new_node, header); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the upper bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - template<class NodePtrCompare> - static node_ptr insert_equal_upper_bound - (const node_ptr & header, const node_ptr & new_node, NodePtrCompare comp) + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) + //! Additional note: nodes with the given key are splayed + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, bool> insert_unique_check + (const node_ptr & header, const KeyType &key + ,KeyNodePtrCompare comp, insert_commit_data &commit_data) { - splay_down(header, new_node, comp); - return tree_algorithms::insert_equal_upper_bound(header, new_node, comp); + splay_down(header, key, comp); + return bstree_algo::insert_unique_check(header, key, comp, commit_data); } - //! <b>Requires</b>: "header" must be the header node of a tree. - //! NodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. NodePtrCompare compares two node_ptrs. - //! - //! <b>Effects</b>: Inserts new_node into the tree before the lower bound - //! according to "comp". - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - template<class NodePtrCompare> - static node_ptr insert_equal_lower_bound - (const node_ptr & header, const node_ptr & new_node, NodePtrCompare comp) + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_check(const const_node_ptr&,const node_ptr&,const KeyType&,KeyNodePtrCompare,insert_commit_data&) + //! Additional note: nodes with the given key are splayed + template<class KeyType, class KeyNodePtrCompare> + static std::pair<node_ptr, bool> insert_unique_check + (const node_ptr & header, const node_ptr &hint, const KeyType &key + ,KeyNodePtrCompare comp, insert_commit_data &commit_data) { - splay_down(header, new_node, comp); - return tree_algorithms::insert_equal_lower_bound(header, new_node, comp); + splay_down(header, key, comp); + return bstree_algo::insert_unique_check(header, hint, key, comp, commit_data); } - //! <b>Requires</b>: "cloner" must be a function - //! object taking a node_ptr and returning a new cloned node of it. "disposer" must - //! take a node_ptr and shouldn't throw. - //! - //! <b>Effects</b>: First empties target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! Then, duplicates the entire tree pointed by "source_header" cloning each - //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain - //! the nodes of the target tree. If "cloner" throws, the cloned target nodes - //! are disposed using <tt>void disposer(const node_ptr &)</tt>. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. - template <class Cloner, class Disposer> - static void clone - (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer) - { tree_algorithms::clone(source_header, target_header, cloner, disposer); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::insert_unique_commit(const node_ptr&,const node_ptr&,const insert_commit_data&) + static void insert_unique_commit + (const node_ptr & header, const node_ptr & new_value, const insert_commit_data &commit_data); - // delete node | complexity : constant | exception : nothrow - static void erase(const node_ptr & header, const node_ptr & z, bool splay = true) - { -// node_base* n = t->right; -// if( t->left != node_ptr() ){ -// node_base* l = t->previous(); -// splay_up( l , t ); -// n = t->left; -// n->right = t->right; -// if( n->right != node_ptr() ) -// n->right->parent = n; -// } -// -// if( n != node_ptr() ) -// n->parent = t->parent; -// -// if( t->parent->left == t ) -// t->parent->left = n; -// else // must be ( t->parent->right == t ) -// t->parent->right = n; -// -// if( data_->parent == t ) -// data_->parent = find_leftmost(); - //posibility 1 - if(splay && NodeTraits::get_left(z)){ - splay_up(prev_node(z), header); - } - /* - //possibility 2 - if(splay && NodeTraits::get_left(z) != node_ptr() ){ - node_ptr l = NodeTraits::get_left(z); - splay_up(l, header); - }*//* - if(splay && NodeTraits::get_left(z) != node_ptr() ){ - node_ptr l = prev_node(z); - splay_up_impl(l, z); - }*/ - /* - //possibility 4 - if(splay){ - splay_up(z, header); - }*/ + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header + static bool is_header(const const_node_ptr & p); - //if(splay) - //splay_up(z, header); - tree_algorithms::erase(header, z); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::rebalance + static void rebalance(const node_ptr & header); + + //! @copydoc ::boost::intrusive::bstree_algorithms::rebalance_subtree + static node_ptr rebalance_subtree(const node_ptr & old_root); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED // bottom-up splay, use data_ as parent for n | complexity : logarithmic | exception : nothrow static void splay_up(const node_ptr & node, const node_ptr & header) + { priv_splay_up<true>(node, header); } + + // top-down splay | complexity : logarithmic | exception : strong, note A + template<class KeyType, class KeyNodePtrCompare> + static node_ptr splay_down(const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool *pfound = 0) + { return priv_splay_down<true>(header, key, comp, pfound); } + + private: + + /// @cond + + // bottom-up splay, use data_ as parent for n | complexity : logarithmic | exception : nothrow + template<bool SimpleSplay> + static void priv_splay_up(const node_ptr & node, const node_ptr & header) { // If (node == header) do a splay for the right most node instead // this is to boost performance of equal_range/count on equivalent containers in the case @@ -772,20 +534,19 @@ class splaytree_algorithms rotate(p); rotate(n); } - else{ + else { // zig-zag rotate(n); - rotate(n); + if(!SimpleSplay){ + rotate(n); + } } } } - // top-down splay | complexity : logarithmic | exception : strong, note A - template<class KeyType, class KeyNodePtrCompare> - static node_ptr splay_down(const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) + template<bool SimpleSplay, class KeyType, class KeyNodePtrCompare> + static node_ptr priv_splay_down(const node_ptr & header, const KeyType &key, KeyNodePtrCompare comp, bool *pfound = 0) { - if(!NodeTraits::get_parent(header)) - return header; //Most splay tree implementations use a dummy/null node to implement. //this function. This has some problems for a generic library like Intrusive: // @@ -796,151 +557,87 @@ class splaytree_algorithms //are not changed when splaying (because the invariants of the tree don't //change) We can back up them, use the header as the null node and //reassign old values after the function has been completed. - node_ptr t = NodeTraits::get_parent(header); - //Check if tree has a single node - if(!NodeTraits::get_left(t) && !NodeTraits::get_right(t)) - return t; - //Backup leftmost/rightmost - node_ptr leftmost (NodeTraits::get_left(header)); - node_ptr rightmost(NodeTraits::get_right(header)); - { - //Anti-exception rollback, recovers the original header node if an exception is thrown. - detail::splaydown_rollback<NodeTraits> rollback(&t, header, leftmost, rightmost); - node_ptr null_node = header; - node_ptr l = null_node; - node_ptr r = null_node; + node_ptr const old_root = NodeTraits::get_parent(header); + node_ptr const leftmost = NodeTraits::get_left(header); + node_ptr const rightmost = NodeTraits::get_right(header); + if(leftmost == rightmost){ //Empty or unique node + if(pfound){ + *pfound = old_root && !comp(key, old_root) && !comp(old_root, key); + } + return old_root ? old_root : header; + } + else{ + //Initialize "null node" (the header in our case) + NodeTraits::set_left (header, node_ptr()); + NodeTraits::set_right(header, node_ptr()); + //Class that will backup leftmost/rightmost from header, commit the assemble(), + //and will restore leftmost/rightmost to header even if "comp" throws + detail::splaydown_assemble_and_fix_header<NodeTraits> commit(old_root, header, leftmost, rightmost); + bool found = false; for( ;; ){ - if(comp(key, t)){ - if(NodeTraits::get_left(t) == node_ptr() ) + if(comp(key, commit.t_)){ + node_ptr const t_left = NodeTraits::get_left(commit.t_); + if(!t_left) break; - if(comp(key, NodeTraits::get_left(t))){ - t = tree_algorithms::rotate_right(t); - - if(NodeTraits::get_left(t) == node_ptr()) - break; - link_right(t, r); - } - else if(comp(NodeTraits::get_left(t), key)){ - link_right(t, r); - - if(NodeTraits::get_right(t) == node_ptr() ) + if(comp(key, t_left)){ + bstree_algo::rotate_right_no_parent_fix(commit.t_, t_left); + commit.t_ = t_left; + if( !NodeTraits::get_left(commit.t_) ) break; - link_left(t, l); + link_right(commit.t_, commit.r_); } else{ - link_right(t, r); + link_right(commit.t_, commit.r_); + if(!SimpleSplay && comp(t_left, key)){ + if( !NodeTraits::get_right(commit.t_) ) + break; + link_left(commit.t_, commit.l_); + } } } - else if(comp(t, key)){ - if(NodeTraits::get_right(t) == node_ptr() ) + else if(comp(commit.t_, key)){ + node_ptr const t_right = NodeTraits::get_right(commit.t_); + if(!t_right) break; - if(comp(NodeTraits::get_right(t), key)){ - t = tree_algorithms::rotate_left( t ); - - if(NodeTraits::get_right(t) == node_ptr() ) + if(comp(t_right, key)){ + bstree_algo::rotate_left_no_parent_fix(commit.t_, t_right); + commit.t_ = t_right; + if( !NodeTraits::get_right(commit.t_) ) break; - link_left(t, l); - } - else if(comp(key, NodeTraits::get_right(t))){ - link_left(t, l); - - if(NodeTraits::get_left(t) == node_ptr()) - break; - - link_right(t, r); + link_left(commit.t_, commit.l_); } else{ - link_left(t, l); + link_left(commit.t_, commit.l_); + if(!SimpleSplay && comp(key, t_right)){ + if( !NodeTraits::get_left(commit.t_) ) + break; + link_right(commit.t_, commit.r_); + } } } else{ + found = true; break; } } - assemble(t, l, r, null_node); - rollback.release(); - } - - //Now recover the original header except for the - //splayed root node. - //t is the current root - NodeTraits::set_parent(header, t); - NodeTraits::set_parent(t, header); - //Recover leftmost/rightmost pointers - NodeTraits::set_left (header, leftmost); - NodeTraits::set_right(header, rightmost); - return t; - } - - //! <b>Requires</b>: header must be the header of a tree. - //! - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - static void rebalance(const node_ptr & header) - { tree_algorithms::rebalance(header); } - - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - static node_ptr rebalance_subtree(const node_ptr & old_root) - { return tree_algorithms::rebalance_subtree(old_root); } - - - //! <b>Requires</b>: "n" must be a node inserted in a tree. - //! - //! <b>Effects</b>: Returns a pointer to the header node of the tree. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - static node_ptr get_header(const node_ptr & n) - { return tree_algorithms::get_header(n); } - - private: - - /// @cond - - // assemble the three sub-trees into new tree pointed to by t | complexity : constant | exception : nothrow - static void assemble(const node_ptr &t, const node_ptr & l, const node_ptr & r, const const_node_ptr & null_node ) - { - NodeTraits::set_right(l, NodeTraits::get_left(t)); - NodeTraits::set_left(r, NodeTraits::get_right(t)); - - if(NodeTraits::get_right(l) != node_ptr()){ - NodeTraits::set_parent(NodeTraits::get_right(l), l); - } - - if(NodeTraits::get_left(r) != node_ptr()){ - NodeTraits::set_parent(NodeTraits::get_left(r), r); - } - - NodeTraits::set_left (t, NodeTraits::get_right(null_node)); - NodeTraits::set_right(t, NodeTraits::get_left(null_node)); - - if( NodeTraits::get_left(t) != node_ptr() ){ - NodeTraits::set_parent(NodeTraits::get_left(t), t); - } - - if( NodeTraits::get_right(t) ){ - NodeTraits::set_parent(NodeTraits::get_right(t), t); + //commit.~splaydown_assemble_and_fix_header<NodeTraits>() will first + //"assemble()" + link the new root & recover header's leftmost & rightmost + if(pfound){ + *pfound = found; + } + return commit.t_; } } // break link to left child node and attach it to left tree pointed to by l | complexity : constant | exception : nothrow static void link_left(node_ptr & t, node_ptr & l) { + //procedure link_left; + // t, l, right(l) := right(t), t, t + //end link_left NodeTraits::set_right(l, t); NodeTraits::set_parent(t, l); l = t; @@ -950,6 +647,9 @@ class splaytree_algorithms // break link to right child node and attach it to right tree pointed to by r | complexity : constant | exception : nothrow static void link_right(node_ptr & t, node_ptr & r) { + //procedure link_right; + // t, r, left(r) := left(t), t, t + //end link_right; NodeTraits::set_left(r, t); NodeTraits::set_parent(t, r); r = t; @@ -959,21 +659,24 @@ class splaytree_algorithms // rotate n with its parent | complexity : constant | exception : nothrow static void rotate(const node_ptr & n) { + //procedure rotate_left; + // t, right(t), left(right(t)) := right(t), left(right(t)), t + //end rotate_left; node_ptr p = NodeTraits::get_parent(n); node_ptr g = NodeTraits::get_parent(p); //Test if g is header before breaking tree //invariants that would make is_header invalid - bool g_is_header = is_header(g); + bool g_is_header = bstree_algo::is_header(g); if(NodeTraits::get_left(p) == n){ NodeTraits::set_left(p, NodeTraits::get_right(n)); - if(NodeTraits::get_left(p) != node_ptr()) + if(NodeTraits::get_left(p)) NodeTraits::set_parent(NodeTraits::get_left(p), p); NodeTraits::set_right(n, p); } else{ // must be ( p->right == n ) NodeTraits::set_right(p, NodeTraits::get_left(n)); - if(NodeTraits::get_right(p) != node_ptr()) + if(NodeTraits::get_right(p)) NodeTraits::set_parent(NodeTraits::get_right(p), p); NodeTraits::set_left(n, p); } @@ -1000,6 +703,22 @@ class splaytree_algorithms /// @endcond }; +/// @cond + +template<class NodeTraits> +struct get_algo<SplayTreeAlgorithms, NodeTraits> +{ + typedef splaytree_algorithms<NodeTraits> type; +}; + +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<SplayTreeAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/treap.hpp b/boost/intrusive/treap.hpp index b539acc569..b3afb864be 100644 --- a/boost/intrusive/treap.hpp +++ b/boost/intrusive/treap.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2008-2012 +// (C) Copyright Ion Gaztanaga 2008-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -9,60 +9,51 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_TRIE_HPP -#define BOOST_INTRUSIVE_TRIE_HPP +#ifndef BOOST_INTRUSIVE_TREAP_HPP +#define BOOST_INTRUSIVE_TREAP_HPP + +#if defined(_MSC_VER) +# pragma once +#endif #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <algorithm> #include <cstddef> #include <functional> -#include <iterator> #include <utility> #include <boost/intrusive/detail/assert.hpp> #include <boost/static_assert.hpp> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/bs_set_hook.hpp> +#include <boost/intrusive/bstree.hpp> #include <boost/intrusive/detail/tree_node.hpp> #include <boost/intrusive/detail/ebo_functor_holder.hpp> #include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/clear_on_destructor_base.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/options.hpp> +#include <boost/intrusive/detail/get_value_traits.hpp> #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/treap_algorithms.hpp> #include <boost/intrusive/link_mode.hpp> -#include <boost/move/move.hpp> +#include <boost/move/utility_core.hpp> #include <boost/intrusive/priority_compare.hpp> +#include <boost/intrusive/detail/node_cloner_disposer.hpp> +#include <boost/intrusive/detail/key_nodeptr_comp.hpp> namespace boost { namespace intrusive { /// @cond -template <class ValueTraits, class Compare, class PrioCompare, class SizeType, bool ConstantTimeSize> -struct treap_setopt +struct treap_defaults { - typedef ValueTraits value_traits; - typedef Compare compare; - typedef PrioCompare priority_compare; - typedef SizeType size_type; - static const bool constant_time_size = ConstantTimeSize; + typedef default_bstree_hook_applier proto_value_traits; + static const bool constant_time_size = true; + typedef std::size_t size_type; + typedef void compare; + typedef void priority; + typedef void header_holder_type; }; -template <class T> -struct treap_set_defaults - : pack_options - < none - , base_hook<detail::default_bs_set_hook> - , constant_time_size<true> - , size_type<std::size_t> - , compare<std::less<T> > - , priority<boost::intrusive::priority_compare<T> > - >::type -{}; - /// @endcond //! The class template treap is an intrusive treap container that @@ -81,170 +72,94 @@ struct treap_set_defaults #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class treap_impl - : private detail::clear_on_destructor_base<treap_impl<Config> > + /// @cond + : public bstree_impl<ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder> + , public detail::ebo_functor_holder + < typename get_prio + < VoidOrPrioComp + , typename bstree_impl + <ValueTraits, VoidOrKeyComp, SizeType, ConstantTimeSize, BsTreeAlgorithms, HeaderHolder>::value_type>::type + > + /// @endcond { - template<class C> friend class detail::clear_on_destructor_base; public: - typedef typename Config::value_traits value_traits; + typedef ValueTraits value_traits; /// @cond - static const bool external_value_traits = - detail::external_value_traits_is_true<value_traits>::value; - typedef typename detail::eval_if_c - < external_value_traits - , detail::eval_value_traits<value_traits> - , detail::identity<value_traits> - >::type real_value_traits; + typedef bstree_impl< ValueTraits, VoidOrKeyComp, SizeType + , ConstantTimeSize, BsTreeAlgorithms + , HeaderHolder> tree_type; + typedef tree_type implementation_defined; + typedef get_prio + < VoidOrPrioComp + , typename tree_type::value_type> get_prio_type; + + typedef detail::ebo_functor_holder + <typename get_prio_type::type> prio_base; + /// @endcond - typedef typename real_value_traits::pointer pointer; - typedef typename real_value_traits::const_pointer const_pointer; - typedef typename pointer_traits<pointer>::element_type value_type; - typedef typename pointer_traits<pointer>::reference reference; - typedef typename pointer_traits<const_pointer>::reference const_reference; - typedef typename pointer_traits<pointer>::difference_type difference_type; - typedef value_type key_type; - typedef typename Config::size_type size_type; - typedef typename Config::compare value_compare; - typedef typename Config::priority_compare priority_compare; - typedef value_compare key_compare; - typedef tree_iterator<treap_impl, false> iterator; - typedef tree_iterator<treap_impl, true> const_iterator; - typedef boost::intrusive::detail::reverse_iterator<iterator> reverse_iterator; - typedef boost::intrusive::detail::reverse_iterator<const_iterator>const_reverse_iterator; - typedef typename real_value_traits::node_traits node_traits; - typedef typename node_traits::node node; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <node>::type node_ptr; - typedef typename pointer_traits - <pointer>::template rebind_pointer - <const node>::type const_node_ptr; - typedef treap_algorithms<node_traits> node_algorithms; - - static const bool constant_time_size = Config::constant_time_size; - static const bool stateful_value_traits = detail::is_stateful_value_traits<real_value_traits>::value; + + typedef typename implementation_defined::pointer pointer; + typedef typename implementation_defined::const_pointer const_pointer; + typedef typename implementation_defined::value_type value_type; + typedef typename implementation_defined::key_type key_type; + typedef typename implementation_defined::reference reference; + typedef typename implementation_defined::const_reference const_reference; + typedef typename implementation_defined::difference_type difference_type; + typedef typename implementation_defined::size_type size_type; + typedef typename implementation_defined::value_compare value_compare; + typedef typename implementation_defined::key_compare key_compare; + typedef typename implementation_defined::iterator iterator; + typedef typename implementation_defined::const_iterator const_iterator; + typedef typename implementation_defined::reverse_iterator reverse_iterator; + typedef typename implementation_defined::const_reverse_iterator const_reverse_iterator; + typedef typename implementation_defined::node_traits node_traits; + typedef typename implementation_defined::node node; + typedef typename implementation_defined::node_ptr node_ptr; + typedef typename implementation_defined::const_node_ptr const_node_ptr; + typedef BOOST_INTRUSIVE_IMPDEF(treap_algorithms<node_traits>) node_algorithms; + typedef BOOST_INTRUSIVE_IMPDEF(typename get_prio_type::type) priority_compare; + + static const bool constant_time_size = implementation_defined::constant_time_size; + static const bool stateful_value_traits = implementation_defined::stateful_value_traits; + static const bool safemode_or_autounlink = is_safe_autounlink<value_traits::link_mode>::value; /// @cond private: - typedef detail::size_holder<constant_time_size, size_type> size_traits; //noncopyable BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_impl) - enum { safemode_or_autounlink = - (int)real_value_traits::link_mode == (int)auto_unlink || - (int)real_value_traits::link_mode == (int)safe_link }; - - //Constant-time size is incompatible with auto-unlink hooks! - BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink))); - - struct header_plus_size : public size_traits - { node header_; }; - - struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare> - { - node_plus_pred_t(const value_compare &comp, const priority_compare &p_comp) - : detail::ebo_functor_holder<value_compare>(comp) - , header_plus_priority_size_(p_comp) - {} - struct header_plus_priority_size - : public detail::ebo_functor_holder<priority_compare> - { - header_plus_priority_size(const priority_compare &p_comp) - : detail::ebo_functor_holder<priority_compare>(p_comp) - {} - header_plus_size header_plus_size_; - } header_plus_priority_size_; - }; - - struct data_t : public treap_impl::value_traits - { - typedef typename treap_impl::value_traits value_traits; - data_t(const value_compare & comp, const priority_compare &pcomp, const value_traits &val_traits) - : value_traits(val_traits), node_plus_pred_(comp, pcomp) - {} - node_plus_pred_t node_plus_pred_; - } data_; - - const value_compare &priv_comp() const - { return data_.node_plus_pred_.get(); } - - value_compare &priv_comp() - { return data_.node_plus_pred_.get(); } - const priority_compare &priv_pcomp() const - { return data_.node_plus_pred_.header_plus_priority_size_.get(); } + { return static_cast<const prio_base&>(*this).get(); } priority_compare &priv_pcomp() - { return data_.node_plus_pred_.header_plus_priority_size_.get(); } - - const value_traits &priv_value_traits() const - { return data_; } - - value_traits &priv_value_traits() - { return data_; } - - node_ptr priv_header_ptr() - { return pointer_traits<node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_.header_); } - - const_node_ptr priv_header_ptr() const - { return pointer_traits<const_node_ptr>::pointer_to(data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_.header_); } - - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - - size_traits &priv_size_traits() - { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_; } - - const size_traits &priv_size_traits() const - { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_; } - - const real_value_traits &get_real_value_traits(detail::bool_<false>) const - { return data_; } - - const real_value_traits &get_real_value_traits(detail::bool_<true>) const - { return data_.get_value_traits(*this); } - - real_value_traits &get_real_value_traits(detail::bool_<false>) - { return data_; } - - real_value_traits &get_real_value_traits(detail::bool_<true>) - { return data_.get_value_traits(*this); } + { return static_cast<prio_base&>(*this).get(); } /// @endcond public: - - const real_value_traits &get_real_value_traits() const - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - - real_value_traits &get_real_value_traits() - { return this->get_real_value_traits(detail::bool_<external_value_traits>()); } - typedef typename node_algorithms::insert_commit_data insert_commit_data; - //! <b>Effects</b>: Constructs an empty treap. + //! <b>Effects</b>: Constructs an empty container. //! //! <b>Complexity</b>: Constant. //! //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare/priority_compare objects throw. Basic guarantee. - treap_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) - : data_(cmp, pcmp, v_traits) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - } + explicit treap_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, v_traits), prio_base(pcmp) + {} //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. //! cmp must be a comparison function that induces a strict weak ordering. //! - //! <b>Effects</b>: Constructs an empty treap and inserts elements from + //! <b>Effects</b>: Constructs an empty container and inserts elements from //! [b, e). //! //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using @@ -259,92 +174,46 @@ class treap_impl , const value_compare &cmp = value_compare() , const priority_compare &pcmp = priority_compare() , const value_traits &v_traits = value_traits()) - : data_(cmp, pcmp, v_traits) + : tree_type(cmp, v_traits), prio_base(pcmp) { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); if(unique) this->insert_unique(b, e); else this->insert_equal(b, e); } - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) treap_impl(BOOST_RV_REF(treap_impl) x) - : data_( ::boost::move(x.priv_comp()) - , ::boost::move(x.priv_pcomp()) - , ::boost::move(x.priv_value_traits())) - { - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(size_type(0)); - this->swap(x); - } + : tree_type(::boost::move(static_cast<tree_type&>(x))) + , prio_base(::boost::move(x.priv_pcomp())) + {} - //! <b>Effects</b>: to-do - //! + //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) treap_impl& operator=(BOOST_RV_REF(treap_impl) x) { this->swap(x); return *this; } - //! <b>Effects</b>: Detaches all elements from this. The objects in the set - //! are not deleted (i.e. no destructors are called), but the nodes according to - //! the value_traits template parameter are reinitialized and thus can be reused. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~treap_impl() - {} - - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return iterator (node_traits::get_left(this->priv_header_ptr()), this); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::~bstree() + ~treap_impl(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return this->cbegin(); } + //! @copydoc ::boost::intrusive::bstree::begin() + iterator begin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return const_iterator (node_traits::get_left(this->priv_header_ptr()), this); } + //! @copydoc ::boost::intrusive::bstree::begin()const + const_iterator begin() const; - //! <b>Effects</b>: Returns an iterator pointing to the end of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return iterator (this->priv_header_ptr(), this); } + //! @copydoc ::boost::intrusive::bstree::cbegin()const + const_iterator cbegin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return this->cend(); } + //! @copydoc ::boost::intrusive::bstree::end() + iterator end(); - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return const_iterator (uncast(this->priv_header_ptr()), this); } + //! @copydoc ::boost::intrusive::bstree::end()const + const_iterator end() const; + //! @copydoc ::boost::intrusive::bstree::cend()const + const_iterator cend() const; + #endif //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the treap. //! @@ -352,7 +221,7 @@ class treap_impl //! //! <b>Throws</b>: Nothing. iterator top() - { return this->empty() ? this->end() : iterator (node_traits::get_parent(this->priv_header_ptr()), this); } + { return this->tree_type::root(); } //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the treap.. //! @@ -368,61 +237,27 @@ class treap_impl //! //! <b>Throws</b>: Nothing. const_iterator ctop() const - { return this->empty() ? this->cend() : const_iterator (node_traits::get_parent(this->priv_header_ptr()), this); } + { return this->tree_type::root(); } - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return reverse_iterator(this->end()); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::rbegin() + reverse_iterator rbegin(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return const_reverse_iterator(this->end()); } + //! @copydoc ::boost::intrusive::bstree::rbegin()const + const_reverse_iterator rbegin() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return const_reverse_iterator(this->end()); } + //! @copydoc ::boost::intrusive::bstree::crbegin()const + const_reverse_iterator crbegin() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return reverse_iterator(this->begin()); } + //! @copydoc ::boost::intrusive::bstree::rend() + reverse_iterator rend(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return const_reverse_iterator(this->begin()); } + //! @copydoc ::boost::intrusive::bstree::rend()const + const_reverse_iterator rend() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return const_reverse_iterator(this->begin()); } + //! @copydoc ::boost::intrusive::bstree::crend()const + const_reverse_iterator crend() const; + #endif //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the //! reversed treap. @@ -451,59 +286,33 @@ class treap_impl const_reverse_iterator crtop() const { return const_reverse_iterator(this->top()); } - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of treap. - //! - //! <b>Effects</b>: Returns a const reference to the treap associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static treap_impl &container_from_end_iterator(iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(iterator) + static treap_impl &container_from_end_iterator(iterator end_iterator); - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of treap. - //! - //! <b>Effects</b>: Returns a const reference to the treap associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const treap_impl &container_from_end_iterator(const_iterator end_iterator) - { return priv_container_from_end_iterator(end_iterator); } + //! @copydoc ::boost::intrusive::bstree::container_from_end_iterator(const_iterator) + static const treap_impl &container_from_end_iterator(const_iterator end_iterator); - //! <b>Precondition</b>: it must be a valid iterator - //! of treap. - //! - //! <b>Effects</b>: Returns a const reference to the treap associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static treap_impl &container_from_iterator(iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(iterator) + static treap_impl &container_from_iterator(iterator it); - //! <b>Precondition</b>: it must be a valid end const_iterator - //! of treap. - //! - //! <b>Effects</b>: Returns a const reference to the treap associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const treap_impl &container_from_iterator(const_iterator it) - { return priv_container_from_iterator(it); } + //! @copydoc ::boost::intrusive::bstree::container_from_iterator(const_iterator) + static const treap_impl &container_from_iterator(const_iterator it); - //! <b>Effects</b>: Returns the value_compare object used by the treap. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return this->priv_comp(); } + //! @copydoc ::boost::intrusive::bstree::key_comp()const + key_compare key_comp() const; + + //! @copydoc ::boost::intrusive::bstree::value_comp()const + value_compare value_comp() const; + + //! @copydoc ::boost::intrusive::bstree::empty()const + bool empty() const; - //! <b>Effects</b>: Returns the priority_compare object used by the treap. + //! @copydoc ::boost::intrusive::bstree::size()const + size_type size() const; + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! <b>Effects</b>: Returns the priority_compare object used by the container. //! //! <b>Complexity</b>: Constant. //! @@ -511,29 +320,6 @@ class treap_impl priority_compare priority_comp() const { return this->priv_pcomp(); } - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return node_algorithms::unique(this->priv_header_ptr()); } - - //! <b>Effects</b>: Returns the number of elements stored in the treap. - //! - //! <b>Complexity</b>: Linear to elements contained in *this - //! if constant-time size option is disabled. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { - if(constant_time_size) - return this->priv_size_traits().get_size(); - else{ - return (size_type)node_algorithms::size(this->priv_header_ptr()); - } - } - //! <b>Effects</b>: Swaps the contents of two treaps. //! //! <b>Complexity</b>: Constant. @@ -541,22 +327,36 @@ class treap_impl //! <b>Throws</b>: If the comparison functor's swap call throws. void swap(treap_impl& other) { + tree_type::swap(other); //This can throw using std::swap; - swap(priv_comp(), priv_comp()); - swap(priv_pcomp(), priv_pcomp()); - //These can't throw - node_algorithms::swap_tree(this->priv_header_ptr(), other.priv_header_ptr()); - if(constant_time_size){ - size_type backup = this->priv_size_traits().get_size(); - this->priv_size_traits().set_size(other.priv_size_traits().get_size()); - other.priv_size_traits().set_size(backup); - } + swap(this->priv_pcomp(), other.priv_pcomp()); + } + + //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. + //! Cloner should yield to nodes equivalent to the original nodes. + //! + //! <b>Effects</b>: Erases all the elements from *this + //! calling Disposer::operator()(pointer), clones all the + //! elements from src calling Cloner::operator()(const_reference ) + //! and inserts them on *this. Copies the predicate from the source container. + //! + //! If cloner throws, all cloned elements are unlinked and disposed + //! calling Disposer::operator()(pointer). + //! + //! <b>Complexity</b>: Linear to erased plus inserted elements. + //! + //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. + template <class Cloner, class Disposer> + void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer) + { + tree_type::clone_from(src, cloner, disposer); + this->priv_pcomp() = src.priv_pcomp(); } //! <b>Requires</b>: value must be an lvalue //! - //! <b>Effects</b>: Inserts value into the treap before the upper bound. + //! <b>Effects</b>: Inserts value into the container before the upper bound. //! //! <b>Complexity</b>: Average complexity for insert element is at //! most logarithmic. @@ -567,23 +367,23 @@ class treap_impl //! No copy-constructors are called. iterator insert_equal(reference value) { - detail::key_nodeptr_comp<value_compare, treap_impl> - key_node_comp(priv_comp(), this); - detail::key_nodeptr_comp<priority_compare, treap_impl> - key_node_pcomp(priv_pcomp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->value_comp(), &this->get_value_traits()); + detail::key_nodeptr_comp<priority_compare, value_traits> + key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); iterator ret(node_algorithms::insert_equal_upper_bound - (this->priv_header_ptr(), to_insert, key_node_comp, key_node_pcomp), this); - this->priv_size_traits().increment(); + (this->tree_type::header_ptr(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr()); + this->tree_type::sz_traits().increment(); return ret; } //! <b>Requires</b>: value must be an lvalue, and "hint" must be //! a valid iterator. //! - //! <b>Effects</b>: Inserts x into the treap, using "hint" as a hint to + //! <b>Effects</b>: Inserts x into the container, using "hint" as a hint to //! where it will be inserted. If "hint" is the upper_bound //! the insertion takes constant time (two comparisons in the worst case) //! @@ -596,23 +396,23 @@ class treap_impl //! No copy-constructors are called. iterator insert_equal(const_iterator hint, reference value) { - detail::key_nodeptr_comp<value_compare, treap_impl> - key_node_comp(priv_comp(), this); - detail::key_nodeptr_comp<priority_compare, treap_impl> - key_node_pcomp(priv_pcomp(), this); - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + detail::key_nodeptr_comp<value_compare, value_traits> + key_node_comp(this->value_comp(), &this->get_value_traits()); + detail::key_nodeptr_comp<priority_compare, value_traits> + key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); iterator ret (node_algorithms::insert_equal - (this->priv_header_ptr(), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this); - this->priv_size_traits().increment(); + (this->tree_type::header_ptr(), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this->priv_value_traits_ptr()); + this->tree_type::sz_traits().increment(); return ret; } //! <b>Requires</b>: Dereferencing iterator must yield an lvalue //! of type value_type. //! - //! <b>Effects</b>: Inserts a each element of a range into the treap + //! <b>Effects</b>: Inserts a each element of a range into the container //! before the upper bound of the key of each element. //! //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the @@ -627,14 +427,14 @@ class treap_impl template<class Iterator> void insert_equal(Iterator b, Iterator e) { - iterator end(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_equal(end, *b); + this->insert_equal(iend, *b); } //! <b>Requires</b>: value must be an lvalue //! - //! <b>Effects</b>: Inserts value into the treap if the value + //! <b>Effects</b>: Inserts value into the container if the value //! is not already present. //! //! <b>Complexity</b>: Average complexity for insert element is at @@ -648,7 +448,7 @@ class treap_impl std::pair<iterator, bool> insert_unique(reference value) { insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), priv_pcomp(), commit_data); + std::pair<iterator, bool> ret = insert_unique_check(value, this->value_comp(), this->priv_pcomp(), commit_data); if(!ret.second) return ret; return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true); @@ -657,7 +457,7 @@ class treap_impl //! <b>Requires</b>: value must be an lvalue, and "hint" must be //! a valid iterator //! - //! <b>Effects</b>: Tries to insert x into the treap, using "hint" as a hint + //! <b>Effects</b>: Tries to insert x into the container, using "hint" as a hint //! to where it will be inserted. //! //! <b>Complexity</b>: Logarithmic in general, but it is amortized @@ -672,7 +472,7 @@ class treap_impl iterator insert_unique(const_iterator hint, reference value) { insert_commit_data commit_data; - std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), priv_pcomp(), commit_data); + std::pair<iterator, bool> ret = insert_unique_check(hint, value, this->value_comp(), this->priv_pcomp(), commit_data); if(!ret.second) return ret.first; return insert_unique_commit(value, commit_data); @@ -681,7 +481,7 @@ class treap_impl //! <b>Requires</b>: Dereferencing iterator must yield an lvalue //! of type value_type. //! - //! <b>Effects</b>: Tries to insert each element of a range into the treap. + //! <b>Effects</b>: Tries to insert each element of a range into the container. //! //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the //! size of the range. However, it is linear in N if the range is already sorted @@ -696,9 +496,9 @@ class treap_impl void insert_unique(Iterator b, Iterator e) { if(this->empty()){ - iterator end(this->end()); + iterator iend(this->end()); for (; b != e; ++b) - this->insert_unique(end, *b); + this->insert_unique(iend, *b); } else{ for (; b != e; ++b) @@ -744,14 +544,14 @@ class treap_impl ( const KeyType &key, KeyValueCompare key_value_comp , KeyValuePrioCompare key_value_pcomp, insert_commit_data &commit_data) { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - comp(key_value_comp, this); - detail::key_nodeptr_comp<KeyValuePrioCompare, treap_impl> - pcomp(key_value_pcomp, this); + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + ocomp(key_value_comp, &this->get_value_traits()); + detail::key_nodeptr_comp<KeyValuePrioCompare, value_traits> + pcomp(key_value_pcomp, &this->get_value_traits()); std::pair<node_ptr, bool> ret = (node_algorithms::insert_unique_check - (this->priv_header_ptr(), key, comp, pcomp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); + (this->tree_type::header_ptr(), key, ocomp, pcomp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); } //! <b>Requires</b>: key_value_comp must be a comparison function that induces @@ -796,14 +596,14 @@ class treap_impl , KeyValuePrioCompare key_value_pcomp , insert_commit_data &commit_data) { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - comp(key_value_comp, this); - detail::key_nodeptr_comp<KeyValuePrioCompare, treap_impl> - pcomp(key_value_pcomp, this); + detail::key_nodeptr_comp<KeyValueCompare, value_traits> + ocomp(key_value_comp, &this->get_value_traits()); + detail::key_nodeptr_comp<KeyValuePrioCompare, value_traits> + pcomp(key_value_pcomp, &this->get_value_traits()); std::pair<node_ptr, bool> ret = (node_algorithms::insert_unique_check - (this->priv_header_ptr(), hint.pointed_node(), key, comp, pcomp, commit_data)); - return std::pair<iterator, bool>(iterator(ret.first, this), ret.second); + (this->tree_type::header_ptr(), hint.pointed_node(), key, ocomp, pcomp, commit_data)); + return std::pair<iterator, bool>(iterator(ret.first, this->priv_value_traits_ptr()), ret.second); } //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data @@ -825,89 +625,89 @@ class treap_impl //! erased between the "insert_check" and "insert_commit" calls. iterator insert_unique_commit(reference value, const insert_commit_data &commit_data) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - node_algorithms::insert_unique_commit(this->priv_header_ptr(), to_insert, commit_data); - this->priv_size_traits().increment(); - return iterator(to_insert, this); + node_algorithms::insert_unique_commit(this->tree_type::header_ptr(), to_insert, commit_data); + this->tree_type::sz_traits().increment(); + return iterator(to_insert, this->priv_value_traits_ptr()); } //! <b>Requires</b>: value must be an lvalue, "pos" must be //! a valid iterator (or end) and must be the succesor of value //! once inserted according to the predicate //! - //! <b>Effects</b>: Inserts x into the treap before "pos". + //! <b>Effects</b>: Inserts x into the container before "pos". //! //! <b>Complexity</b>: Constant time. //! //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. //! //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" treap ordering invariant will be broken. + //! the successor of "value" container ordering invariant will be broken. //! This is a low-level function to be used only for performance reasons //! by advanced users. iterator insert_before(const_iterator pos, reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - detail::key_nodeptr_comp<priority_compare, treap_impl> - pcomp(priv_pcomp(), this); + detail::key_nodeptr_comp<priority_compare, value_traits> + pcomp(this->priv_pcomp(), &this->get_value_traits()); iterator ret (node_algorithms::insert_before - (this->priv_header_ptr(), pos.pointed_node(), to_insert, pcomp), this); - this->priv_size_traits().increment(); + (this->tree_type::header_ptr(), pos.pointed_node(), to_insert, pcomp), this->priv_value_traits_ptr()); + this->tree_type::sz_traits().increment(); return ret; } //! <b>Requires</b>: value must be an lvalue, and it must be no less //! than the greatest inserted key //! - //! <b>Effects</b>: Inserts x into the treap in the last position. + //! <b>Effects</b>: Inserts x into the container in the last position. //! //! <b>Complexity</b>: Constant time. //! //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. //! //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key treap ordering invariant will be broken. + //! less than the greatest inserted key container ordering invariant will be broken. //! This function is slightly more efficient than using "insert_before". //! This is a low-level function to be used only for performance reasons //! by advanced users. void push_back(reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - detail::key_nodeptr_comp<priority_compare, treap_impl> - pcomp(priv_pcomp(), this); - node_algorithms::push_back(this->priv_header_ptr(), to_insert, pcomp); - this->priv_size_traits().increment(); + detail::key_nodeptr_comp<priority_compare, value_traits> + pcomp(this->priv_pcomp(), &this->get_value_traits()); + node_algorithms::push_back(this->tree_type::header_ptr(), to_insert, pcomp); + this->tree_type::sz_traits().increment(); } //! <b>Requires</b>: value must be an lvalue, and it must be no greater //! than the minimum inserted key //! - //! <b>Effects</b>: Inserts x into the treap in the first position. + //! <b>Effects</b>: Inserts x into the container in the first position. //! //! <b>Complexity</b>: Constant time. //! //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. //! //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key treap ordering invariant will be broken. + //! greater than the minimum inserted key container ordering invariant will be broken. //! This function is slightly more efficient than using "insert_before". //! This is a low-level function to be used only for performance reasons //! by advanced users. void push_front(reference value) { - node_ptr to_insert(get_real_value_traits().to_node_ptr(value)); + node_ptr to_insert(this->get_value_traits().to_node_ptr(value)); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert)); - detail::key_nodeptr_comp<priority_compare, treap_impl> - pcomp(priv_pcomp(), this); - node_algorithms::push_front(this->priv_header_ptr(), to_insert, pcomp); - this->priv_size_traits().increment(); + detail::key_nodeptr_comp<priority_compare, value_traits> + pcomp(this->priv_pcomp(), &this->get_value_traits()); + node_algorithms::push_front(this->tree_type::header_ptr(), to_insert, pcomp); + this->tree_type::sz_traits().increment(); } //! <b>Effects</b>: Erases the element pointed to by pos. @@ -925,10 +725,10 @@ class treap_impl node_ptr to_erase(i.pointed_node()); if(safemode_or_autounlink) BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase)); - detail::key_nodeptr_comp<priority_compare, treap_impl> - key_node_pcomp(priv_pcomp(), this); - node_algorithms::erase(this->priv_header_ptr(), to_erase, key_node_pcomp); - this->priv_size_traits().decrement(); + detail::key_nodeptr_comp<priority_compare, value_traits> + key_node_pcomp(this->priv_pcomp(), &this->get_value_traits()); + node_algorithms::erase(this->tree_type::header_ptr(), to_erase, key_node_pcomp); + this->tree_type::sz_traits().decrement(); if(safemode_or_autounlink) node_algorithms::init(to_erase); return ret.unconst(); @@ -957,7 +757,7 @@ class treap_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. size_type erase(const_reference value) - { return this->erase(value, priv_comp()); } + { return this->erase(value, this->value_comp()); } //! <b>Effects</b>: Erases all the elements with the given key. //! according to the comparison functor "comp". @@ -1000,7 +800,7 @@ class treap_impl { node_ptr to_erase(i.pointed_node()); iterator ret(this->erase(i)); - disposer(get_real_value_traits().to_value_ptr(to_erase)); + disposer(this->get_value_traits().to_value_ptr(to_erase)); return ret; } @@ -1087,15 +887,7 @@ class treap_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. void clear() - { - if(safemode_or_autounlink){ - this->clear_and_dispose(detail::null_disposer()); - } - else{ - node_algorithms::init_header(priv_header_ptr()); - this->priv_size_traits().set_size(0); - } - } + { tree_type::clear(); } //! <b>Effects</b>: Erases all of the elements calling disposer(p) for //! each node to be erased. @@ -1109,484 +901,134 @@ class treap_impl template<class Disposer> void clear_and_dispose(Disposer disposer) { - node_algorithms::clear_and_dispose(this->priv_header_ptr() - , detail::node_disposer<Disposer, treap_impl>(disposer, this)); - node_algorithms::init_header(this->priv_header_ptr()); - this->priv_size_traits().set_size(0); + node_algorithms::clear_and_dispose(this->tree_type::header_ptr() + , detail::node_disposer<Disposer, value_traits, TreapAlgorithms>(disposer, &this->get_value_traits())); + node_algorithms::init_header(this->tree_type::header_ptr()); + this->tree_type::sz_traits().set_size(0); } - //! <b>Effects</b>: Returns the number of contained elements with the given value - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given value. - //! - //! <b>Throws</b>: Nothing. - size_type count(const_reference value) const - { return this->count(value, priv_comp()); } - - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: Nothing. - template<class KeyType, class KeyValueCompare> - size_type count(const KeyType &key, KeyValueCompare comp) const + //! @copydoc ::boost::intrusive::bstree::check(ExtraChecker)const + template <class ExtraChecker> + void check(ExtraChecker extra_checker) const { - std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp); - return std::distance(ret.first, ret.second); + typedef detail::key_nodeptr_comp<priority_compare, value_traits> nodeptr_prio_comp_t; + nodeptr_prio_comp_t nodeptr_prio_comp(priv_pcomp(), &this->get_value_traits()); + tree_type::check(detail::treap_node_extra_checker<ValueTraits, nodeptr_prio_comp_t, ExtraChecker>(nodeptr_prio_comp, extra_checker)); } - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator lower_bound(const_reference value) - { return this->lower_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::check()const + void check() const + { check(detail::empty_node_checker<ValueTraits>()); } - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator lower_bound(const_reference value) const - { return this->lower_bound(value, priv_comp()); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree::count(const_reference)const + size_type count(const_reference value) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + size_type count(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::lower_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + iterator lower_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator upper_bound(const_reference value) - { return this->upper_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator upper_bound(const_reference value) const - { return this->upper_bound(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference) + iterator upper_bound(const_reference value); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k according to comp or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return const_iterator(node_algorithms::upper_bound - (this->priv_header_ptr(), key, key_node_comp), this); - } + iterator upper_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - iterator find(const_reference value) - { return this->find(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - iterator find(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - const_iterator find(const_reference value) const - { return this->find(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const_reference) + iterator find(const_reference value); - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - return const_iterator - (node_algorithms::find(this->priv_header_ptr(), key, key_node_comp), this); - } + iterator find(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - std::pair<iterator,iterator> equal_range(const_reference value) - { return this->equal_range(value, priv_comp()); } + //! @copydoc ::boost::intrusive::bstree::find(const_reference)const + const_iterator find(const_reference value) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp) - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + const_iterator find(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare) + template<class KeyType, class KeyValueCompare> + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); + + //! @copydoc ::boost::intrusive::bstree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return this->equal_range(value, priv_comp()); } + equal_range(const_reference value) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. + //! @copydoc ::boost::intrusive::bstree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType &key, KeyValueCompare comp) const - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::equal_range(this->priv_header_ptr(), key, key_node_comp)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + equal_range(const KeyType& key, KeyValueCompare comp) const; - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this)); - } + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator,const_iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return this->bounded_range(lower_value, upper_value, priv_comp(), left_closed, right_closed); } + //! @copydoc ::boost::intrusive::bstree::bounded_range(const_reference,const_reference,bool,bool)const + std::pair<const_iterator, const_iterator> + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const template<class KeyType, class KeyValueCompare> - std::pair<const_iterator,const_iterator> bounded_range - (const KeyType &lower_key, const KeyType &upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { - detail::key_nodeptr_comp<KeyValueCompare, treap_impl> - key_node_comp(comp, this); - std::pair<node_ptr, node_ptr> ret - (node_algorithms::bounded_range - (this->priv_header_ptr(), lower_key, upper_key, key_node_comp, left_closed, right_closed)); - return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this)); - } + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const treap_impl &src, Cloner cloner, Disposer disposer) - { - this->clear_and_dispose(disposer); - if(!src.empty()){ - detail::exception_disposer<treap_impl, Disposer> - rollback(*this, disposer); - node_algorithms::clone - (src.priv_header_ptr() - ,this->priv_header_ptr() - ,detail::node_cloner<Cloner, treap_impl>(cloner, this) - ,detail::node_disposer<Disposer, treap_impl>(disposer, this)); - this->priv_size_traits().set_size(src.priv_size_traits().get_size()); - this->priv_comp() = src.priv_comp(); - rollback.release(); - } - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - //! <b>Effects</b>: Unlinks the leftmost node from the treap. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the treap and the treap can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the treap. - pointer unlink_leftmost_without_rebalance() - { - node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance - (this->priv_header_ptr())); - if(!to_be_disposed) - return 0; - this->priv_size_traits().decrement(); - if(safemode_or_autounlink)//If this is commented does not work with normal_link - node_algorithms::init(to_be_disposed); - return get_real_value_traits().to_value_ptr(to_be_disposed); - } + //! @copydoc ::boost::intrusive::bstree::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any treap. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! treap with with_this. The treap does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering and priority rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { - node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this) - , this->priv_header_ptr() - , get_real_value_traits().to_node_ptr(with_this)); - if(safemode_or_autounlink) - node_algorithms::init(replace_this.pointed_node()); - } + //! @copydoc ::boost::intrusive::bstree::iterator_to(reference) + iterator iterator_to(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return iterator (value_traits::to_node_ptr(value), 0); - } + //! @copydoc ::boost::intrusive::bstree::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { - BOOST_STATIC_ASSERT((!stateful_value_traits)); - return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0); - } + //! @copydoc ::boost::intrusive::bstree::init_node(reference) + static void init_node(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return iterator (value_traits::to_node_ptr(value), this); } + //! @copydoc ::boost::intrusive::bstree::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); - //! <b>Requires</b>: value must be an lvalue and shall be in a set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); } + //! @copydoc ::boost::intrusive::bstree::replace_node + void replace_node(iterator replace_this, reference with_this); - //! <b>Requires</b>: value shall not be in a treap. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { node_algorithms::init(value_traits::to_node_ptr(value)); } + //! @copydoc ::boost::intrusive::bstree::remove_node + void remove_node(reference value); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED /// @cond private: @@ -1605,197 +1047,66 @@ class treap_impl return b.unconst(); } /// @endcond - - private: - static treap_impl &priv_container_from_end_iterator(const const_iterator &end_iterator) - { - header_plus_size *r = detail::parent_from_member<header_plus_size, node> - ( boost::intrusive::detail::to_raw_pointer(end_iterator.pointed_node()), &header_plus_size::header_); - typename node_plus_pred_t::header_plus_priority_size *n = - detail::parent_from_member - < typename node_plus_pred_t::header_plus_priority_size - , header_plus_size> - (r, &node_plus_pred_t::header_plus_priority_size::header_plus_size_); - node_plus_pred_t *pn = detail::parent_from_member - < node_plus_pred_t - , typename node_plus_pred_t::header_plus_priority_size> - (n, &node_plus_pred_t::header_plus_priority_size_); - data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(pn, &data_t::node_plus_pred_); - treap_impl *tr = detail::parent_from_member<treap_impl, data_t>(d, &treap_impl::data_); - return *tr; - } - - static treap_impl &priv_container_from_iterator(const const_iterator &it) - { return priv_container_from_end_iterator(it.end_iterator_from_it()); } }; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator< -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -bool operator== -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ - typedef treap_impl<Config> tree_type; - typedef typename tree_type::const_iterator const_iterator; +bool operator< (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); - if(tree_type::constant_time_size && x.size() != y.size()){ - return false; - } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } -} +template<class T, class ...Options> +bool operator==(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ return !(x == y); } +bool operator!= (const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ return y < x; } +bool operator>(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ return !(y < x); } +bool operator<=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y) -#else -(const treap_impl<Config> &x, const treap_impl<Config> &y) -#endif -{ return !(x < y); } +bool operator>=(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y); -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(treap_impl<T, Options...> &x, treap_impl<T, Options...> &y) -#else -(treap_impl<Config> &x, treap_impl<Config> &y) -#endif -{ x.swap(y); } +void swap(treap_impl<T, Options...> &x, treap_impl<T, Options...> &y); -/// @cond -#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - > -#else +#endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + +//! Helper metafunction to define a \c treap that yields to the same type when the +//! same options (either explicitly or implicitly) are used. +#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> +#else +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif -struct make_treap_opt +struct make_treap { typedef typename pack_options - < treap_set_defaults<T>, + < treap_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type packed_options; + typedef typename detail::get_value_traits - <T, typename packed_options::value_traits>::type value_traits; + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; - typedef treap_setopt + typedef treap_impl < value_traits , typename packed_options::compare , typename packed_options::priority , typename packed_options::size_type , packed_options::constant_time_size - > type; -}; -/// @endcond - -//! Helper metafunction to define a \c treap that yields to the same type when the -//! same options (either explicitly or implicitly) are used. -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class ...Options> -#else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> -#endif -struct make_trie -{ - /// @cond - typedef treap_impl - < typename make_treap_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -1803,23 +1114,23 @@ struct make_trie #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class treap - : public make_trie<T, + : public make_treap<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type { - typedef typename make_trie + typedef typename make_treap <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1830,16 +1141,17 @@ class treap typedef typename Base::value_compare value_compare; typedef typename Base::priority_compare priority_compare; typedef typename Base::value_traits value_traits; - typedef typename Base::real_value_traits real_value_traits; typedef typename Base::iterator iterator; typedef typename Base::const_iterator const_iterator; + typedef typename Base::reverse_iterator reverse_iterator; + typedef typename Base::const_reverse_iterator const_reverse_iterator; //Assert if passed value traits are compatible with the type - BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value)); + BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - treap( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, pcmp, v_traits) {} @@ -1856,7 +1168,7 @@ class treap {} treap& operator=(BOOST_RV_REF(treap) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<treap&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static treap &container_from_end_iterator(iterator end_iterator) { return static_cast<treap &>(Base::container_from_end_iterator(end_iterator)); } @@ -1864,19 +1176,18 @@ class treap static const treap &container_from_end_iterator(const_iterator end_iterator) { return static_cast<const treap &>(Base::container_from_end_iterator(end_iterator)); } - static treap &container_from_it(iterator it) + static treap &container_from_iterator(iterator it) { return static_cast<treap &>(Base::container_from_iterator(it)); } - static const treap &container_from_it(const_iterator it) + static const treap &container_from_iterator(const_iterator it) { return static_cast<const treap &>(Base::container_from_iterator(it)); } }; #endif - } //namespace intrusive } //namespace boost #include <boost/intrusive/detail/config_end.hpp> -#endif //BOOST_INTRUSIVE_TRIE_HPP +#endif //BOOST_INTRUSIVE_TREAP_HPP diff --git a/boost/intrusive/treap_algorithms.hpp b/boost/intrusive/treap_algorithms.hpp index 967e7315cf..787c3d0bac 100644 --- a/boost/intrusive/treap_algorithms.hpp +++ b/boost/intrusive/treap_algorithms.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012. +// (C) Copyright Ion Gaztanaga 2006-2014. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,21 +13,62 @@ #ifndef BOOST_INTRUSIVE_TREAP_ALGORITHMS_HPP #define BOOST_INTRUSIVE_TREAP_ALGORITHMS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <cstddef> -#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/detail/assert.hpp> -#include <boost/intrusive/pointer_traits.hpp> -#include <boost/intrusive/detail/utilities.hpp> -#include <boost/intrusive/detail/tree_algorithms.hpp> +#include <boost/intrusive/detail/algo_type.hpp> +#include <boost/intrusive/bstree_algorithms.hpp> #include <algorithm> namespace boost { namespace intrusive { +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + +namespace detail +{ + +template<class ValueTraits, class NodePtrPrioCompare, class ExtraChecker> +struct treap_node_extra_checker + : public ExtraChecker +{ + typedef ExtraChecker base_checker_t; + typedef ValueTraits value_traits; + typedef typename value_traits::node_traits node_traits; + typedef typename node_traits::const_node_ptr const_node_ptr; + + typedef typename base_checker_t::return_type return_type; + + treap_node_extra_checker(const NodePtrPrioCompare& prio_comp, ExtraChecker extra_checker) + : base_checker_t(extra_checker), prio_comp_(prio_comp) + {} + + void operator () (const const_node_ptr& p, + const return_type& check_return_left, const return_type& check_return_right, + return_type& check_return) + { + if (node_traits::get_left(p)) + BOOST_INTRUSIVE_INVARIANT_ASSERT(!prio_comp_(node_traits::get_left(p), p)); + if (node_traits::get_right(p)) + BOOST_INTRUSIVE_INVARIANT_ASSERT(!prio_comp_(node_traits::get_right(p), p)); + base_checker_t::operator()(p, check_return_left, check_return_right, check_return); + } + + const NodePtrPrioCompare prio_comp_; +}; + +} // namespace detail + +#endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! treap_algorithms provides basic algorithms to manipulate //! nodes forming a treap. //! @@ -47,7 +88,7 @@ namespace intrusive { //! //! <b>Typedefs</b>: //! -//! <tt>node</tt>: The type of the node that forms the circular list +//! <tt>node</tt>: The type of the node that forms the treap //! //! <tt>node_ptr</tt>: A pointer to a node //! @@ -68,6 +109,9 @@ namespace intrusive { //! <tt>static void set_right(node_ptr n, node_ptr right);</tt> template<class NodeTraits> class treap_algorithms + #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public bstree_algorithms<NodeTraits> + #endif { public: typedef NodeTraits node_traits; @@ -78,32 +122,10 @@ class treap_algorithms /// @cond private: - class remove_on_destroy - { - remove_on_destroy(const remove_on_destroy&); - remove_on_destroy& operator=(const remove_on_destroy&); - public: - remove_on_destroy(const node_ptr & header, const node_ptr & z) - : header_(header), z_(z), remove_it_(true) - {} - ~remove_on_destroy() - { - if(remove_it_){ - tree_algorithms::erase(header_, z_); - } - } - - void release() - { remove_it_ = false; } - - const node_ptr header_; - const node_ptr z_; - bool remove_it_; - }; + typedef bstree_algorithms<NodeTraits> bstree_algo; class rerotate_on_destroy { - rerotate_on_destroy(const remove_on_destroy&); rerotate_on_destroy& operator=(const rerotate_on_destroy&); public: @@ -129,38 +151,28 @@ class treap_algorithms static void rotate_up_n(const node_ptr header, const node_ptr p, std::size_t n) { - for( node_ptr p_parent = NodeTraits::get_parent(p) - ; n-- - ; p_parent = NodeTraits::get_parent(p)){ - //Check if left child - if(p == NodeTraits::get_left(p_parent)){ - tree_algorithms::rotate_right(p_parent, header); + node_ptr p_parent(NodeTraits::get_parent(p)); + node_ptr p_grandparent(NodeTraits::get_parent(p_parent)); + while(n--){ + if(p == NodeTraits::get_left(p_parent)){ //p is left child + bstree_algo::rotate_right(p_parent, p, p_grandparent, header); } - else{ //Right child - tree_algorithms::rotate_left(p_parent, header); + else{ //p is right child + bstree_algo::rotate_left(p_parent, p, p_grandparent, header); } + p_parent = p_grandparent; + p_grandparent = NodeTraits::get_parent(p_parent); } } - typedef detail::tree_algorithms<NodeTraits> tree_algorithms; - - static node_ptr uncast(const const_node_ptr & ptr) - { return pointer_traits<node_ptr>::const_cast_from(ptr); } - /// @endcond public: - static node_ptr begin_node(const const_node_ptr & header) - { return tree_algorithms::begin_node(header); } - - static node_ptr end_node(const const_node_ptr & header) - { return tree_algorithms::end_node(header); } - //! This type is the information that will be //! filled by insert_unique_check struct insert_commit_data /// @cond - : public tree_algorithms::insert_commit_data + : public bstree_algo::insert_commit_data /// @endcond { /// @cond @@ -168,361 +180,118 @@ class treap_algorithms /// @endcond }; - //! <b>Requires</b>: header1 and header2 must be the header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two trees. After the function header1 will contain - //! links to the second tree and header2 will have links to the first tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static void swap_tree(const node_ptr & header1, const node_ptr & header2) - { return tree_algorithms::swap_tree(header1, header2); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & node2) - { - if(node1 == node2) - return; + //! @copydoc ::boost::intrusive::bstree_algorithms::get_header(const const_node_ptr&) + static node_ptr get_header(const const_node_ptr & n); - node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2)); - swap_nodes(node1, header1, node2, header2); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::begin_node + static node_ptr begin_node(const const_node_ptr & header); - //! <b>Requires</b>: node1 and node2 can't be header nodes - //! of two trees with header header1 and header2. - //! - //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted - //! in the position node2 before the function. node2 will be inserted in the - //! position node1 had before the function. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! node1 and node2 are not equivalent according to the ordering rules. - //! - //!Experimental function - static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2) - { tree_algorithms::swap_nodes(node1, header1, node2, header2); } + //! @copydoc ::boost::intrusive::bstree_algorithms::end_node + static node_ptr end_node(const const_node_ptr & header); - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing and comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node) - { - if(node_to_be_replaced == new_node) - return; - replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_tree + static void swap_tree(const node_ptr & header1, const node_ptr & header2); - //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree - //! with header "header" and new_node must not be inserted in a tree. - //! - //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the - //! tree with new_node. The tree does not need to be rebalanced - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! new_node is not equivalent to node_to_be_replaced according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - //! - //!Experimental function - static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node) - { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); } + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & node2); - //! <b>Requires</b>: node is a tree node but not the header. - //! - //! <b>Effects</b>: Unlinks the node and rebalances the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: If "pcomp" throws, strong guarantee + //! @copydoc ::boost::intrusive::bstree_algorithms::swap_nodes(const node_ptr&,const node_ptr&,const node_ptr&,const node_ptr&) + static void swap_nodes(const node_ptr & node1, const node_ptr & header1, const node_ptr & node2, const node_ptr & header2); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & new_node); + + //! @copydoc ::boost::intrusive::bstree_algorithms::replace_node(const node_ptr&,const node_ptr&,const node_ptr&) + static void replace_node(const node_ptr & node_to_be_replaced, const node_ptr & header, const node_ptr & new_node); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink(const node_ptr&) template<class NodePtrPriorityCompare> static void unlink(const node_ptr & node, NodePtrPriorityCompare pcomp) { node_ptr x = NodeTraits::get_parent(node); if(x){ - while(!is_header(x)) + while(!bstree_algo::is_header(x)) x = NodeTraits::get_parent(x); erase(x, node, pcomp); } } - //! <b>Requires</b>: header is the header of a tree. - //! - //! <b>Effects</b>: Unlinks the leftmost node from the tree, and - //! updates the header link to the new leftmost node. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header) - { return tree_algorithms::unlink_leftmost_without_rebalance(header); } - - //! <b>Requires</b>: node is a node of the tree or an node initialized - //! by init(...). - //! - //! <b>Effects</b>: Returns true if the node is initialized by init(). - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - static bool unique(const const_node_ptr & node) - { return tree_algorithms::unique(node); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::unlink_leftmost_without_rebalance + static node_ptr unlink_leftmost_without_rebalance(const node_ptr & header); - //! <b>Requires</b>: node is a node of the tree but it's not the header. - //! - //! <b>Effects</b>: Returns the number of nodes of the subtree. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t count(const const_node_ptr & node) - { return tree_algorithms::count(node); } + //! @copydoc ::boost::intrusive::bstree_algorithms::unique(const const_node_ptr&) + static bool unique(const const_node_ptr & node); - //! <b>Requires</b>: header is the header node of the tree. - //! - //! <b>Effects</b>: Returns the number of nodes above the header. - //! - //! <b>Complexity</b>: Linear time. - //! - //! <b>Throws</b>: Nothing. - static std::size_t size(const const_node_ptr & header) - { return tree_algorithms::size(header); } + //! @copydoc ::boost::intrusive::bstree_algorithms::size(const const_node_ptr&) + static std::size_t size(const const_node_ptr & header); - //! <b>Requires</b>: p is a node from the tree except the header. - //! - //! <b>Effects</b>: Returns the next node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr next_node(const node_ptr & p) - { return tree_algorithms::next_node(p); } + //! @copydoc ::boost::intrusive::bstree_algorithms::next_node(const node_ptr&) + static node_ptr next_node(const node_ptr & node); - //! <b>Requires</b>: p is a node from the tree except the leftmost node. - //! - //! <b>Effects</b>: Returns the previous node of the tree. - //! - //! <b>Complexity</b>: Average constant time. - //! - //! <b>Throws</b>: Nothing. - static node_ptr prev_node(const node_ptr & p) - { return tree_algorithms::prev_node(p); } + //! @copydoc ::boost::intrusive::bstree_algorithms::prev_node(const node_ptr&) + static node_ptr prev_node(const node_ptr & node); - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: After the function unique(node) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init(const node_ptr & node) - { tree_algorithms::init(node); } + //! @copydoc ::boost::intrusive::bstree_algorithms::init(const node_ptr&) + static void init(const node_ptr & node); - //! <b>Requires</b>: node must not be part of any tree. - //! - //! <b>Effects</b>: Initializes the header to represent an empty tree. - //! unique(header) == true. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree. - static void init_header(const node_ptr & header) - { - tree_algorithms::init_header(header); - } + //! @copydoc ::boost::intrusive::bstree_algorithms::init_header(const node_ptr&) + static void init_header(const node_ptr & header); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - //! <b>Requires</b>: header must be the header of a tree, z a node - //! of that tree and z != header. - //! - //! <b>Effects</b>: Erases node "z" from the tree with header "header". - //! - //! <b>Complexity</b>: Amortized constant time. - //! - //! <b>Throws</b>: If "pcomp" throws, strong guarantee. + //! @copydoc ::boost::intrusive::bstree_algorithms::erase(const node_ptr&,const node_ptr&) template<class NodePtrPriorityCompare> static node_ptr erase(const node_ptr & header, const node_ptr & z, NodePtrPriorityCompare pcomp) { rebalance_for_erasure(header, z, pcomp); - tree_algorithms::erase(header, z); -// assert(check_invariant(header, pcomp)); + bstree_algo::erase(header, z); return z; } - //! <b>Requires</b>: "cloner" must be a function - //! object taking a node_ptr and returning a new cloned node of it. "disposer" must - //! take a node_ptr and shouldn't throw. - //! - //! <b>Effects</b>: First empties target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! Then, duplicates the entire tree pointed by "source_header" cloning each - //! source node with <tt>node_ptr Cloner::operator()(const node_ptr &)</tt> to obtain - //! the nodes of the target tree. If "cloner" throws, the cloned target nodes - //! are disposed using <tt>void disposer(const node_ptr &)</tt>. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::bstree_algorithms::clone(const const_node_ptr&,const node_ptr&,Cloner,Disposer) template <class Cloner, class Disposer> static void clone - (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer) - { - tree_algorithms::clone(source_header, target_header, cloner, disposer); - } + (const const_node_ptr & source_header, const node_ptr & target_header, Cloner cloner, Disposer disposer); - //! <b>Requires</b>: "disposer" must be an object function - //! taking a node_ptr parameter and shouldn't throw. - //! - //! <b>Effects</b>: Empties the target tree calling - //! <tt>void disposer::operator()(const node_ptr &)</tt> for every node of the tree - //! except the header. - //! - //! <b>Complexity</b>: Linear to the number of element of the source tree plus the. - //! number of elements of tree target tree when calling this function. - //! - //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed. + //! @copydoc ::boost::intrusive::bstree_algorithms::clear_and_dispose(const node_ptr&,Disposer) template<class Disposer> - static void clear_and_dispose(const node_ptr & header, Disposer disposer) - { tree_algorithms::clear_and_dispose(header, disposer); } + static void clear_and_dispose(const node_ptr & header, Disposer disposer); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is - //! not less than "key" according to "comp" or "header" if that element does - //! not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::lower_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr lower_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::lower_bound(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the first element that is greater - //! than "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::upper_bound(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr upper_bound - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::upper_bound(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to - //! "key" according to "comp" or "header" if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::find(const const_node_ptr&, const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static node_ptr find - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::find(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! - //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing - //! all elements that are equivalent to "key" according to "comp" or an - //! empty range that indicates the position where those elements would be - //! if they there are no equivalent elements. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. + //! @copydoc ::boost::intrusive::bstree_algorithms::equal_range(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> equal_range - (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp) - { return tree_algorithms::equal_range(header, key, comp); } + (const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); - //! <b>Requires</b>: "header" must be the header node of a tree. - //! KeyNodePtrCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + //! @copydoc ::boost::intrusive::bstree_algorithms::bounded_range(const const_node_ptr&,const KeyType&,const KeyType&,KeyNodePtrCompare,bool,bool) template<class KeyType, class KeyNodePtrCompare> static std::pair<node_ptr, node_ptr> bounded_range (const const_node_ptr & header, const KeyType &lower_key, const KeyType &upper_key, KeyNodePtrCompare comp - , bool left_closed, bool right_closed) - { return tree_algorithms::bounded_range(header, lower_key, upper_key, comp, left_closed, right_closed); } + , bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::bstree_algorithms::count(const const_node_ptr&,const KeyType&,KeyNodePtrCompare) + template<class KeyType, class KeyNodePtrCompare> + static std::size_t count(const const_node_ptr & header, const KeyType &key, KeyNodePtrCompare comp); + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Requires</b>: "h" must be the header node of a tree. //! NodePtrCompare is a function object that induces a strict weak @@ -544,7 +313,7 @@ class treap_algorithms (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::insert_equal_upper_bound_check(h, new_node, comp, commit_data); + bstree_algo::insert_equal_upper_bound_check(h, new_node, comp, commit_data); rebalance_check_and_commit(h, new_node, pcomp, commit_data); return new_node; } @@ -569,7 +338,7 @@ class treap_algorithms (const node_ptr & h, const node_ptr & new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::insert_equal_lower_bound_check(h, new_node, comp, commit_data); + bstree_algo::insert_equal_lower_bound_check(h, new_node, comp, commit_data); rebalance_check_and_commit(h, new_node, pcomp, commit_data); return new_node; } @@ -597,7 +366,7 @@ class treap_algorithms (const node_ptr & h, const node_ptr & hint, const node_ptr & new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::insert_equal_check(h, hint, new_node, comp, commit_data); + bstree_algo::insert_equal_check(h, hint, new_node, comp, commit_data); rebalance_check_and_commit(h, new_node, pcomp, commit_data); return new_node; } @@ -625,7 +394,7 @@ class treap_algorithms (const node_ptr & header, const node_ptr & pos, const node_ptr & new_node, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::insert_before_check(header, pos, commit_data); + bstree_algo::insert_before_check(header, pos, commit_data); rebalance_check_and_commit(header, new_node, pcomp, commit_data); return new_node; } @@ -651,7 +420,7 @@ class treap_algorithms static void push_back(const node_ptr & header, const node_ptr & new_node, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::push_back_check(header, commit_data); + bstree_algo::push_back_check(header, commit_data); rebalance_check_and_commit(header, new_node, pcomp, commit_data); } @@ -676,7 +445,7 @@ class treap_algorithms static void push_front(const node_ptr & header, const node_ptr & new_node, NodePtrPriorityCompare pcomp) { insert_commit_data commit_data; - tree_algorithms::push_front_check(header, commit_data); + bstree_algo::push_front_check(header, commit_data); rebalance_check_and_commit(header, new_node, pcomp, commit_data); } @@ -721,7 +490,7 @@ class treap_algorithms ,insert_commit_data &commit_data) { std::pair<node_ptr, bool> ret = - tree_algorithms::insert_unique_check(header, key, comp, commit_data); + bstree_algo::insert_unique_check(header, key, comp, commit_data); if(ret.second) rebalance_after_insertion_check(header, commit_data.node, key, pcomp, commit_data.rotations); return ret; @@ -772,7 +541,7 @@ class treap_algorithms ,KeyNodePtrCompare comp, KeyNodePtrPrioCompare pcomp, insert_commit_data &commit_data) { std::pair<node_ptr, bool> ret = - tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data); + bstree_algo::insert_unique_check(header, hint, key, comp, commit_data); if(ret.second) rebalance_after_insertion_check(header, commit_data.node, key, pcomp, commit_data.rotations); return ret; @@ -798,35 +567,19 @@ class treap_algorithms static void insert_unique_commit (const node_ptr & header, const node_ptr & new_node, const insert_commit_data &commit_data) { - tree_algorithms::insert_unique_commit(header, new_node, commit_data); - rebalance_after_insertion_commit(header, new_node, commit_data.rotations); + bstree_algo::insert_unique_commit(header, new_node, commit_data); + rotate_up_n(header, new_node, commit_data.rotations); } - //! <b>Requires</b>: "n" must be a node inserted in a tree. - //! - //! <b>Effects</b>: Returns a pointer to the header node of the tree. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: Nothing. - static node_ptr get_header(const node_ptr & n) - { return tree_algorithms::get_header(n); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::bstree_algorithms::is_header + static bool is_header(const const_node_ptr & p); + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED /// @cond private: - //! <b>Requires</b>: p is a node of a tree. - //! - //! <b>Effects</b>: Returns true if p is the header of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - static bool is_header(const const_node_ptr & p) - { - return tree_algorithms::is_header(p); - } - template<class NodePtrPriorityCompare> static void rebalance_for_erasure(const node_ptr & header, const node_ptr & z, NodePtrPriorityCompare pcomp) { @@ -836,11 +589,12 @@ class treap_algorithms node_ptr z_left = NodeTraits::get_left(z); node_ptr z_right = NodeTraits::get_right(z); while(z_left || z_right){ + const node_ptr z_parent(NodeTraits::get_parent(z)); if(!z_right || (z_left && pcomp(z_left, z_right))){ - tree_algorithms::rotate_right(z, header); + bstree_algo::rotate_right(z, z_left, z_parent, header); } else{ - tree_algorithms::rotate_left(z, header); + bstree_algo::rotate_left(z, z_right, z_parent, header); } ++n; z_left = NodeTraits::get_left(z); @@ -855,11 +609,10 @@ class treap_algorithms { rebalance_after_insertion_check(h, commit_data.node, new_node, pcomp, commit_data.rotations); //No-throw - tree_algorithms::insert_unique_commit(h, new_node, commit_data); - rebalance_after_insertion_commit(h, new_node, commit_data.rotations); + bstree_algo::insert_unique_commit(h, new_node, commit_data); + rotate_up_n(h, new_node, commit_data.rotations); } - template<class Key, class KeyNodePriorityCompare> static void rebalance_after_insertion_check (const const_node_ptr &header, const const_node_ptr & up, const Key &k @@ -876,22 +629,6 @@ class treap_algorithms num_rotations = n; } - static void rebalance_after_insertion_commit(const node_ptr & header, const node_ptr & p, std::size_t n) - { - // Now execute n rotations - for( node_ptr p_parent = NodeTraits::get_parent(p) - ; n-- - ; p_parent = NodeTraits::get_parent(p)){ - //Check if left child - if(p == NodeTraits::get_left(p_parent)){ - tree_algorithms::rotate_right(p_parent, header); - } - else{ //Right child - tree_algorithms::rotate_left(p_parent, header); - } - } - } - template<class NodePtrPriorityCompare> static bool check_invariant(const const_node_ptr & header, NodePtrPriorityCompare pcomp) { @@ -912,6 +649,22 @@ class treap_algorithms /// @endcond }; +/// @cond + +template<class NodeTraits> +struct get_algo<TreapAlgorithms, NodeTraits> +{ + typedef treap_algorithms<NodeTraits> type; +}; + +template <class ValueTraits, class NodePtrCompare, class ExtraChecker> +struct get_node_checker<TreapAlgorithms, ValueTraits, NodePtrCompare, ExtraChecker> +{ + typedef detail::bstree_node_checker<ValueTraits, NodePtrCompare, ExtraChecker> type; +}; + +/// @endcond + } //namespace intrusive } //namespace boost diff --git a/boost/intrusive/treap_set.hpp b/boost/intrusive/treap_set.hpp index 66adfaf207..ef68b0595e 100644 --- a/boost/intrusive/treap_set.hpp +++ b/boost/intrusive/treap_set.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2007-2012 +// (C) Copyright Ion Gaztanaga 2007-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -9,15 +9,19 @@ // See http://www.boost.org/libs/intrusive for documentation. // ///////////////////////////////////////////////////////////////////////////// -#ifndef BOOST_INTRUSIVE_TRIE_SET_HPP -#define BOOST_INTRUSIVE_TRIE_SET_HPP +#ifndef BOOST_INTRUSIVE_TREAP_SET_HPP +#define BOOST_INTRUSIVE_TREAP_SET_HPP + +#if defined(_MSC_VER) +# pragma once +#endif #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/treap.hpp> #include <boost/intrusive/detail/mpl.hpp> -#include <boost/move/move.hpp> -#include <iterator> +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { @@ -36,14 +40,16 @@ namespace intrusive { #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class treap_set_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public treap_impl<ValueTraits, VoidOrKeyComp, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> +#endif { /// @cond - typedef treap_impl<Config> tree_type; - //! This class is - //! movable + public: + typedef treap_impl<ValueTraits, VoidOrKeyComp, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_set_impl) typedef tree_type implementation_defined; @@ -72,12 +78,7 @@ class treap_set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = implementation_defined::constant_time_size; public: //! <b>Effects</b>: Constructs an empty treap_set. @@ -87,10 +88,10 @@ class treap_set_impl //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) //! or the copy constructor of the value_compare object throws. - treap_set_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, pcmp, v_traits) + explicit treap_set_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, pcmp, v_traits) {} //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. @@ -110,1255 +111,349 @@ class treap_set_impl , const value_compare &cmp = value_compare() , const priority_compare &pcmp = priority_compare() , const value_traits &v_traits = value_traits()) - : tree_(true, b, e, cmp, pcmp, v_traits) + : tree_type(true, b, e, cmp, pcmp, v_traits) {} //! <b>Effects</b>: to-do //! treap_set_impl(BOOST_RV_REF(treap_set_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} //! <b>Effects</b>: to-do //! treap_set_impl& operator=(BOOST_RV_REF(treap_set_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } + { return static_cast<treap_set_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_set - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~treap_set_impl() - {} + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::treap::~treap() + ~treap_set_impl(); - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } + //! @copydoc ::boost::intrusive::treap::begin() + iterator begin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } + //! @copydoc ::boost::intrusive::treap::begin()const + const_iterator begin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } + //! @copydoc ::boost::intrusive::treap::cbegin()const + const_iterator cbegin() const; - //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } + //! @copydoc ::boost::intrusive::treap::end() + iterator end(); - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } + //! @copydoc ::boost::intrusive::treap::end()const + const_iterator end() const; - //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator top() - { return tree_.top(); } + //! @copydoc ::boost::intrusive::treap::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree.. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator top() const - { return this->ctop(); } + //! @copydoc ::boost::intrusive::treap::rbegin() + reverse_iterator rbegin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree.. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator ctop() const - { return tree_.ctop(); } + //! @copydoc ::boost::intrusive::treap::rbegin()const + const_reverse_iterator rbegin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } + //! @copydoc ::boost::intrusive::treap::crbegin()const + const_reverse_iterator crbegin() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } + //! @copydoc ::boost::intrusive::treap::rend() + reverse_iterator rend(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } + //! @copydoc ::boost::intrusive::treap::rend()const + const_reverse_iterator rend() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } + //! @copydoc ::boost::intrusive::treap::crend()const + const_reverse_iterator crend() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } + //! @copydoc ::boost::intrusive::treap::container_from_end_iterator(iterator) + static treap_set_impl &container_from_end_iterator(iterator end_iterator); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } + //! @copydoc ::boost::intrusive::treap::container_from_end_iterator(const_iterator) + static const treap_set_impl &container_from_end_iterator(const_iterator end_iterator); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } + //! @copydoc ::boost::intrusive::treap::container_from_iterator(iterator) + static treap_set_impl &container_from_iterator(iterator it); - //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rtop() - { return tree_.rtop(); } + //! @copydoc ::boost::intrusive::treap::container_from_iterator(const_iterator) + static const treap_set_impl &container_from_iterator(const_iterator it); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rtop() const - { return tree_.crtop(); } + //! @copydoc ::boost::intrusive::treap::key_comp()const + key_compare key_comp() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crtop() const - { return tree_.crtop(); } + //! @copydoc ::boost::intrusive::treap::value_comp()const + value_compare value_comp() const; - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of treap_set. - //! - //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static treap_set_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<treap_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &treap_set_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of treap_set. - //! - //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const treap_set_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<treap_set_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &treap_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of set. - //! - //! <b>Effects</b>: Returns a reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static treap_set_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<treap_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &treap_set_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of set. - //! - //! <b>Effects</b>: Returns a const reference to the set associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Logarithmic. - static const treap_set_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<treap_set_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &treap_set_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } + //! @copydoc ::boost::intrusive::treap::empty()const + bool empty() const; - //! <b>Effects</b>: Returns the value_compare object used by the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } + //! @copydoc ::boost::intrusive::treap::size()const + size_type size() const; - //! <b>Effects</b>: Returns the priority_compare object used by the treap_set. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If priority_compare copy-constructor throws. - priority_compare priority_comp() const - { return tree_.priority_comp(); } + //! @copydoc ::boost::intrusive::treap::swap + void swap(treap_set_impl& other); - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } + //! @copydoc ::boost::intrusive::treap::clone_from + template <class Cloner, class Disposer> + void clone_from(const treap_set_impl &src, Cloner cloner, Disposer disposer); - //! <b>Effects</b>: Returns the number of elements stored in the treap_set. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } + //! @copydoc ::boost::intrusive::treap::top() + iterator top(); - //! <b>Effects</b>: Swaps the contents of two sets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(treap_set_impl& other) - { tree_.swap(other.tree_); } + //! @copydoc ::boost::intrusive::treap::top()const + const_iterator top() const; - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const treap_set_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } + //! @copydoc ::boost::intrusive::treap::ctop()const + const_iterator ctop() const; - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to inserts value into the treap_set. - //! - //! <b>Returns</b>: If the value - //! is not already present inserts it and returns a pair containing the - //! iterator to the new value and true. If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare or priority_compare ordering function throw. - //! Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::rtop() + reverse_iterator rtop(); + + //! @copydoc ::boost::intrusive::treap::rtop()const + const_reverse_iterator rtop() const; + + //! @copydoc ::boost::intrusive::treap::crtop()const + const_reverse_iterator crtop() const; + + //! @copydoc ::boost::intrusive::treap::crtop() const + priority_compare priority_comp() const; + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::treap::insert_unique(reference) std::pair<iterator, bool> insert(reference value) - { return tree_.insert_unique(value); } + { return tree_type::insert_unique(value); } - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Tries to to insert x into the treap_set, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the - //! new element was inserted into the treap_set. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If the internal value_compare or priority_compare ordering - //! functions throw. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::insert_unique(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_unique(hint, value); } + { return tree_type::insert_unique(hint, value); } - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. - //! key_value_pcomp must be a comparison function that induces - //! the same strict weak ordering as priority_compare. The difference is that - //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using - //! a user provided key instead of the value itself. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Average complexity is at most logarithmic. - //! - //! <b>Throws</b>: If key_value_comp or key_value_pcomp ordering function throw. - //! Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! node that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that - //! part to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This gives a total - //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the treap_set. - template<class KeyType, class KeyValueCompare, class KeyValuePriorityCompare> + //! @copydoc ::boost::intrusive::treap::insert_unique_check(const KeyType&,KeyValueCompare,KeyValuePrioCompare,insert_commit_data&) + template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare> std::pair<iterator, bool> insert_check - ( const KeyType &key, KeyValueCompare key_value_comp, KeyValuePriorityCompare key_value_pcomp + ( const KeyType &key, KeyValueCompare key_value_comp, KeyValuePrioCompare key_value_pcomp , insert_commit_data &commit_data) - { return tree_.insert_unique_check(key, key_value_comp, key_value_pcomp, commit_data); } + { return tree_type::insert_unique_check(key, key_value_comp, key_value_pcomp, commit_data); } - //! <b>Requires</b>: key_value_comp must be a comparison function that induces - //! the same strict weak ordering as value_compare. - //! key_value_pcomp must be a comparison function that induces - //! the same strict weak ordering as priority_compare. The difference is that - //! key_value_pcomp and key_value_comp compare an arbitrary key with the contained values. - //! - //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using - //! a user provided key instead of the value itself, using "hint" - //! as a hint to where it will be inserted. - //! - //! <b>Returns</b>: If there is an equivalent value - //! returns a pair containing an iterator to the already present value - //! and false. If the value can be inserted returns true in the returned - //! pair boolean and fills "commit_data" that is meant to be used with - //! the "insert_commit" function. - //! - //! <b>Complexity</b>: Logarithmic in general, but it's amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If key_value_comp or key_value_pcomp ordering function throw. - //! Strong guarantee. - //! - //! <b>Notes</b>: This function is used to improve performance when constructing - //! a value_type is expensive: if there is an equivalent value - //! the constructed object must be discarded. Many times, the part of the - //! constructing that is used to impose the order is much cheaper to construct - //! than the value_type and this function offers the possibility to use that key - //! to check if the insertion will be successful. - //! - //! If the check is successful, the user can construct the value_type and use - //! "insert_commit" to insert the object in constant-time. This can give a total - //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)). - //! - //! "commit_data" remains valid for a subsequent "insert_commit" only if no more - //! objects are inserted or erased from the treap_set. - template<class KeyType, class KeyValueCompare, class KeyValuePriorityCompare> + //! @copydoc ::boost::intrusive::treap::insert_unique_check(const_iterator,const KeyType&,KeyValueCompare,KeyValuePrioCompare,insert_commit_data&) + template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare> std::pair<iterator, bool> insert_check ( const_iterator hint, const KeyType &key - , KeyValueCompare key_value_comp, KeyValuePriorityCompare key_value_pcomp + , KeyValueCompare key_value_comp, KeyValuePrioCompare key_value_pcomp , insert_commit_data &commit_data) - { return tree_.insert_unique_check(hint, key, key_value_comp, key_value_pcomp, commit_data); } + { return tree_type::insert_unique_check(hint, key, key_value_comp, key_value_pcomp, commit_data); } - //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data - //! must have been obtained from a previous call to "insert_check". - //! No objects should have been inserted or erased from the treap_set between - //! the "insert_check" that filled "commit_data" and the call to "insert_commit". - //! - //! <b>Effects</b>: Inserts the value in the treap_set using the information obtained - //! from the "commit_data" that a previous "insert_check" filled. - //! - //! <b>Returns</b>: An iterator to the newly inserted object. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function has only sense if a "insert_check" has been - //! previously executed to fill "commit_data". No value should be inserted or - //! erased between the "insert_check" and "insert_commit" calls. - iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return tree_.insert_unique_commit(value, commit_data); } - - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the treap_set. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If the internal value_compare or priority_compare ordering function - //! throw. Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::insert_unique(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_unique(b, e); } + { tree_type::insert_unique(b, e); } - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate. "value" must not be equal to any - //! inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the treap before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" treap ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be greater than - //! any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the treap in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key treap ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be less - //! than any inserted key according to the predicate. - //! - //! <b>Effects</b>: Inserts x into the treap in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key treap ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } + //! @copydoc ::boost::intrusive::treap::insert_unique_commit + iterator insert_commit(reference value, const insert_commit_data &commit_data) + { return tree_type::insert_unique_commit(value, commit_data); } - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::treap::insert_before + iterator insert_before(const_iterator pos, reference value); - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size()) + this->count(value)). - //! - //! <b>Throws</b>: If internal value_compare or priority_compare - //! ordering functions throw. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } + //! @copydoc ::boost::intrusive::treap::push_back + void push_back(reference value); - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp or internal priority_compare - //! ordering functions throw. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::push_front + void push_front(reference value); + + //! @copydoc ::boost::intrusive::treap::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::treap::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::treap::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::treap::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). Basic guarantee. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } + size_type erase_and_dispose(const_reference value, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp or internal priority_compare ordering functions throw. - //! Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::clear + void clear(); + + //! @copydoc ::boost::intrusive::treap::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } + void clear_and_dispose(Disposer disposer); - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::treap::count(const_reference)const size_type count(const_reference value) const - { return tree_.find(value) != end(); } + { return static_cast<size_type>(this->tree_type::find(value) != this->tree_type::cend()); } - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + //! @copydoc ::boost::intrusive::treap::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp) != end(); } + { return static_cast<size_type>(this->tree_type::find(key, comp) != this->tree_type::cend()); } - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::treap::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } + iterator lower_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } + //! @copydoc ::boost::intrusive::treap::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } + //! @copydoc ::boost::intrusive::treap::upper_bound(const_reference) + iterator upper_bound(const_reference value); - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } + iterator upper_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } + //! @copydoc ::boost::intrusive::treap::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } + //! @copydoc ::boost::intrusive::treap::find(const_reference) + iterator find(const_reference value); - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } + iterator find(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } + //! @copydoc ::boost::intrusive::treap::find(const_reference)const + const_iterator find(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } + const_iterator find(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference) std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } + { return this->tree_type::lower_bound_range(value); } - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } + { return this->tree_type::lower_bound_range(key, comp); } - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + //! @copydoc ::boost::intrusive::rbtree::equal_range(const_reference)const std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return tree_.equal_range(value); } + { return this->tree_type::lower_bound_range(value); } - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::rbtree::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } + { return this->tree_type::lower_bound_range(key, comp); } - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::treap::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::treap::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. - std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. - template<class KeyType, class KeyValueCompare> + //! @copydoc ::boost::intrusive::treap::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! treap_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! treap_set that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::iterator_to(reference) + iterator iterator_to(reference value); - //! <b>Requires</b>: value shall not be in a treap_set/treap_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } + //! @copydoc ::boost::intrusive::treap::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } + //! @copydoc ::boost::intrusive::treap::init_node(reference) + static void init_node(reference value); - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } + //! @copydoc ::boost::intrusive::treap::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); - //! <b>Returns</b>: The balance factor (alpha) used in this tree - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - float balance_factor() const - { return tree_.balance_factor(); } + //! @copydoc ::boost::intrusive::treap::replace_node + void replace_node(iterator replace_this, reference with_this); - //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0 - //! - //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances - //! the tree if the new balance factor is stricter (less) than the old factor. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - void balance_factor(float new_alpha) - { tree_.balance_factor(new_alpha); } - - /// @cond - friend bool operator==(const treap_set_impl &x, const treap_set_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::treap::remove_node + void remove_node(reference value); - friend bool operator<(const treap_set_impl &x, const treap_set_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y) -#else -(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y) -#endif -{ return !(x == y); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y) -#else -(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y) -#endif -{ return y < x; } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y) -#else -(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y) -#endif -{ return !(y < x); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y) -#else -(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y) -#endif -{ return !(x < y); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(treap_set_impl<T, Options...> &x, treap_set_impl<T, Options...> &y) -#else -(treap_set_impl<Config> &x, treap_set_impl<Config> &y) -#endif -{ x.swap(y); } //! Helper metafunction to define a \c treap_set that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_treap_set { - /// @cond - typedef treap_set_impl - < typename make_treap_opt<T, + typedef typename pack_options + < treap_defaults, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif - >::type - > implementation_defined; + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + + typedef treap_set_impl + < value_traits + , typename packed_options::compare + , typename packed_options::priority + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -1366,14 +461,14 @@ struct make_treap_set #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class treap_set : public make_treap_set<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1382,7 +477,7 @@ class treap_set typedef typename make_treap_set <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -1399,9 +494,9 @@ class treap_set //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - treap_set( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap_set( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, pcmp, v_traits) {} @@ -1418,7 +513,7 @@ class treap_set {} treap_set& operator=(BOOST_RV_REF(treap_set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<treap_set &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static treap_set &container_from_end_iterator(iterator end_iterator) { return static_cast<treap_set &>(Base::container_from_end_iterator(end_iterator)); } @@ -1449,14 +544,17 @@ class treap_set #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class VoidOrKeyComp, class VoidOrPrioComp, class SizeType, bool ConstantTimeSize, typename HeaderHolder> #endif class treap_multiset_impl +#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED + : public treap_impl<ValueTraits, VoidOrKeyComp, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> +#endif { /// @cond - typedef treap_impl<Config> tree_type; - + typedef treap_impl<ValueTraits, VoidOrKeyComp, VoidOrPrioComp, SizeType, ConstantTimeSize, HeaderHolder> tree_type; BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_multiset_impl) + typedef tree_type implementation_defined; /// @endcond @@ -1483,12 +581,7 @@ class treap_multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - static const bool constant_time_size = Config::constant_time_size; - - /// @cond - private: - tree_type tree_; - /// @endcond + static const bool constant_time_size = implementation_defined::constant_time_size; public: //! <b>Effects</b>: Constructs an empty treap_multiset. @@ -1497,11 +590,11 @@ class treap_multiset_impl //! //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor of the value_compare/priority_compare objects throw. - treap_multiset_impl( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) - : tree_(cmp, pcmp, v_traits) + //! or the copy constructor of the value_compare object throws. + explicit treap_multiset_impl( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(cmp, pcmp, v_traits) {} //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type. @@ -1511,1161 +604,326 @@ class treap_multiset_impl //! [b, e). //! //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using - //! comp and otherwise N * log N, where N is the distance between first and last + //! comp and otherwise N * log N, where N is std::distance(last, first). //! //! <b>Throws</b>: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or the copy constructor/operator() of the value_compare/priority_compare objects throw. + //! or the copy constructor/operator() of the value_compare object throws. template<class Iterator> treap_multiset_impl( Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) - : tree_(false, b, e, cmp, pcmp, v_traits) + , const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) + : tree_type(false, b, e, cmp, pcmp, v_traits) {} //! <b>Effects</b>: to-do //! treap_multiset_impl(BOOST_RV_REF(treap_multiset_impl) x) - : tree_(::boost::move(x.tree_)) + : tree_type(::boost::move(static_cast<tree_type&>(x))) {} //! <b>Effects</b>: to-do //! treap_multiset_impl& operator=(BOOST_RV_REF(treap_multiset_impl) x) - { tree_ = ::boost::move(x.tree_); return *this; } + { return static_cast<treap_multiset_impl&>(tree_type::operator=(::boost::move(static_cast<tree_type&>(x)))); } - //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_multiset - //! are not deleted (i.e. no destructors are called). - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - ~treap_multiset_impl() - {} + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::treap::~treap() + ~treap_multiset_impl(); - //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator begin() - { return tree_.begin(); } + //! @copydoc ::boost::intrusive::treap::begin() + iterator begin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator begin() const - { return tree_.begin(); } + //! @copydoc ::boost::intrusive::treap::begin()const + const_iterator begin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cbegin() const - { return tree_.cbegin(); } + //! @copydoc ::boost::intrusive::treap::cbegin()const + const_iterator cbegin() const; - //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator end() - { return tree_.end(); } + //! @copydoc ::boost::intrusive::treap::end() + iterator end(); - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator end() const - { return tree_.end(); } + //! @copydoc ::boost::intrusive::treap::end()const + const_iterator end() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator cend() const - { return tree_.cend(); } + //! @copydoc ::boost::intrusive::treap::cend()const + const_iterator cend() const; - //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator top() - { return tree_.top(); } + //! @copydoc ::boost::intrusive::treap::rbegin() + reverse_iterator rbegin(); - //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree.. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator top() const - { return this->ctop(); } + //! @copydoc ::boost::intrusive::treap::rbegin()const + const_reverse_iterator rbegin() const; - //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree.. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator ctop() const - { return tree_.ctop(); } + //! @copydoc ::boost::intrusive::treap::crbegin()const + const_reverse_iterator crbegin() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the - //! reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rbegin() - { return tree_.rbegin(); } + //! @copydoc ::boost::intrusive::treap::rend() + reverse_iterator rend(); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rbegin() const - { return tree_.rbegin(); } + //! @copydoc ::boost::intrusive::treap::rend()const + const_reverse_iterator rend() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning - //! of the reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crbegin() const - { return tree_.crbegin(); } + //! @copydoc ::boost::intrusive::treap::crend()const + const_reverse_iterator crend() const; - //! <b>Effects</b>: Returns a reverse_iterator pointing to the end - //! of the reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rend() - { return tree_.rend(); } + //! @copydoc ::boost::intrusive::treap::container_from_end_iterator(iterator) + static treap_multiset_impl &container_from_end_iterator(iterator end_iterator); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rend() const - { return tree_.rend(); } + //! @copydoc ::boost::intrusive::treap::container_from_end_iterator(const_iterator) + static const treap_multiset_impl &container_from_end_iterator(const_iterator end_iterator); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end - //! of the reversed treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crend() const - { return tree_.crend(); } + //! @copydoc ::boost::intrusive::treap::container_from_iterator(iterator) + static treap_multiset_impl &container_from_iterator(iterator it); - //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the - //! reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - reverse_iterator rtop() - { return tree_.rtop(); } + //! @copydoc ::boost::intrusive::treap::container_from_iterator(const_iterator) + static const treap_multiset_impl &container_from_iterator(const_iterator it); - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator rtop() const - { return tree_.crtop(); } + //! @copydoc ::boost::intrusive::treap::key_comp()const + key_compare key_comp() const; - //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object - //! of the reversed tree. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_reverse_iterator crtop() const - { return tree_.crtop(); } + //! @copydoc ::boost::intrusive::treap::value_comp()const + value_compare value_comp() const; - //! <b>Precondition</b>: end_iterator must be a valid end iterator - //! of treap_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static treap_multiset_impl &container_from_end_iterator(iterator end_iterator) - { - return *detail::parent_from_member<treap_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &treap_multiset_impl::tree_); - } - - //! <b>Precondition</b>: end_iterator must be a valid end const_iterator - //! of treap_multiset. - //! - //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const treap_multiset_impl &container_from_end_iterator(const_iterator end_iterator) - { - return *detail::parent_from_member<treap_multiset_impl, tree_type> - ( &tree_type::container_from_end_iterator(end_iterator) - , &treap_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static treap_multiset_impl &container_from_iterator(iterator it) - { - return *detail::parent_from_member<treap_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &treap_multiset_impl::tree_); - } - - //! <b>Precondition</b>: it must be a valid const_iterator of multiset. - //! - //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - static const treap_multiset_impl &container_from_iterator(const_iterator it) - { - return *detail::parent_from_member<treap_multiset_impl, tree_type> - ( &tree_type::container_from_iterator(it) - , &treap_multiset_impl::tree_); - } - - //! <b>Effects</b>: Returns the key_compare object used by the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If key_compare copy-constructor throws. - key_compare key_comp() const - { return tree_.value_comp(); } + //! @copydoc ::boost::intrusive::treap::empty()const + bool empty() const; - //! <b>Effects</b>: Returns the value_compare object used by the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If value_compare copy-constructor throws. - value_compare value_comp() const - { return tree_.value_comp(); } + //! @copydoc ::boost::intrusive::treap::size()const + size_type size() const; - //! <b>Effects</b>: Returns the priority_compare object used by the treap_multiset. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If priority_compare copy-constructor throws. - priority_compare priority_comp() const - { return tree_.priority_comp(); } + //! @copydoc ::boost::intrusive::treap::swap + void swap(treap_multiset_impl& other); - //! <b>Effects</b>: Returns true if the container is empty. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - bool empty() const - { return tree_.empty(); } + //! @copydoc ::boost::intrusive::treap::clone_from + template <class Cloner, class Disposer> + void clone_from(const treap_multiset_impl &src, Cloner cloner, Disposer disposer); - //! <b>Effects</b>: Returns the number of elements stored in the treap_multiset. - //! - //! <b>Complexity</b>: Linear to elements contained in *this if, - //! constant-time size option is enabled. Constant-time otherwise. - //! - //! <b>Throws</b>: Nothing. - size_type size() const - { return tree_.size(); } + //! @copydoc ::boost::intrusive::treap::top() + iterator top(); - //! <b>Effects</b>: Swaps the contents of two treap_multisets. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: If the swap() call for the comparison functor - //! found using ADL throws. Strong guarantee. - void swap(treap_multiset_impl& other) - { tree_.swap(other.tree_); } + //! @copydoc ::boost::intrusive::treap::top()const + const_iterator top() const; - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! Cloner should yield to nodes equivalent to the original nodes. - //! - //! <b>Effects</b>: Erases all the elements from *this - //! calling Disposer::operator()(pointer), clones all the - //! elements from src calling Cloner::operator()(const_reference ) - //! and inserts them on *this. Copies the predicate from the source container. - //! - //! If cloner throws, all cloned elements are unlinked and disposed - //! calling Disposer::operator()(pointer). - //! - //! <b>Complexity</b>: Linear to erased plus inserted elements. - //! - //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee. - template <class Cloner, class Disposer> - void clone_from(const treap_multiset_impl &src, Cloner cloner, Disposer disposer) - { tree_.clone_from(src.tree_, cloner, disposer); } + //! @copydoc ::boost::intrusive::treap::ctop()const + const_iterator ctop() const; - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts value into the treap_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Average complexity for insert element is at - //! most logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare or priority_compare ordering - //! function throws. Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::rtop() + reverse_iterator rtop(); + + //! @copydoc ::boost::intrusive::treap::rtop()const + const_reverse_iterator rtop() const; + + //! @copydoc ::boost::intrusive::treap::crtop()const + const_reverse_iterator crtop() const; + + //! @copydoc ::boost::intrusive::treap::crtop() const + priority_compare priority_comp() const; + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + + //! @copydoc ::boost::intrusive::treap::insert_equal(reference) iterator insert(reference value) - { return tree_.insert_equal(value); } + { return tree_type::insert_equal(value); } - //! <b>Requires</b>: value must be an lvalue - //! - //! <b>Effects</b>: Inserts x into the treap_multiset, using pos as a hint to - //! where it will be inserted. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Logarithmic in general, but it is amortized - //! constant time if t is inserted immediately before hint. - //! - //! <b>Throws</b>: If internal value_compare or priority_compare ordering functions throw. - //! Strong guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::insert_equal(const_iterator,reference) iterator insert(const_iterator hint, reference value) - { return tree_.insert_equal(hint, value); } + { return tree_type::insert_equal(hint, value); } - //! <b>Requires</b>: Dereferencing iterator must yield an lvalue - //! of type value_type. - //! - //! <b>Effects</b>: Inserts a range into the treap_multiset. - //! - //! <b>Returns</b>: An iterator that points to the position where the new - //! element was inserted. - //! - //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the - //! size of the range. However, it is linear in N if the range is already sorted - //! by value_comp(). - //! - //! <b>Throws</b>: If internal value_compare or priority_compare ordering functions throw. - //! Basic guarantee. - //! - //! <b>Note</b>: Does not affect the validity of iterators and references. - //! No copy-constructors are called. + //! @copydoc ::boost::intrusive::treap::insert_equal(Iterator,Iterator) template<class Iterator> void insert(Iterator b, Iterator e) - { tree_.insert_equal(b, e); } + { tree_type::insert_equal(b, e); } - //! <b>Requires</b>: value must be an lvalue, "pos" must be - //! a valid iterator (or end) and must be the succesor of value - //! once inserted according to the predicate - //! - //! <b>Effects</b>: Inserts x into the treap before "pos". - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if "pos" is not - //! the successor of "value" treap ordering invariant will be broken. - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - iterator insert_before(const_iterator pos, reference value) - { return tree_.insert_before(pos, value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no less - //! than the greatest inserted key. - //! - //! <b>Effects</b>: Inserts x into the treap in the last position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! less than the greatest inserted key treap ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_back(reference value) - { tree_.push_back(value); } - - //! <b>Requires</b>: value must be an lvalue, and it must be no greater - //! than the minimum inserted key - //! - //! <b>Effects</b>: Inserts x into the treap in the first position. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: This function does not check preconditions so if value is - //! greater than the minimum inserted key treap ordering invariant will be broken. - //! This function is slightly more efficient than using "insert_before". - //! This is a low-level function to be used only for performance reasons - //! by advanced users. - void push_front(reference value) - { tree_.push_front(value); } - - //! <b>Effects</b>: Erases the element pointed to by pos. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator i) - { return tree_.erase(i); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + //! @copydoc ::boost::intrusive::treap::insert_before + iterator insert_before(const_iterator pos, reference value); - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - iterator erase(const_iterator b, const_iterator e) - { return tree_.erase(b, e); } + //! @copydoc ::boost::intrusive::treap::push_back + void push_back(reference value); - //! <b>Effects</b>: Erases all the elements with the given value. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare or priority_compare ordering - //! functiona throw. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - size_type erase(const_reference value) - { return tree_.erase(value); } + //! @copydoc ::boost::intrusive::treap::push_front + void push_front(reference value); - //! <b>Effects</b>: Erases all the elements that compare equal with - //! the given key and the given comparison functor. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp or internal priority_compare ordering functions throw. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::erase(const_iterator) + iterator erase(const_iterator i); + + //! @copydoc ::boost::intrusive::treap::erase(const_iterator,const_iterator) + iterator erase(const_iterator b, const_iterator e); + + //! @copydoc ::boost::intrusive::treap::erase(const_reference) + size_type erase(const_reference value); + + //! @copydoc ::boost::intrusive::treap::erase(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - size_type erase(const KeyType& key, KeyValueCompare comp - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase(key, comp); } - - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased element. - //! - //! <b>Effects</b>: Erases the element pointed to by pos. - //! Disposer::operator()(pointer) is called for the removed element. - //! - //! <b>Complexity</b>: Average complexity for erase element is constant time. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Strong guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. - template<class Disposer> - iterator erase_and_dispose(const_iterator i, Disposer disposer) - { return tree_.erase_and_dispose(i, disposer); } + size_type erase(const KeyType& key, KeyValueCompare comp); - #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(iterator i, Disposer disposer) - { return this->erase_and_dispose(const_iterator(i), disposer); } - #endif + iterator erase_and_dispose(const_iterator i, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Returns</b>: An iterator to the element after the erased elements. - //! - //! <b>Effects</b>: Erases the range pointed to by b end e. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Complexity</b>: Average complexity for erase range is at most - //! O(log(size() + N)), where N is the number of elements in the range. - //! - //! <b>Throws</b>: If the internal priority_compare function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_iterator,const_iterator,Disposer) template<class Disposer> - iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { return tree_.erase_and_dispose(b, e, disposer); } + iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given value. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(value)). - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const_reference, Disposer) template<class Disposer> - size_type erase_and_dispose(const_reference value, Disposer disposer) - { return tree_.erase_and_dispose(value, disposer); } + size_type erase_and_dispose(const_reference value, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements with the given key. - //! according to the comparison functor "comp". - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Returns</b>: The number of erased elements. - //! - //! <b>Complexity</b>: O(log(size() + this->count(key, comp)). - //! - //! <b>Throws</b>: If comp or internal priority_compare ordering functions throw. Basic guarantee. - //! - //! <b>Note</b>: Invalidates the iterators - //! to the erased elements. + //! @copydoc ::boost::intrusive::treap::erase_and_dispose(const KeyType&,KeyValueCompare,Disposer) template<class KeyType, class KeyValueCompare, class Disposer> - size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer - /// @cond - , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0 - /// @endcond - ) - { return tree_.erase_and_dispose(key, comp, disposer); } - - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. - void clear() - { return tree_.clear(); } + size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer); - //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. - //! - //! <b>Effects</b>: Erases all the elements of the container. - //! - //! <b>Complexity</b>: Linear to the number of elements on the container. - //! Disposer::operator()(pointer) is called for the removed elements. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: Invalidates the iterators (but not the references) - //! to the erased elements. No destructors are called. + //! @copydoc ::boost::intrusive::treap::clear + void clear(); + + //! @copydoc ::boost::intrusive::treap::clear_and_dispose template<class Disposer> - void clear_and_dispose(Disposer disposer) - { return tree_.clear_and_dispose(disposer); } + void clear_and_dispose(Disposer disposer); - //! <b>Effects</b>: Returns the number of contained elements with the given key - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - size_type count(const_reference value) const - { return tree_.count(value); } + //! @copydoc ::boost::intrusive::treap::count(const_reference)const + size_type count(const_reference value) const; - //! <b>Effects</b>: Returns the number of contained elements with the same key - //! compared with the given comparison functor. - //! - //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal - //! to number of objects with the given key. - //! - //! <b>Throws</b>: If comp ordering function throws. + //! @copydoc ::boost::intrusive::treap::count(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - size_type count(const KeyType& key, KeyValueCompare comp) const - { return tree_.count(key, comp); } - - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator lower_bound(const_reference value) - { return tree_.lower_bound(value); } - - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + size_type count(const KeyType& key, KeyValueCompare comp) const; + + //! @copydoc ::boost::intrusive::treap::lower_bound(const_reference) + iterator lower_bound(const_reference value); + + //! @copydoc ::boost::intrusive::treap::lower_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator lower_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.lower_bound(key, comp); } + iterator lower_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns a const iterator to the first element whose - //! key is not less than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator lower_bound(const_reference value) const - { return tree_.lower_bound(value); } + //! @copydoc ::boost::intrusive::treap::lower_bound(const_reference)const + const_iterator lower_bound(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is not less than k or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::lower_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.lower_bound(key, comp); } + const_iterator lower_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator upper_bound(const_reference value) - { return tree_.upper_bound(value); } + //! @copydoc ::boost::intrusive::treap::upper_bound(const_reference) + iterator upper_bound(const_reference value); - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::upper_bound(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator upper_bound(const KeyType& key, KeyValueCompare comp) - { return tree_.upper_bound(key, comp); } + iterator upper_bound(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Returns an iterator to the first element whose - //! key is greater than k or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator upper_bound(const_reference value) const - { return tree_.upper_bound(value); } + //! @copydoc ::boost::intrusive::treap::upper_bound(const_reference)const + const_iterator upper_bound(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Returns a const_iterator to the first element whose - //! key according to the comparison functor is greater than key or - //! end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::upper_bound(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const - { return tree_.upper_bound(key, comp); } + const_iterator upper_bound(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds an iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - iterator find(const_reference value) - { return tree_.find(value); } + //! @copydoc ::boost::intrusive::treap::find(const_reference) + iterator find(const_reference value); - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds an iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::find(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - iterator find(const KeyType& key, KeyValueCompare comp) - { return tree_.find(key, comp); } + iterator find(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a const_iterator to the first element whose value is - //! "value" or end() if that element does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - const_iterator find(const_reference value) const - { return tree_.find(value); } + //! @copydoc ::boost::intrusive::treap::find(const_reference)const + const_iterator find(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a const_iterator to the first element whose key is - //! "key" according to the comparison functor or end() if that element - //! does not exist. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::find(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> - const_iterator find(const KeyType& key, KeyValueCompare comp) const - { return tree_.find(key, comp); } + const_iterator find(const KeyType& key, KeyValueCompare comp) const; - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. - std::pair<iterator,iterator> equal_range(const_reference value) - { return tree_.equal_range(value); } + //! @copydoc ::boost::intrusive::treap::equal_range(const_reference) + std::pair<iterator,iterator> equal_range(const_reference value); - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::equal_range(const KeyType&,KeyValueCompare) template<class KeyType, class KeyValueCompare> - std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp) - { return tree_.equal_range(key, comp); } + std::pair<iterator,iterator> equal_range(const KeyType& key, KeyValueCompare comp); - //! <b>Effects</b>: Finds a range containing all elements whose key is k or - //! an empty range that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the internal value_compare ordering function throws. + //! @copydoc ::boost::intrusive::treap::equal_range(const_reference)const std::pair<const_iterator, const_iterator> - equal_range(const_reference value) const - { return tree_.equal_range(value); } + equal_range(const_reference value) const; - //! <b>Requires</b>: comp must imply the same element order as - //! value_compare. Usually key is the part of the value_type - //! that is used in the ordering functor. - //! - //! <b>Effects</b>: Finds a range containing all elements whose key is k - //! according to the comparison functor or an empty range - //! that indicates the position where those elements would be - //! if they there is no elements with key k. - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If comp ordering function throws. - //! - //! <b>Note</b>: This function is used when constructing a value_type - //! is expensive and the value_type can be compared with a cheaper - //! key type. Usually this key is part of the value_type. + //! @copydoc ::boost::intrusive::treap::equal_range(const KeyType&,KeyValueCompare)const template<class KeyType, class KeyValueCompare> std::pair<const_iterator, const_iterator> - equal_range(const KeyType& key, KeyValueCompare comp) const - { return tree_.equal_range(key, comp); } + equal_range(const KeyType& key, KeyValueCompare comp) const; - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + //! @copydoc ::boost::intrusive::treap::bounded_range(const_reference,const_reference,bool,bool) std::pair<iterator,iterator> bounded_range - (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. + (const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed); + + //! @copydoc ::boost::intrusive::treap::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool) template<class KeyType, class KeyValueCompare> std::pair<iterator,iterator> bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed); - //! <b>Requires</b>: 'lower_value' must not be greater than 'upper_value'. If - //! 'lower_value' == 'upper_value', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise - //! - //! second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If the predicate throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_value and upper_value. + //! @copydoc ::boost::intrusive::treap::bounded_range(const_reference,const_reference,bool,bool)const std::pair<const_iterator, const_iterator> - bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_value, upper_value, left_closed, right_closed); } - - //! <b>Requires</b>: KeyValueCompare is a function object that induces a strict weak - //! ordering compatible with the strict weak ordering used to create the - //! the tree. - //! 'lower_key' must not be greater than 'upper_key' according to 'comp'. If - //! 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be false. - //! - //! <b>Effects</b>: Returns an a pair with the following criteria: - //! - //! first = lower_bound(lower_key, comp) if left_closed, upper_bound(lower_key, comp) otherwise - //! - //! second = upper_bound(upper_key, comp) if right_closed, lower_bound(upper_key, comp) otherwise - //! - //! <b>Complexity</b>: Logarithmic. - //! - //! <b>Throws</b>: If "comp" throws. - //! - //! <b>Note</b>: This function can be more efficient than calling upper_bound - //! and lower_bound for lower_key and upper_key. - template<class KeyType, class KeyValueCompare> - std::pair<const_iterator, const_iterator> - bounded_range - (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const - { return tree_.bounded_range(lower_key, upper_key, comp, left_closed, right_closed); } - - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static iterator s_iterator_to(reference value) - { return tree_type::s_iterator_to(value); } + bounded_range(const_reference lower_value, const_reference upper_value, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! treap_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This static function is available only if the <i>value traits</i> - //! is stateless. - static const_iterator s_iterator_to(const_reference value) - { return tree_type::s_iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::bounded_range(const KeyType&,const KeyType&,KeyValueCompare,bool,bool)const + template<class KeyType, class KeyValueCompare> + std::pair<const_iterator, const_iterator> bounded_range + (const KeyType& lower_key, const KeyType& upper_key, KeyValueCompare comp, bool left_closed, bool right_closed) const; - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset - //! that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - iterator iterator_to(reference value) - { return tree_.iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::s_iterator_to(reference) + static iterator s_iterator_to(reference value); - //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of - //! appropriate type. Otherwise the behavior is undefined. - //! - //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the - //! treap_multiset that points to the value - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - const_iterator iterator_to(const_reference value) const - { return tree_.iterator_to(value); } + //! @copydoc ::boost::intrusive::treap::s_iterator_to(const_reference) + static const_iterator s_iterator_to(const_reference value); - //! <b>Requires</b>: value shall not be in a treap_multiset/treap_multiset. - //! - //! <b>Effects</b>: init_node puts the hook of a value in a well-known default - //! state. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant time. - //! - //! <b>Note</b>: This function puts the hook in the well-known default state - //! used by auto_unlink and safe hooks. - static void init_node(reference value) - { tree_type::init_node(value); } + //! @copydoc ::boost::intrusive::treap::iterator_to(reference) + iterator iterator_to(reference value); - //! <b>Effects</b>: Unlinks the leftmost node from the tree. - //! - //! <b>Complexity</b>: Average complexity is constant time. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Notes</b>: This function breaks the tree and the tree can - //! only be used for more unlink_leftmost_without_rebalance calls. - //! This function is normally used to achieve a step by step - //! controlled destruction of the tree. - pointer unlink_leftmost_without_rebalance() - { return tree_.unlink_leftmost_without_rebalance(); } - - //! <b>Requires</b>: replace_this must be a valid iterator of *this - //! and with_this must not be inserted in any tree. - //! - //! <b>Effects</b>: Replaces replace_this in its position in the - //! tree with with_this. The tree does not need to be rebalanced. - //! - //! <b>Complexity</b>: Constant. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Note</b>: This function will break container ordering invariants if - //! with_this is not equivalent to *replace_this according to the - //! ordering rules. This function is faster than erasing and inserting - //! the node, since no rebalancing or comparison is needed. - void replace_node(iterator replace_this, reference with_this) - { tree_.replace_node(replace_this, with_this); } - - //! <b>Effects</b>: Rebalances the tree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear. - void rebalance() - { tree_.rebalance(); } + //! @copydoc ::boost::intrusive::treap::iterator_to(const_reference)const + const_iterator iterator_to(const_reference value) const; - //! <b>Requires</b>: old_root is a node of a tree. - //! - //! <b>Effects</b>: Rebalances the subtree rooted at old_root. - //! - //! <b>Returns</b>: The new root of the subtree. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - iterator rebalance_subtree(iterator root) - { return tree_.rebalance_subtree(root); } + //! @copydoc ::boost::intrusive::treap::init_node(reference) + static void init_node(reference value); - //! <b>Returns</b>: The balance factor (alpha) used in this tree - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Constant. - float balance_factor() const - { return tree_.balance_factor(); } + //! @copydoc ::boost::intrusive::treap::unlink_leftmost_without_rebalance + pointer unlink_leftmost_without_rebalance(); - //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0 - //! - //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances - //! the tree if the new balance factor is stricter (less) than the old factor. - //! - //! <b>Throws</b>: Nothing. - //! - //! <b>Complexity</b>: Linear to the elements in the subtree. - void balance_factor(float new_alpha) - { tree_.balance_factor(new_alpha); } + //! @copydoc ::boost::intrusive::treap::replace_node + void replace_node(iterator replace_this, reference with_this); - /// @cond - friend bool operator==(const treap_multiset_impl &x, const treap_multiset_impl &y) - { return x.tree_ == y.tree_; } + //! @copydoc ::boost::intrusive::treap::remove_node + void remove_node(reference value); - friend bool operator<(const treap_multiset_impl &x, const treap_multiset_impl &y) - { return x.tree_ < y.tree_; } - /// @endcond + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator!= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y) -#else -(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y) -#endif -{ return !(x == y); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator> -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y) -#else -(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y) -#endif -{ return y < x; } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator<= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y) -#else -(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y) -#endif -{ return !(y < x); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline bool operator>= -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y) -#else -(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y) -#endif -{ return !(x < y); } - -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -template<class T, class ...Options> -#else -template<class Config> -#endif -inline void swap -#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) -(treap_multiset_impl<T, Options...> &x, treap_multiset_impl<T, Options...> &y) -#else -(treap_multiset_impl<Config> &x, treap_multiset_impl<Config> &y) -#endif -{ x.swap(y); } //! Helper metafunction to define a \c treap_multiset that yields to the same type when the //! same options (either explicitly or implicitly) are used. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none> +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void> #endif struct make_treap_multiset { - /// @cond + typedef typename pack_options + < treap_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + typedef typename detail::get_header_holder_type + < value_traits, typename packed_options::header_holder_type >::type header_holder_type; + typedef treap_multiset_impl - < typename make_treap_opt<T, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 - #else - Options... - #endif - >::type - > implementation_defined; + < value_traits + , typename packed_options::compare + , typename packed_options::priority + , typename packed_options::size_type + , packed_options::constant_time_size + , header_holder_type + > implementation_defined; /// @endcond typedef implementation_defined type; }; @@ -2673,14 +931,14 @@ struct make_treap_multiset #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) -template<class T, class O1, class O2, class O3, class O4> +template<class T, class O1, class O2, class O3, class O4, class O5> #else template<class T, class ...Options> #endif class treap_multiset : public make_treap_multiset<T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif @@ -2689,12 +947,11 @@ class treap_multiset typedef typename make_treap_multiset <T, #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4 + O1, O2, O3, O4, O5 #else Options... #endif >::type Base; - //Movable BOOST_MOVABLE_BUT_NOT_COPYABLE(treap_multiset) public: @@ -2707,17 +964,17 @@ class treap_multiset //Assert if passed value traits are compatible with the type BOOST_STATIC_ASSERT((detail::is_same<typename value_traits::value_type, T>::value)); - treap_multiset( const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + explicit treap_multiset( const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : Base(cmp, pcmp, v_traits) {} template<class Iterator> treap_multiset( Iterator b, Iterator e - , const value_compare &cmp = value_compare() - , const priority_compare &pcmp = priority_compare() - , const value_traits &v_traits = value_traits()) + , const value_compare &cmp = value_compare() + , const priority_compare &pcmp = priority_compare() + , const value_traits &v_traits = value_traits()) : Base(b, e, cmp, pcmp, v_traits) {} @@ -2726,7 +983,7 @@ class treap_multiset {} treap_multiset& operator=(BOOST_RV_REF(treap_multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<treap_multiset &>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } static treap_multiset &container_from_end_iterator(iterator end_iterator) { return static_cast<treap_multiset &>(Base::container_from_end_iterator(end_iterator)); } @@ -2748,4 +1005,4 @@ class treap_multiset #include <boost/intrusive/detail/config_end.hpp> -#endif //BOOST_INTRUSIVE_TRIE_SET_HPP +#endif //BOOST_INTRUSIVE_TREAP_SET_HPP diff --git a/boost/intrusive/trivial_value_traits.hpp b/boost/intrusive/trivial_value_traits.hpp index 5c166fdaa1..18d28be92c 100644 --- a/boost/intrusive/trivial_value_traits.hpp +++ b/boost/intrusive/trivial_value_traits.hpp @@ -1,6 +1,6 @@ ///////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,6 +13,12 @@ #ifndef BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP #define BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP +#if defined(_MSC_VER) +# pragma once +#endif + +#include <boost/intrusive/detail/config_begin.hpp> +#include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/link_mode.hpp> #include <boost/intrusive/pointer_traits.hpp> @@ -22,7 +28,11 @@ namespace intrusive { //!This value traits template is used to create value traits //!from user defined node traits where value_traits::value_type and //!node_traits::node should be equal -template<class NodeTraits, link_mode_type LinkMode = normal_link> +template<class NodeTraits, link_mode_type LinkMode + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED + = safe_link + #endif +> struct trivial_value_traits { typedef NodeTraits node_traits; @@ -43,4 +53,6 @@ struct trivial_value_traits } //namespace intrusive } //namespace boost +#include <boost/intrusive/detail/config_end.hpp> + #endif //BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP diff --git a/boost/intrusive/unordered_set.hpp b/boost/intrusive/unordered_set.hpp index a06d74bf31..e47f3baaaf 100644 --- a/boost/intrusive/unordered_set.hpp +++ b/boost/intrusive/unordered_set.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2014 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -13,12 +13,15 @@ #ifndef BOOST_INTRUSIVE_UNORDERED_SET_HPP #define BOOST_INTRUSIVE_UNORDERED_SET_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> #include <boost/intrusive/hashtable.hpp> -#include <boost/move/move.hpp> -#include <iterator> - +#include <boost/move/utility_core.hpp> +#include <boost/static_assert.hpp> namespace boost { namespace intrusive { @@ -61,13 +64,14 @@ namespace intrusive { #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Hash, class Equal, class SizeType, class BucketTraits, std::size_t BoolFlags> #endif class unordered_set_impl + : public hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> { /// @cond private: - typedef hashtable_impl<Config> table_type; + typedef hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> table_type; //! This class is //! movable @@ -102,11 +106,6 @@ class unordered_set_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - /// @cond - private: - table_type table_; - /// @endcond - public: //! <b>Requires</b>: buckets must not be being used by any other resource. @@ -122,11 +121,11 @@ class unordered_set_impl //! //! <b>Notes</b>: buckets array must be disposed only after //! *this is disposed. - unordered_set_impl( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) - : table_(b_traits, hash_func, equal_func, v_traits) + explicit unordered_set_impl( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) + : table_type(b_traits, hash_func, equal_func, v_traits) {} //! <b>Requires</b>: buckets must not be being used by any other resource @@ -151,20 +150,21 @@ class unordered_set_impl , const hasher & hash_func = hasher() , const key_equal &equal_func = key_equal() , const value_traits &v_traits = value_traits()) - : table_(b_traits, hash_func, equal_func, v_traits) - { table_.insert_unique(b, e); } + : table_type(b_traits, hash_func, equal_func, v_traits) + { table_type::insert_unique(b, e); } //! <b>Effects</b>: to-do //! unordered_set_impl(BOOST_RV_REF(unordered_set_impl) x) - : table_(::boost::move(x.table_)) + : table_type(::boost::move(static_cast<table_type&>(x))) {} //! <b>Effects</b>: to-do //! unordered_set_impl& operator=(BOOST_RV_REF(unordered_set_impl) x) - { table_ = ::boost::move(x.table_); return *this; } + { return static_cast<unordered_set_impl&>(table_type::operator=(::boost::move(static_cast<table_type&>(x)))); } + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set //! are not deleted (i.e. no destructors are called). //! @@ -182,7 +182,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. iterator begin() - { return table_.begin(); } + { return table_type::begin(); } //! <b>Effects</b>: Returns a const_iterator pointing to the beginning //! of the unordered_set. @@ -192,7 +192,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. const_iterator begin() const - { return table_.begin(); } + { return table_type::begin(); } //! <b>Effects</b>: Returns a const_iterator pointing to the beginning //! of the unordered_set. @@ -202,7 +202,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. const_iterator cbegin() const - { return table_.cbegin(); } + { return table_type::cbegin(); } //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set. //! @@ -210,7 +210,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. iterator end() - { return table_.end(); } + { return table_type::end(); } //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set. //! @@ -218,7 +218,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. const_iterator end() const - { return table_.end(); } + { return table_type::end(); } //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set. //! @@ -226,7 +226,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. const_iterator cend() const - { return table_.cend(); } + { return table_type::cend(); } //! <b>Effects</b>: Returns the hasher object used by the unordered_set. //! @@ -234,7 +234,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If hasher copy-constructor throws. hasher hash_function() const - { return table_.hash_function(); } + { return table_type::hash_function(); } //! <b>Effects</b>: Returns the key_equal object used by the unordered_set. //! @@ -242,7 +242,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If key_equal copy-constructor throws. key_equal key_eq() const - { return table_.key_eq(); } + { return table_type::key_eq(); } //! <b>Effects</b>: Returns true if the container is empty. //! @@ -252,7 +252,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. bool empty() const - { return table_.empty(); } + { return table_type::empty(); } //! <b>Effects</b>: Returns the number of elements stored in the unordered_set. //! @@ -261,7 +261,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. size_type size() const - { return table_.size(); } + { return table_type::size(); } //! <b>Requires</b>: the hasher and the equality function unqualified swap //! call should not throw. @@ -274,7 +274,7 @@ class unordered_set_impl //! <b>Throws</b>: If the swap() call for the comparison or hash functors //! found using ADL throw. Basic guarantee. void swap(unordered_set_impl& other) - { table_.swap(other.table_); } + { table_type::swap(other.table_); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! Cloner should yield to nodes that compare equal and produce the same @@ -297,7 +297,9 @@ class unordered_set_impl //! throws. Basic guarantee. template <class Cloner, class Disposer> void clone_from(const unordered_set_impl &src, Cloner cloner, Disposer disposer) - { table_.clone_from(src.table_, cloner, disposer); } + { table_type::clone_from(src.table_, cloner, disposer); } + + #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Requires</b>: value must be an lvalue //! @@ -316,7 +318,7 @@ class unordered_set_impl //! <b>Note</b>: Does not affect the validity of iterators and references. //! No copy-constructors are called. std::pair<iterator, bool> insert(reference value) - { return table_.insert_unique(value); } + { return table_type::insert_unique(value); } //! <b>Requires</b>: Dereferencing iterator must yield an lvalue //! of type value_type. @@ -332,7 +334,7 @@ class unordered_set_impl //! No copy-constructors are called. template<class Iterator> void insert(Iterator b, Iterator e) - { table_.insert_unique(b, e); } + { table_type::insert_unique(b, e); } //! <b>Requires</b>: "hasher" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -372,7 +374,7 @@ class unordered_set_impl template<class KeyType, class KeyHasher, class KeyValueEqual> std::pair<iterator, bool> insert_check (const KeyType &key, KeyHasher hasher, KeyValueEqual key_value_equal, insert_commit_data &commit_data) - { return table_.insert_unique_check(key, hasher, key_value_equal, commit_data); } + { return table_type::insert_unique_check(key, hasher, key_value_equal, commit_data); } //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data //! must have been obtained from a previous call to "insert_check". @@ -394,7 +396,9 @@ class unordered_set_impl //! //! After a successful rehashing insert_commit_data remains valid. iterator insert_commit(reference value, const insert_commit_data &commit_data) - { return table_.insert_unique_commit(value, commit_data); } + { return table_type::insert_unique_commit(value, commit_data); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Effects</b>: Erases the element pointed to by i. //! @@ -405,7 +409,7 @@ class unordered_set_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased element. No destructors are called. void erase(const_iterator i) - { table_.erase(i); } + { table_type::erase(i); } //! <b>Effects</b>: Erases the range pointed to by b end e. //! @@ -417,7 +421,7 @@ class unordered_set_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. void erase(const_iterator b, const_iterator e) - { table_.erase(b, e); } + { table_type::erase(b, e); } //! <b>Effects</b>: Erases all the elements with the given value. //! @@ -431,7 +435,7 @@ class unordered_set_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. size_type erase(const_reference value) - { return table_.erase(value); } + { return table_type::erase(value); } //! <b>Requires</b>: "hasher" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -455,7 +459,7 @@ class unordered_set_impl //! to the erased elements. No destructors are called. template<class KeyType, class KeyHasher, class KeyValueEqual> size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.erase(key, hash_func, equal_func); } + { return table_type::erase(key, hash_func, equal_func); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -474,7 +478,7 @@ class unordered_set_impl , typename detail::enable_if_c<!detail::is_convertible<Disposer, const_iterator>::value >::type * = 0 /// @endcond ) - { table_.erase_and_dispose(i, disposer); } + { table_type::erase_and_dispose(i, disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -490,7 +494,7 @@ class unordered_set_impl //! to the erased elements. template<class Disposer> void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { table_.erase_and_dispose(b, e, disposer); } + { table_type::erase_and_dispose(b, e, disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -508,7 +512,7 @@ class unordered_set_impl //! to the erased elements. No destructors are called. template<class Disposer> size_type erase_and_dispose(const_reference value, Disposer disposer) - { return table_.erase_and_dispose(value, disposer); } + { return table_type::erase_and_dispose(value, disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -527,7 +531,7 @@ class unordered_set_impl //! to the erased elements. template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer> size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer) - { return table_.erase_and_dispose(key, hash_func, equal_func, disposer); } + { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); } //! <b>Effects</b>: Erases all of the elements. //! @@ -539,7 +543,7 @@ class unordered_set_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. void clear() - { return table_.clear(); } + { return table_type::clear(); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -554,7 +558,7 @@ class unordered_set_impl //! to the erased elements. No destructors are called. template<class Disposer> void clear_and_dispose(Disposer disposer) - { return table_.clear_and_dispose(disposer); } + { return table_type::clear_and_dispose(disposer); } //! <b>Effects</b>: Returns the number of contained elements with the given value //! @@ -562,7 +566,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. size_type count(const_reference value) const - { return table_.find(value) != end(); } + { return table_type::find(value) != end(); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -579,7 +583,7 @@ class unordered_set_impl //! <b>Throws</b>: If hash_func or equal_func throw. template<class KeyType, class KeyHasher, class KeyValueEqual> size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.find(key, hash_func, equal_func) != end(); } + { return table_type::find(key, hash_func, equal_func) != end(); } //! <b>Effects</b>: Finds an iterator to the first element is equal to //! "value" or end() if that element does not exist. @@ -588,7 +592,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. iterator find(const_reference value) - { return table_.find(value); } + { return table_type::find(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -611,7 +615,7 @@ class unordered_set_impl //! key type. Usually this key is part of the value_type. template<class KeyType, class KeyHasher, class KeyValueEqual> iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.find(key, hash_func, equal_func); } + { return table_type::find(key, hash_func, equal_func); } //! <b>Effects</b>: Finds a const_iterator to the first element whose key is //! "key" or end() if that element does not exist. @@ -620,7 +624,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. const_iterator find(const_reference value) const - { return table_.find(value); } + { return table_type::find(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -643,7 +647,7 @@ class unordered_set_impl //! key type. Usually this key is part of the value_type. template<class KeyType, class KeyHasher, class KeyValueEqual> const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.find(key, hash_func, equal_func); } + { return table_type::find(key, hash_func, equal_func); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent //! to value. Returns std::make_pair(this->end(), this->end()) if no such @@ -653,7 +657,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. std::pair<iterator,iterator> equal_range(const_reference value) - { return table_.equal_range(value); } + { return table_type::equal_range(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -677,7 +681,7 @@ class unordered_set_impl //! key type. Usually this key is part of the value_type. template<class KeyType, class KeyHasher, class KeyValueEqual> std::pair<iterator,iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.equal_range(key, hash_func, equal_func); } + { return table_type::equal_range(key, hash_func, equal_func); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent //! to value. Returns std::make_pair(this->end(), this->end()) if no such @@ -688,7 +692,7 @@ class unordered_set_impl //! <b>Throws</b>: If the internal hasher or the equality functor throws. std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return table_.equal_range(value); } + { return table_type::equal_range(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -713,7 +717,7 @@ class unordered_set_impl template<class KeyType, class KeyHasher, class KeyValueEqual> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.equal_range(key, hash_func, equal_func); } + { return table_type::equal_range(key, hash_func, equal_func); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -725,7 +729,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hash function throws. iterator iterator_to(reference value) - { return table_.iterator_to(value); } + { return table_type::iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -737,7 +741,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the internal hash function throws. const_iterator iterator_to(const_reference value) const - { return table_.iterator_to(value); } + { return table_type::iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -779,7 +783,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. local_iterator local_iterator_to(reference value) - { return table_.local_iterator_to(value); } + { return table_type::local_iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -791,7 +795,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. const_local_iterator local_iterator_to(const_reference value) const - { return table_.local_iterator_to(value); } + { return table_type::local_iterator_to(value); } //! <b>Effects</b>: Returns the number of buckets passed in the constructor //! or the last rehash function. @@ -800,7 +804,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. size_type bucket_count() const - { return table_.bucket_count(); } + { return table_type::bucket_count(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -810,7 +814,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. size_type bucket_size(size_type n) const - { return table_.bucket_size(n); } + { return table_type::bucket_size(n); } //! <b>Effects</b>: Returns the index of the bucket in which elements //! with keys equivalent to k would be found, if any such element existed. @@ -821,7 +825,7 @@ class unordered_set_impl //! //! <b>Note</b>: the return value is in the range [0, this->bucket_count()). size_type bucket(const value_type& k) const - { return table_.bucket(k); } + { return table_type::bucket(k); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -837,7 +841,7 @@ class unordered_set_impl //! <b>Note</b>: the return value is in the range [0, this->bucket_count()). template<class KeyType, class KeyHasher> size_type bucket(const KeyType& k, KeyHasher hash_func) const - { return table_.bucket(k, hash_func); } + { return table_type::bucket(k, hash_func); } //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor //! or the last rehash function. @@ -846,7 +850,7 @@ class unordered_set_impl //! //! <b>Throws</b>: Nothing. bucket_ptr bucket_pointer() const - { return table_.bucket_pointer(); } + { return table_type::bucket_pointer(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -860,7 +864,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator begin(size_type n) - { return table_.begin(n); } + { return table_type::begin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -874,7 +878,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator begin(size_type n) const - { return table_.begin(n); } + { return table_type::begin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -888,7 +892,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator cbegin(size_type n) const - { return table_.cbegin(n); } + { return table_type::cbegin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -902,7 +906,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator end(size_type n) - { return table_.end(n); } + { return table_type::end(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -916,7 +920,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator end(size_type n) const - { return table_.end(n); } + { return table_type::end(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -930,7 +934,7 @@ class unordered_set_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator cend(size_type n) const - { return table_.cend(n); } + { return table_type::cend(n); } //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array //! or the same as the old bucket array. new_size is the length of the @@ -946,7 +950,7 @@ class unordered_set_impl //! //! <b>Throws</b>: If the hasher functor throws. Basic guarantee. void rehash(const bucket_traits &new_bucket_traits) - { table_.rehash(new_bucket_traits); } + { table_type::rehash(new_bucket_traits); } //! <b>Requires</b>: //! @@ -958,11 +962,11 @@ class unordered_set_impl //! //! <b>Note</b>: this method is only available if incremental<true> option is activated. bool incremental_rehash(bool grow = true) - { return table_.incremental_rehash(grow); } + { return table_type::incremental_rehash(grow); } //! <b>Note</b>: this method is only available if incremental<true> option is activated. bool incremental_rehash(const bucket_traits &new_bucket_traits) - { return table_.incremental_rehash(new_bucket_traits); } + { return table_type::incremental_rehash(new_bucket_traits); } //! <b>Requires</b>: //! @@ -972,7 +976,7 @@ class unordered_set_impl //! //! <b>Throws</b>: size_type split_count() const - { return table_.split_count(); } + { return table_type::split_count(); } //! <b>Effects</b>: Returns the nearest new bucket count optimized for //! the container that is bigger than n. This suggestion can be used @@ -997,6 +1001,8 @@ class unordered_set_impl //! <b>Throws</b>: Nothing. static size_type suggested_lower_bucket_count(size_type n) { return table_type::suggested_lower_bucket_count(n); } + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; //! Helper metafunction to define an \c unordered_set that yields to the same type when the @@ -1004,26 +1010,45 @@ class unordered_set_impl #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - , class O5 = none, class O6 = none - , class O7 = none, class O8 = none - , class O9 = none, class O10= none +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void, class O6 = void + , class O7 = void, class O8 = void + , class O9 = void, class O10= void > #endif struct make_unordered_set { /// @cond + typedef typename pack_options + < hashtable_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + + typedef typename make_bucket_traits + <T, true, packed_options>::type bucket_traits; + typedef unordered_set_impl - < typename make_hashtable_opt - <T, true, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 - #else - Options... - #endif - >::type + < value_traits + , typename packed_options::hash + , typename packed_options::equal + , typename packed_options::size_type + , bucket_traits + , (std::size_t(true)*hash_bool_flags::unique_keys_pos) + | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos) + | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos) + | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos) + | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos) + | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos) > implementation_defined; + /// @endcond typedef implementation_defined type; }; @@ -1067,10 +1092,10 @@ class unordered_set typedef typename Base::hasher hasher; typedef typename Base::key_equal key_equal; - unordered_set ( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) + explicit unordered_set ( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) : Base(b_traits, hash_func, equal_func, v_traits) {} @@ -1089,7 +1114,7 @@ class unordered_set {} unordered_set& operator=(BOOST_RV_REF(unordered_set) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<unordered_set&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } }; #endif @@ -1133,13 +1158,14 @@ class unordered_set #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class T, class ...Options> #else -template<class Config> +template<class ValueTraits, class Hash, class Equal, class SizeType, class BucketTraits, std::size_t BoolFlags> #endif class unordered_multiset_impl + : public hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> { /// @cond private: - typedef hashtable_impl<Config> table_type; + typedef hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> table_type; /// @endcond //Movable @@ -1173,11 +1199,6 @@ class unordered_multiset_impl typedef typename implementation_defined::const_node_ptr const_node_ptr; typedef typename implementation_defined::node_algorithms node_algorithms; - /// @cond - private: - table_type table_; - /// @endcond - public: //! <b>Requires</b>: buckets must not be being used by any other resource. @@ -1193,11 +1214,11 @@ class unordered_multiset_impl //! //! <b>Notes</b>: buckets array must be disposed only after //! *this is disposed. - unordered_multiset_impl ( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) - : table_(b_traits, hash_func, equal_func, v_traits) + explicit unordered_multiset_impl ( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) + : table_type(b_traits, hash_func, equal_func, v_traits) {} //! <b>Requires</b>: buckets must not be being used by any other resource @@ -1222,19 +1243,21 @@ class unordered_multiset_impl , const hasher & hash_func = hasher() , const key_equal &equal_func = key_equal() , const value_traits &v_traits = value_traits()) - : table_(b_traits, hash_func, equal_func, v_traits) - { table_.insert_equal(b, e); } + : table_type(b_traits, hash_func, equal_func, v_traits) + { table_type::insert_equal(b, e); } //! <b>Effects</b>: to-do //! unordered_multiset_impl(BOOST_RV_REF(unordered_multiset_impl) x) - : table_(::boost::move(x.table_)) + : table_type(::boost::move(static_cast<table_type&>(x))) {} //! <b>Effects</b>: to-do //! unordered_multiset_impl& operator=(BOOST_RV_REF(unordered_multiset_impl) x) - { table_ = ::boost::move(x.table_); return *this; } + { return static_cast<unordered_multiset_impl&>(table_type::operator=(::boost::move(static_cast<table_type&>(x)))); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_multiset //! are not deleted (i.e. no destructors are called). @@ -1253,7 +1276,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. iterator begin() - { return table_.begin(); } + { return table_type::begin(); } //! <b>Effects</b>: Returns a const_iterator pointing to the beginning //! of the unordered_multiset. @@ -1263,7 +1286,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. const_iterator begin() const - { return table_.begin(); } + { return table_type::begin(); } //! <b>Effects</b>: Returns a const_iterator pointing to the beginning //! of the unordered_multiset. @@ -1273,7 +1296,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. const_iterator cbegin() const - { return table_.cbegin(); } + { return table_type::cbegin(); } //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_multiset. //! @@ -1281,7 +1304,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. iterator end() - { return table_.end(); } + { return table_type::end(); } //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_multiset. //! @@ -1289,7 +1312,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. const_iterator end() const - { return table_.end(); } + { return table_type::end(); } //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_multiset. //! @@ -1297,7 +1320,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. const_iterator cend() const - { return table_.cend(); } + { return table_type::cend(); } //! <b>Effects</b>: Returns the hasher object used by the unordered_set. //! @@ -1305,7 +1328,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If hasher copy-constructor throws. hasher hash_function() const - { return table_.hash_function(); } + { return table_type::hash_function(); } //! <b>Effects</b>: Returns the key_equal object used by the unordered_multiset. //! @@ -1313,7 +1336,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If key_equal copy-constructor throws. key_equal key_eq() const - { return table_.key_eq(); } + { return table_type::key_eq(); } //! <b>Effects</b>: Returns true if the container is empty. //! @@ -1323,7 +1346,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. bool empty() const - { return table_.empty(); } + { return table_type::empty(); } //! <b>Effects</b>: Returns the number of elements stored in the unordered_multiset. //! @@ -1332,7 +1355,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. size_type size() const - { return table_.size(); } + { return table_type::size(); } //! <b>Requires</b>: the hasher and the equality function unqualified swap //! call should not throw. @@ -1346,7 +1369,7 @@ class unordered_multiset_impl //! <b>Throws</b>: If the swap() call for the comparison or hash functors //! found using ADL throw. Basic guarantee. void swap(unordered_multiset_impl& other) - { table_.swap(other.table_); } + { table_type::swap(other.table_); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! Cloner should yield to nodes that compare equal and produce the same @@ -1369,7 +1392,9 @@ class unordered_multiset_impl //! throws. Basic guarantee. template <class Cloner, class Disposer> void clone_from(const unordered_multiset_impl &src, Cloner cloner, Disposer disposer) - { table_.clone_from(src.table_, cloner, disposer); } + { table_type::clone_from(src.table_, cloner, disposer); } + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Requires</b>: value must be an lvalue //! @@ -1384,7 +1409,7 @@ class unordered_multiset_impl //! <b>Note</b>: Does not affect the validity of iterators and references. //! No copy-constructors are called. iterator insert(reference value) - { return table_.insert_equal(value); } + { return table_type::insert_equal(value); } //! <b>Requires</b>: Dereferencing iterator must yield an lvalue //! of type value_type. @@ -1400,7 +1425,9 @@ class unordered_multiset_impl //! No copy-constructors are called. template<class Iterator> void insert(Iterator b, Iterator e) - { table_.insert_equal(b, e); } + { table_type::insert_equal(b, e); } + + #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED //! <b>Effects</b>: Erases the element pointed to by i. //! @@ -1411,7 +1438,7 @@ class unordered_multiset_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased element. No destructors are called. void erase(const_iterator i) - { table_.erase(i); } + { table_type::erase(i); } //! <b>Effects</b>: Erases the range pointed to by b end e. //! @@ -1423,7 +1450,7 @@ class unordered_multiset_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. void erase(const_iterator b, const_iterator e) - { table_.erase(b, e); } + { table_type::erase(b, e); } //! <b>Effects</b>: Erases all the elements with the given value. //! @@ -1437,7 +1464,7 @@ class unordered_multiset_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. size_type erase(const_reference value) - { return table_.erase(value); } + { return table_type::erase(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1462,7 +1489,7 @@ class unordered_multiset_impl //! to the erased elements. No destructors are called. template<class KeyType, class KeyHasher, class KeyValueEqual> size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.erase(key, hash_func, equal_func); } + { return table_type::erase(key, hash_func, equal_func); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1481,7 +1508,7 @@ class unordered_multiset_impl , typename detail::enable_if_c<!detail::is_convertible<Disposer, const_iterator>::value >::type * = 0 /// @endcond ) - { table_.erase_and_dispose(i, disposer); } + { table_type::erase_and_dispose(i, disposer); } #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template<class Disposer> @@ -1503,7 +1530,7 @@ class unordered_multiset_impl //! to the erased elements. template<class Disposer> void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer) - { table_.erase_and_dispose(b, e, disposer); } + { table_type::erase_and_dispose(b, e, disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1521,7 +1548,7 @@ class unordered_multiset_impl //! to the erased elements. No destructors are called. template<class Disposer> size_type erase_and_dispose(const_reference value, Disposer disposer) - { return table_.erase_and_dispose(value, disposer); } + { return table_type::erase_and_dispose(value, disposer); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1540,7 +1567,7 @@ class unordered_multiset_impl //! to the erased elements. template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer> size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer) - { return table_.erase_and_dispose(key, hash_func, equal_func, disposer); } + { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); } //! <b>Effects</b>: Erases all the elements of the container. //! @@ -1552,7 +1579,7 @@ class unordered_multiset_impl //! <b>Note</b>: Invalidates the iterators (but not the references) //! to the erased elements. No destructors are called. void clear() - { return table_.clear(); } + { return table_type::clear(); } //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw. //! @@ -1567,7 +1594,7 @@ class unordered_multiset_impl //! to the erased elements. No destructors are called. template<class Disposer> void clear_and_dispose(Disposer disposer) - { return table_.clear_and_dispose(disposer); } + { return table_type::clear_and_dispose(disposer); } //! <b>Effects</b>: Returns the number of contained elements with the given key //! @@ -1575,7 +1602,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. size_type count(const_reference value) const - { return table_.count(value); } + { return table_type::count(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1592,7 +1619,7 @@ class unordered_multiset_impl //! <b>Throws</b>: If the internal hasher or the equality functor throws. template<class KeyType, class KeyHasher, class KeyValueEqual> size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.count(key, hash_func, equal_func); } + { return table_type::count(key, hash_func, equal_func); } //! <b>Effects</b>: Finds an iterator to the first element whose value is //! "value" or end() if that element does not exist. @@ -1601,7 +1628,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. iterator find(const_reference value) - { return table_.find(value); } + { return table_type::find(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1624,7 +1651,7 @@ class unordered_multiset_impl //! key type. Usually this key is part of the value_type. template<class KeyType, class KeyHasher, class KeyValueEqual> iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.find(key, hash_func, equal_func); } + { return table_type::find(key, hash_func, equal_func); } //! <b>Effects</b>: Finds a const_iterator to the first element whose key is //! "key" or end() if that element does not exist. @@ -1633,7 +1660,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. const_iterator find(const_reference value) const - { return table_.find(value); } + { return table_type::find(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1656,7 +1683,7 @@ class unordered_multiset_impl //! key type. Usually this key is part of the value_type. template<class KeyType, class KeyHasher, class KeyValueEqual> const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.find(key, hash_func, equal_func); } + { return table_type::find(key, hash_func, equal_func); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent //! to value. Returns std::make_pair(this->end(), this->end()) if no such @@ -1666,7 +1693,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the internal hasher or the equality functor throws. std::pair<iterator,iterator> equal_range(const_reference value) - { return table_.equal_range(value); } + { return table_type::equal_range(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1691,7 +1718,7 @@ class unordered_multiset_impl template<class KeyType, class KeyHasher, class KeyValueEqual> std::pair<iterator,iterator> equal_range (const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) - { return table_.equal_range(key, hash_func, equal_func); } + { return table_type::equal_range(key, hash_func, equal_func); } //! <b>Effects</b>: Returns a range containing all elements with values equivalent //! to value. Returns std::make_pair(this->end(), this->end()) if no such @@ -1702,7 +1729,7 @@ class unordered_multiset_impl //! <b>Throws</b>: If the internal hasher or the equality functor throws. std::pair<const_iterator, const_iterator> equal_range(const_reference value) const - { return table_.equal_range(value); } + { return table_type::equal_range(value); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1727,7 +1754,7 @@ class unordered_multiset_impl template<class KeyType, class KeyHasher, class KeyValueEqual> std::pair<const_iterator, const_iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const - { return table_.equal_range(key, hash_func, equal_func); } + { return table_type::equal_range(key, hash_func, equal_func); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_multiset of //! appropriate type. Otherwise the behavior is undefined. @@ -1739,7 +1766,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the hash function throws. iterator iterator_to(reference value) - { return table_.iterator_to(value); } + { return table_type::iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_multiset of //! appropriate type. Otherwise the behavior is undefined. @@ -1751,7 +1778,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the hash function throws. const_iterator iterator_to(const_reference value) const - { return table_.iterator_to(value); } + { return table_type::iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -1793,7 +1820,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. local_iterator local_iterator_to(reference value) - { return table_.local_iterator_to(value); } + { return table_type::local_iterator_to(value); } //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of //! appropriate type. Otherwise the behavior is undefined. @@ -1805,7 +1832,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. const_local_iterator local_iterator_to(const_reference value) const - { return table_.local_iterator_to(value); } + { return table_type::local_iterator_to(value); } //! <b>Effects</b>: Returns the number of buckets passed in the constructor //! or the last rehash function. @@ -1814,7 +1841,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. size_type bucket_count() const - { return table_.bucket_count(); } + { return table_type::bucket_count(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1824,7 +1851,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. size_type bucket_size(size_type n) const - { return table_.bucket_size(n); } + { return table_type::bucket_size(n); } //! <b>Effects</b>: Returns the index of the bucket in which elements //! with keys equivalent to k would be found, if any such element existed. @@ -1835,7 +1862,7 @@ class unordered_multiset_impl //! //! <b>Note</b>: the return value is in the range [0, this->bucket_count()). size_type bucket(const value_type& k) const - { return table_.bucket(k); } + { return table_type::bucket(k); } //! <b>Requires</b>: "hash_func" must be a hash function that induces //! the same hash values as the stored hasher. The difference is that @@ -1851,7 +1878,7 @@ class unordered_multiset_impl //! <b>Note</b>: the return value is in the range [0, this->bucket_count()). template<class KeyType, class KeyHasher> size_type bucket(const KeyType& k, const KeyHasher &hash_func) const - { return table_.bucket(k, hash_func); } + { return table_type::bucket(k, hash_func); } //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor //! or the last rehash function. @@ -1860,7 +1887,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: Nothing. bucket_ptr bucket_pointer() const - { return table_.bucket_pointer(); } + { return table_type::bucket_pointer(); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1874,7 +1901,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator begin(size_type n) - { return table_.begin(n); } + { return table_type::begin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1888,7 +1915,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator begin(size_type n) const - { return table_.begin(n); } + { return table_type::begin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1902,7 +1929,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator cbegin(size_type n) const - { return table_.cbegin(n); } + { return table_type::cbegin(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1916,7 +1943,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. local_iterator end(size_type n) - { return table_.end(n); } + { return table_type::end(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1930,7 +1957,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator end(size_type n) const - { return table_.end(n); } + { return table_type::end(n); } //! <b>Requires</b>: n is in the range [0, this->bucket_count()). //! @@ -1944,7 +1971,7 @@ class unordered_multiset_impl //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range //! containing all of the elements in the nth bucket. const_local_iterator cend(size_type n) const - { return table_.cend(n); } + { return table_type::cend(n); } //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array //! or the same as the old bucket array. new_size is the length of the @@ -1960,7 +1987,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: If the hasher functor throws. void rehash(const bucket_traits &new_bucket_traits) - { table_.rehash(new_bucket_traits); } + { table_type::rehash(new_bucket_traits); } //! <b>Requires</b>: //! @@ -1972,11 +1999,11 @@ class unordered_multiset_impl //! //! <b>Note</b>: this method is only available if incremental<true> option is activated. bool incremental_rehash(bool grow = true) - { return table_.incremental_rehash(grow); } + { return table_type::incremental_rehash(grow); } //! <b>Note</b>: this method is only available if incremental<true> option is activated. bool incremental_rehash(const bucket_traits &new_bucket_traits) - { return table_.incremental_rehash(new_bucket_traits); } + { return table_type::incremental_rehash(new_bucket_traits); } //! <b>Requires</b>: //! @@ -1986,7 +2013,7 @@ class unordered_multiset_impl //! //! <b>Throws</b>: size_type split_count() const - { return table_.split_count(); } + { return table_type::split_count(); } //! <b>Effects</b>: Returns the nearest new bucket count optimized for //! the container that is bigger than n. This suggestion can be used @@ -2011,6 +2038,8 @@ class unordered_multiset_impl //! <b>Throws</b>: Nothing. static size_type suggested_lower_bucket_count(size_type n) { return table_type::suggested_lower_bucket_count(n); } + + #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED }; //! Helper metafunction to define an \c unordered_multiset that yields to the same type when the @@ -2018,26 +2047,45 @@ class unordered_multiset_impl #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class T, class ...Options> #else -template<class T, class O1 = none, class O2 = none - , class O3 = none, class O4 = none - , class O5 = none, class O6 = none - , class O7 = none, class O8 = none - , class O9 = none, class O10= none +template<class T, class O1 = void, class O2 = void + , class O3 = void, class O4 = void + , class O5 = void, class O6 = void + , class O7 = void, class O8 = void + , class O9 = void, class O10= void > #endif struct make_unordered_multiset { /// @cond + typedef typename pack_options + < hashtable_defaults, + #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) + O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 + #else + Options... + #endif + >::type packed_options; + + typedef typename detail::get_value_traits + <T, typename packed_options::proto_value_traits>::type value_traits; + + typedef typename make_bucket_traits + <T, true, packed_options>::type bucket_traits; + typedef unordered_multiset_impl - < typename make_hashtable_opt - <T, false, - #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) - O1, O2, O3, O4, O5, O6, O7, O8, O9, O10 - #else - Options... - #endif - >::type + < value_traits + , typename packed_options::hash + , typename packed_options::equal + , typename packed_options::size_type + , bucket_traits + , (std::size_t(false)*hash_bool_flags::unique_keys_pos) + | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos) + | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos) + | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos) + | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos) + | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos) > implementation_defined; + /// @endcond typedef implementation_defined type; }; @@ -2080,10 +2128,10 @@ class unordered_multiset typedef typename Base::hasher hasher; typedef typename Base::key_equal key_equal; - unordered_multiset( const bucket_traits &b_traits - , const hasher & hash_func = hasher() - , const key_equal &equal_func = key_equal() - , const value_traits &v_traits = value_traits()) + explicit unordered_multiset( const bucket_traits &b_traits + , const hasher & hash_func = hasher() + , const key_equal &equal_func = key_equal() + , const value_traits &v_traits = value_traits()) : Base(b_traits, hash_func, equal_func, v_traits) {} @@ -2102,7 +2150,7 @@ class unordered_multiset {} unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x) - { this->Base::operator=(::boost::move(static_cast<Base&>(x))); return *this; } + { return static_cast<unordered_multiset&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); } }; #endif diff --git a/boost/intrusive/unordered_set_hook.hpp b/boost/intrusive/unordered_set_hook.hpp index c7e95b222c..7406c9428d 100644 --- a/boost/intrusive/unordered_set_hook.hpp +++ b/boost/intrusive/unordered_set_hook.hpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Olaf Krzikalla 2004-2006. -// (C) Copyright Ion Gaztanaga 2006-2012 +// (C) Copyright Ion Gaztanaga 2006-2013 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -14,14 +14,16 @@ #ifndef BOOST_INTRUSIVE_UNORDERED_SET_HOOK_HPP #define BOOST_INTRUSIVE_UNORDERED_SET_HOOK_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/intrusive/detail/config_begin.hpp> #include <boost/intrusive/intrusive_fwd.hpp> -#include <boost/pointer_cast.hpp> -#include <boost/intrusive/detail/utilities.hpp> + #include <boost/intrusive/pointer_traits.hpp> #include <boost/intrusive/slist_hook.hpp> #include <boost/intrusive/options.hpp> -#include <boost/intrusive/pointer_traits.hpp> #include <boost/intrusive/detail/generic_hook.hpp> namespace boost { @@ -81,9 +83,7 @@ struct unordered_node_traits static const bool optimize_multikey = OptimizeMultiKey; static node_ptr get_next(const const_node_ptr & n) - { - return pointer_traits<node_ptr>::pointer_to(static_cast<node&>(*n->next_)); - } + { return pointer_traits<node_ptr>::static_cast_from(n->next_); } static void set_next(const node_ptr & n, const node_ptr & next) { n->next_ = next; } @@ -120,8 +120,12 @@ struct unordered_algorithms : public circular_slist_algorithms<NodeTraits> { typedef circular_slist_algorithms<NodeTraits> base_type; - typedef unordered_group_adapter<NodeTraits> group_traits; + typedef unordered_group_adapter<NodeTraits> group_traits; typedef circular_slist_algorithms<group_traits> group_algorithms; + typedef NodeTraits node_traits; + typedef typename NodeTraits::node node; + typedef typename NodeTraits::node_ptr node_ptr; + typedef typename NodeTraits::const_node_ptr const_node_ptr; static void init(typename base_type::node_ptr n) { @@ -142,6 +146,11 @@ struct unordered_algorithms } }; +//Class to avoid defining the same algo as a circular list, as hooks would be ambiguous between them +template<class Algo> +struct uset_algo_wrapper : public Algo +{}; + template<class VoidPointer, bool StoreHash, bool OptimizeMultiKey> struct get_uset_node_algo { @@ -151,9 +160,9 @@ struct get_uset_node_algo , slist_node_traits<VoidPointer> >::type node_traits_type; typedef typename detail::if_c - < OptimizeMultiKey - , unordered_algorithms<node_traits_type> - , circular_slist_algorithms<node_traits_type> + < OptimizeMultiKey + , unordered_algorithms<node_traits_type> + , uset_algo_wrapper< circular_slist_algorithms<node_traits_type> > >::type type; }; /// @endcond @@ -163,7 +172,7 @@ struct get_uset_node_algo #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_unordered_set_base_hook { @@ -177,14 +186,14 @@ struct make_unordered_set_base_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_uset_node_algo<typename packed_options::void_pointer - , packed_options::store_hash - , packed_options::optimize_multikey - > + typedef generic_hook + < typename get_uset_node_algo < typename packed_options::void_pointer + , packed_options::store_hash + , packed_options::optimize_multikey + >::type , typename packed_options::tag , packed_options::link_mode - , detail::UsetBaseHook + , HashBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -203,7 +212,7 @@ struct make_unordered_set_base_hook //! unique tag. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). @@ -302,7 +311,7 @@ class unordered_set_base_hook #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES) template<class ...Options> #else -template<class O1 = none, class O2 = none, class O3 = none, class O4 = none> +template<class O1 = void, class O2 = void, class O3 = void, class O4 = void> #endif struct make_unordered_set_member_hook { @@ -316,14 +325,14 @@ struct make_unordered_set_member_hook #endif >::type packed_options; - typedef detail::generic_hook - < get_uset_node_algo< typename packed_options::void_pointer - , packed_options::store_hash - , packed_options::optimize_multikey - > + typedef generic_hook + < typename get_uset_node_algo< typename packed_options::void_pointer + , packed_options::store_hash + , packed_options::optimize_multikey + >::type , member_tag , packed_options::link_mode - , detail::NoBaseHook + , NoBaseHookId > implementation_defined; /// @endcond typedef implementation_defined type; @@ -337,7 +346,7 @@ struct make_unordered_set_member_hook //! \c link_mode<> and \c store_hash<>. //! //! \c void_pointer<> is the pointer type that will be used internally in the hook -//! and the the container configured to use this hook. +//! and the container configured to use this hook. //! //! \c link_mode<> will specify the linking mode of the hook (\c normal_link, //! \c auto_unlink or \c safe_link). |