summaryrefslogtreecommitdiff
path: root/boost/intrusive
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-12-11 09:55:56 (GMT)
committerChanho Park <chanho61.park@samsung.com>2014-12-11 09:55:56 (GMT)
commit08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/intrusive
parentbb4dd8289b351fae6b55e303f189127a394a1edd (diff)
downloadboost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/intrusive')
-rw-r--r--boost/intrusive/any_hook.hpp102
-rw-r--r--boost/intrusive/avl_set.hpp2728
-rw-r--r--boost/intrusive/avl_set_hook.hpp38
-rw-r--r--boost/intrusive/avltree.hpp1917
-rw-r--r--boost/intrusive/avltree_algorithms.hpp925
-rw-r--r--boost/intrusive/bs_set.hpp948
-rw-r--r--boost/intrusive/bs_set_hook.hpp44
-rw-r--r--boost/intrusive/bstree.hpp2177
-rw-r--r--boost/intrusive/bstree_algorithms.hpp (renamed from boost/intrusive/detail/tree_algorithms.hpp)1576
-rw-r--r--boost/intrusive/circular_list_algorithms.hpp120
-rw-r--r--boost/intrusive/circular_slist_algorithms.hpp68
-rw-r--r--boost/intrusive/derivation_value_traits.hpp37
-rw-r--r--boost/intrusive/detail/algo_type.hpp46
-rw-r--r--boost/intrusive/detail/any_node_and_algorithms.hpp79
-rw-r--r--boost/intrusive/detail/array_initializer.hpp90
-rw-r--r--boost/intrusive/detail/assert.hpp4
-rw-r--r--boost/intrusive/detail/avltree_node.hpp61
-rw-r--r--boost/intrusive/detail/clear_on_destructor_base.hpp36
-rw-r--r--boost/intrusive/detail/common_slist_algorithms.hpp109
-rw-r--r--boost/intrusive/detail/config_begin.hpp5
-rw-r--r--boost/intrusive/detail/config_end.hpp2
-rw-r--r--boost/intrusive/detail/default_header_holder.hpp65
-rw-r--r--boost/intrusive/detail/ebo_functor_holder.hpp141
-rw-r--r--boost/intrusive/detail/empty_node_checker.hpp40
-rw-r--r--boost/intrusive/detail/equal_to_value.hpp44
-rw-r--r--boost/intrusive/detail/exception_disposer.hpp84
-rw-r--r--boost/intrusive/detail/function_detector.hpp8
-rw-r--r--boost/intrusive/detail/generic_hook.hpp198
-rw-r--r--boost/intrusive/detail/get_value_traits.hpp218
-rw-r--r--boost/intrusive/detail/has_member_function_callable_with.hpp264
-rw-r--r--boost/intrusive/detail/hashtable_node.hpp200
-rw-r--r--boost/intrusive/detail/hook_traits.hpp182
-rw-r--r--boost/intrusive/detail/iiterator.hpp227
-rw-r--r--boost/intrusive/detail/is_stateful_value_traits.hpp8
-rw-r--r--boost/intrusive/detail/key_nodeptr_comp.hpp72
-rw-r--r--boost/intrusive/detail/list_iterator.hpp129
-rw-r--r--boost/intrusive/detail/list_node.hpp159
-rw-r--r--boost/intrusive/detail/math.hpp271
-rw-r--r--boost/intrusive/detail/memory_util.hpp214
-rw-r--r--boost/intrusive/detail/mpl.hpp355
-rw-r--r--boost/intrusive/detail/node_cloner_disposer.hpp109
-rw-r--r--boost/intrusive/detail/node_holder.hpp31
-rw-r--r--boost/intrusive/detail/node_to_value.hpp126
-rw-r--r--boost/intrusive/detail/parent_from_member.hpp45
-rw-r--r--boost/intrusive/detail/pointer_element.hpp170
-rw-r--r--boost/intrusive/detail/preprocessor.hpp16
-rw-r--r--boost/intrusive/detail/rbtree_node.hpp71
-rw-r--r--boost/intrusive/detail/reverse_iterator.hpp139
-rw-r--r--boost/intrusive/detail/simple_disposers.hpp46
-rw-r--r--boost/intrusive/detail/size_holder.hpp80
-rw-r--r--boost/intrusive/detail/slist_iterator.hpp120
-rw-r--r--boost/intrusive/detail/slist_node.hpp132
-rw-r--r--boost/intrusive/detail/std_fwd.hpp54
-rw-r--r--boost/intrusive/detail/to_raw_pointer.hpp42
-rw-r--r--boost/intrusive/detail/transform_iterator.hpp13
-rw-r--r--boost/intrusive/detail/tree_iterator.hpp141
-rw-r--r--boost/intrusive/detail/tree_node.hpp157
-rw-r--r--boost/intrusive/detail/uncast.hpp51
-rw-r--r--boost/intrusive/detail/utilities.hpp879
-rw-r--r--boost/intrusive/detail/workaround.hpp16
-rw-r--r--boost/intrusive/hashtable.hpp2266
-rw-r--r--boost/intrusive/intrusive_fwd.hpp647
-rw-r--r--boost/intrusive/linear_slist_algorithms.hpp17
-rw-r--r--boost/intrusive/link_mode.hpp25
-rw-r--r--boost/intrusive/list.hpp391
-rw-r--r--boost/intrusive/list_hook.hpp36
-rw-r--r--boost/intrusive/member_value_traits.hpp28
-rw-r--r--boost/intrusive/options.hpp738
-rw-r--r--boost/intrusive/pack_options.hpp374
-rw-r--r--boost/intrusive/parent_from_member.hpp14
-rw-r--r--boost/intrusive/pointer_plus_bits.hpp16
-rw-r--r--boost/intrusive/pointer_rebind.hpp188
-rw-r--r--boost/intrusive/pointer_traits.hpp74
-rw-r--r--boost/intrusive/priority_compare.hpp27
-rw-r--r--boost/intrusive/rbtree.hpp1886
-rw-r--r--boost/intrusive/rbtree_algorithms.hpp922
-rw-r--r--boost/intrusive/set.hpp2684
-rw-r--r--boost/intrusive/set_hook.hpp38
-rw-r--r--boost/intrusive/sg_set.hpp2787
-rw-r--r--boost/intrusive/sgtree.hpp1847
-rw-r--r--boost/intrusive/sgtree_algorithms.hpp759
-rw-r--r--boost/intrusive/slist.hpp766
-rw-r--r--boost/intrusive/slist_hook.hpp37
-rw-r--r--boost/intrusive/splay_set.hpp2810
-rw-r--r--boost/intrusive/splay_set_hook.hpp292
-rw-r--r--boost/intrusive/splaytree.hpp1845
-rw-r--r--boost/intrusive/splaytree_algorithms.hpp1127
-rw-r--r--boost/intrusive/treap.hpp1395
-rw-r--r--boost/intrusive/treap_algorithms.hpp565
-rw-r--r--boost/intrusive/treap_set.hpp2671
-rw-r--r--boost/intrusive/trivial_value_traits.hpp16
-rw-r--r--boost/intrusive/unordered_set.hpp408
-rw-r--r--boost/intrusive/unordered_set_hook.hpp63
93 files changed, 17241 insertions, 26947 deletions
diff --git a/boost/intrusive/any_hook.hpp b/boost/intrusive/any_hook.hpp
index 7d60de0..1b53837 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 91e2dbb..58d6108 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 825921f..6fdc51b 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 84376a8..d2adf24 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 11463c7..e5bcfde 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 0000000..b87a543
--- /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 682426a..cb5af30 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 0000000..44b02bb
--- /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 c92d39b..de5445e 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 282f474..1e888a1 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 c39b3d0..3dd561d 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 0aae01b..87bc489 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 0000000..e40cb43
--- /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 b274135..5a0e8c2 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 0000000..b2072a8
--- /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 33de97f..d75d225 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 aec0dab..522806a 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 1b5c27f..0000000
--- 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 942b35a..4c7f1a1 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 7d15336..36d605d 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 d653030..a081443 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 0000000..c471691
--- /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 850d074..d2e8107 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 0000000..33d78a3
--- /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 0000000..3ffd1c2
--- /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 0000000..1226f5e
--- /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 08cee2d..f72865d 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 5ddd520..c5af081 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 0000000..6f5a9e3
--- /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 6516e28..ca96f15 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 86e6074..6449fa0 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 0000000..c9c115b
--- /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 0000000..8378ead
--- /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 8677c66..da2260e 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 0000000..dfee8b9
--- /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 0000000..efddfba
--- /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
+