Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51297 - in sandbox/boost/intrusive: . detail
From: igaztanaga_at_[hidden]
Date: 2009-02-17 13:15:49


Author: igaztanaga
Date: 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
New Revision: 51297
URL: http://svn.boost.org/trac/boost/changeset/51297

Log:
Added move_semantics library
Added:
   sandbox/boost/intrusive/detail/list_node.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/mpl.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/parent_from_member.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/pointer_to_other.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/rbtree_node.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/slist_node.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/transform_iterator.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/tree_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/tree_node.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/utilities.hpp (contents, props changed)
   sandbox/boost/intrusive/detail/workaround.hpp (contents, props changed)
   sandbox/boost/intrusive/hashtable.hpp (contents, props changed)
   sandbox/boost/intrusive/intrusive_fwd.hpp (contents, props changed)
   sandbox/boost/intrusive/linear_slist_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/link_mode.hpp (contents, props changed)
   sandbox/boost/intrusive/list.hpp (contents, props changed)
   sandbox/boost/intrusive/list_hook.hpp (contents, props changed)
   sandbox/boost/intrusive/member_value_traits.hpp (contents, props changed)
   sandbox/boost/intrusive/options.hpp (contents, props changed)
   sandbox/boost/intrusive/pointer_plus_bits.hpp (contents, props changed)
   sandbox/boost/intrusive/priority_compare.hpp (contents, props changed)
   sandbox/boost/intrusive/rbtree.hpp (contents, props changed)
   sandbox/boost/intrusive/rbtree_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/set.hpp (contents, props changed)
   sandbox/boost/intrusive/set_hook.hpp (contents, props changed)
   sandbox/boost/intrusive/sg_set.hpp (contents, props changed)
   sandbox/boost/intrusive/sgtree.hpp (contents, props changed)
   sandbox/boost/intrusive/sgtree_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/slist.hpp (contents, props changed)
   sandbox/boost/intrusive/slist_hook.hpp (contents, props changed)
   sandbox/boost/intrusive/splay_set.hpp (contents, props changed)
   sandbox/boost/intrusive/splay_set_hook.hpp (contents, props changed)
   sandbox/boost/intrusive/splaytree.hpp (contents, props changed)
   sandbox/boost/intrusive/splaytree_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/treap.hpp (contents, props changed)
   sandbox/boost/intrusive/treap_algorithms.hpp (contents, props changed)
   sandbox/boost/intrusive/treap_set.hpp (contents, props changed)
   sandbox/boost/intrusive/trivial_value_traits.hpp (contents, props changed)
   sandbox/boost/intrusive/unordered_set.hpp (contents, props changed)
   sandbox/boost/intrusive/unordered_set_hook.hpp (contents, props changed)

Added: sandbox/boost/intrusive/detail/list_node.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/list_node.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,188 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_NODE_HPP
+#define BOOST_INTRUSIVE_LIST_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+
+namespace boost {
+namespace intrusive {
+
+// list_node_traits can be used with circular_list_algorithms and supplies
+// a list_node holding the pointers needed for a double-linked list
+// it is used by list_derived_node and list_member_node
+
+template<class VoidPointer>
+struct list_node
+{
+ typedef typename boost::pointer_to_other
+ <VoidPointer, list_node>::type node_ptr;
+ node_ptr next_;
+ node_ptr prev_;
+};
+
+template<class VoidPointer>
+struct list_node_traits
+{
+ typedef list_node<VoidPointer> node;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ static node_ptr get_previous(const_node_ptr n)
+ { return n->prev_; }
+
+ static void set_previous(node_ptr n, node_ptr prev)
+ { n->prev_ = prev; }
+
+ static node_ptr get_next(const_node_ptr n)
+ { return n->next_; }
+
+ static void set_next(node_ptr n, node_ptr next)
+ { n->next_ = next; }
+};
+
+// list_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class list_iterator
+ : public std::iterator
+ < std::bidirectional_iterator_tag
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>
+ ::type value_type;
+ typedef value_type & reference;
+ typedef value_type * pointer;
+
+ list_iterator()
+ : members_ (node_ptr(0), 0)
+ {}
+
+ explicit list_iterator(node_ptr node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ list_iterator(list_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ list_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<list_iterator&>(*this); }
+
+ public:
+ list_iterator& operator++()
+ {
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return static_cast<list_iterator&> (*this);
+ }
+
+ list_iterator operator++(int)
+ {
+ list_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return result;
+ }
+
+ list_iterator& operator--()
+ {
+ members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
+ return static_cast<list_iterator&> (*this);
+ }
+
+ list_iterator operator--(int)
+ {
+ list_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_previous(members_.nodeptr_);
+ return result;
+ }
+
+ bool operator== (const list_iterator& i) const
+ { return members_.nodeptr_ == i.pointed_node(); }
+
+ bool operator!= (const list_iterator& i) const
+ { return !operator== (i); }
+
+ value_type& operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(members_.nodeptr_)); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr){
+ const Container* c = static_cast<const Container*>(members_.get_ptr());
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(c != 0);
+ return c;
+ }
+ else{
+ return 0;
+ }
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ list_iterator<Container, false> unconst() const
+ { return list_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_LIST_NODE_HPP

Added: sandbox/boost/intrusive/detail/mpl.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/mpl.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,367 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_MPL_HPP
+#define BOOST_INTRUSIVE_DETAIL_MPL_HPP
+
+#include <cstddef>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+typedef char one;
+struct two {one _[2];};
+
+template< bool C_ >
+struct bool_
+{
+ static const bool value = C_;
+};
+
+typedef bool_<true> true_;
+typedef bool_<false> false_;
+
+typedef true_ true_type;
+typedef false_ false_type;
+
+typedef char yes_type;
+struct no_type
+{
+ char padding[8];
+};
+
+template <bool B, class T = void>
+struct enable_if_c {
+ typedef T type;
+};
+
+template <class T>
+struct enable_if_c<false, T> {};
+
+template <class Cond, class T = void>
+struct enable_if : public enable_if_c<Cond::value, T>{};
+
+template<class F, class Param>
+struct apply
+{
+ typedef typename F::template apply<Param>::type type;
+};
+
+template <class T, class U>
+class is_convertible
+{
+ typedef char true_t;
+ class false_t { char dummy[2]; };
+ static true_t dispatch(U);
+ static false_t dispatch(...);
+ static const T &trigger();
+ public:
+ static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t);
+};
+
+template<
+ bool C
+ , typename T1
+ , typename T2
+ >
+struct if_c
+{
+ typedef T1 type;
+};
+
+template<
+ typename T1
+ , typename T2
+ >
+struct if_c<false,T1,T2>
+{
+ typedef T2 type;
+};
+
+template<
+ typename C
+ , typename T1
+ , typename T2
+ >
+struct if_
+{
+ typedef typename if_c<0 != C::value, T1, T2>::type type;
+};
+
+template<
+ bool C
+ , typename F1
+ , typename F2
+ >
+struct eval_if_c
+ : if_c<C,F1,F2>::type
+{};
+
+template<
+ typename C
+ , typename T1
+ , typename T2
+ >
+struct eval_if
+ : if_<C,T1,T2>::type
+{};
+
+// identity is an extension: it is not part of the standard.
+template <class T>
+struct identity
+{
+ typedef T type;
+};
+
+#if defined(BOOST_MSVC) || defined(__BORLANDC_)
+#define BOOST_INTRUSIVE_TT_DECL __cdecl
+#else
+#define BOOST_INTRUSIVE_TT_DECL
+#endif
+
+#if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64)
+#define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+#endif
+
+template <typename T>
+struct is_unary_or_binary_function_impl
+{ static const bool value = false; };
+
+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; };
+/*
+#ifdef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__stdcall*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(...)>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(...)>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__fastcall*)()>
+{ static const bool value = true; };
+
+template <typename R>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(...)>
+{ static const bool value = true; };
+
+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
+*/
+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; };
+
+#ifdef 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; };
+/*
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(T0...)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)>
+{ static const bool value = true; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(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; };
+
+template <typename R, class T0>
+struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)>
+{ static const bool value = true; };
+*/
+#endif
+
+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; };
+/*
+#ifdef 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; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1...)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)>
+{ static const bool value = true; };
+
+template <typename R, class T0, class T1>
+struct is_unary_or_binary_function_impl<R (__fastcall*)(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; };
+
+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
+{ static const bool value = is_unary_or_binary_function_impl<T>::value; };
+
+//boost::alignment_of yields to 10K lines of preprocessed code, so we
+//need an alternative
+template <typename T> struct alignment_of;
+
+template <typename T>
+struct alignment_of_hack
+{
+ char c;
+ T t;
+ alignment_of_hack();
+};
+
+template <unsigned A, unsigned S>
+struct alignment_logic
+{
+ static const std::size_t value = A < S ? A : S;
+};
+
+template< typename T >
+struct alignment_of
+{
+ static const std::size_t value = alignment_logic
+ < sizeof(alignment_of_hack<T>) - sizeof(T)
+ , sizeof(T)
+ >::value;
+};
+
+template <typename T, typename U>
+struct is_same
+{
+ typedef char yes_type;
+ struct no_type
+ {
+ char padding[8];
+ };
+
+ template <typename V>
+ static yes_type is_same_tester(V*, V*);
+ static no_type is_same_tester(...);
+
+ static T *t;
+ static U *u;
+
+ static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u));
+};
+
+template<typename T>
+struct add_const
+{ typedef const T type; };
+
+template<typename T>
+struct remove_const
+{ typedef T type; };
+
+template<typename T>
+struct remove_const<const T>
+{ typedef T type; };
+
+template<class T>
+struct remove_reference
+{
+ typedef T type;
+};
+
+template<class T>
+struct remove_reference<T&>
+{
+ typedef T type;
+};
+
+template<class Class>
+class is_empty_class
+{
+ template <typename T>
+ struct empty_helper_t1 : public T
+ {
+ empty_helper_t1();
+ int i[256];
+ };
+
+ struct empty_helper_t2
+ { int i[256]; };
+
+ public:
+ static const bool value = sizeof(empty_helper_t1<Class>) == sizeof(empty_helper_t2);
+};
+
+template<std::size_t S>
+struct ls_zeros
+{
+ static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
+};
+
+template<>
+struct ls_zeros<0>
+{
+ static const std::size_t value = 0;
+};
+
+template<>
+struct ls_zeros<1>
+{
+ static const std::size_t value = 0;
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP

Added: sandbox/boost/intrusive/detail/parent_from_member.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/parent_from_member.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,71 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_PARENT_FROM_MEMBER_HPP
+#define BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <cstddef>
+
+#if defined(BOOST_MSVC) || ((defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && defined(BOOST_INTEL))
+
+#define BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#include <boost/cstdint.hpp>
+#endif
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template<class Parent, class Member>
+inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member)
+{
+ //The implementation of a pointer to member is compiler dependent.
+ #if defined(BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER)
+ //msvc compliant compilers use their the first 32 bits as offset (even in 64 bit mode)
+ return *(const boost::int32_t*)(void*)&ptr_to_member;
+ //This works with gcc, msvc, ac++, ibmcpp
+ #elif defined(__GNUC__) || defined(__HP_aCC) || defined(BOOST_INTEL) || \
+ defined(__IBMCPP__) || defined(__DECCXX)
+ const Parent * const parent = 0;
+ const char *const member = reinterpret_cast<const char*>(&(parent->*ptr_to_member));
+ return std::ptrdiff_t(member - reinterpret_cast<const char*>(parent));
+ #else
+ //This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC
+ return (*(const std::ptrdiff_t*)(void*)&ptr_to_member) - 1;
+ #endif
+}
+
+template<class Parent, class Member>
+inline Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
+{
+ return (Parent*)((char*)member -
+ offset_from_pointer_to_member(ptr_to_member));
+}
+
+template<class Parent, class Member>
+inline const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
+{
+ return (const Parent*)((const char*)member -
+ offset_from_pointer_to_member(ptr_to_member));
+}
+
+} //namespace detail {
+} //namespace intrusive {
+} //namespace boost {
+
+#ifdef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#undef BOOST_INTRUSIVE_MSVC_COMPLIANT_PTR_TO_MEMBER
+#endif
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP

Added: sandbox/boost/intrusive/detail/pointer_to_other.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/pointer_to_other.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,65 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_POINTER_TO_OTHER_HPP
+#define BOOST_INTRUSIVE_POINTER_TO_OTHER_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/version.hpp>
+
+#if (BOOST_VERSION < 103400)
+
+#ifndef BOOST_POINTER_TO_OTHER_HPP_INCLUDED
+#define BOOST_POINTER_TO_OTHER_HPP_INCLUDED
+
+namespace boost {
+
+template<class T, class U>
+ struct pointer_to_other;
+
+template<class T, class U, template <class> class Sp>
+ struct pointer_to_other< Sp<T>, U >
+{
+ typedef Sp<U> type;
+};
+
+template<class T, class T2, class U,
+ template <class, class> class Sp>
+ struct pointer_to_other< Sp<T, T2>, U >
+{
+ typedef Sp<U, T2> type;
+};
+
+template<class T, class T2, class T3, class U,
+ template <class, class, class> class Sp>
+struct pointer_to_other< Sp<T, T2, T3>, U >
+{
+ typedef Sp<U, T2, T3> type;
+};
+
+template<class T, class U>
+struct pointer_to_other< T*, U >
+{
+ typedef U* type;
+};
+
+} // namespace boost
+
+#endif
+
+#else
+
+#include <boost/pointer_to_other.hpp>
+
+#endif //#ifndef BOOST_POINTER_TO_OTHER_HPP_INCLUDED
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_POINTER_TO_OTHER_HPP

Added: sandbox/boost/intrusive/detail/rbtree_node.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/rbtree_node.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,177 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008.
+//
+// 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_RBTREE_NODE_HPP
+#define BOOST_INTRUSIVE_RBTREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/rbtree_algorithms.hpp>
+#include <boost/intrusive/pointer_plus_bits.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Generic node_traits for any pointer type //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+//This is the compact representation: 3 pointers
+template<class VoidPointer>
+struct compact_rbtree_node
+{
+ typedef typename pointer_to_other
+ <VoidPointer
+ ,compact_rbtree_node<VoidPointer> >::type node_ptr;
+ enum color { red_t, black_t };
+ node_ptr parent_, left_, right_;
+};
+
+//This is the normal representation: 3 pointers + enum
+template<class VoidPointer>
+struct rbtree_node
+{
+ typedef typename pointer_to_other
+ <VoidPointer
+ ,rbtree_node<VoidPointer> >::type node_ptr;
+
+ enum color { red_t, black_t };
+ node_ptr parent_, left_, right_;
+ color color_;
+};
+
+//This is the default node traits implementation
+//using a node with 3 generic pointers plus an enum
+template<class VoidPointer>
+struct default_rbtree_node_traits_impl
+{
+ typedef rbtree_node<VoidPointer> node;
+
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ typedef typename node::color color;
+
+ static node_ptr get_parent(const_node_ptr n)
+ { return n->parent_; }
+
+ static void set_parent(node_ptr n, node_ptr p)
+ { n->parent_ = p; }
+
+ static node_ptr get_left(const_node_ptr n)
+ { return n->left_; }
+
+ static void set_left(node_ptr n, node_ptr l)
+ { n->left_ = l; }
+
+ static node_ptr get_right(const_node_ptr n)
+ { return n->right_; }
+
+ static void set_right(node_ptr n, node_ptr r)
+ { n->right_ = r; }
+
+ static color get_color(const_node_ptr n)
+ { return n->color_; }
+
+ static void set_color(node_ptr n, color c)
+ { n->color_ = c; }
+
+ static color black()
+ { return node::black_t; }
+
+ static color red()
+ { return node::red_t; }
+};
+
+//This is the compact node traits implementation
+//using a node with 3 generic pointers
+template<class VoidPointer>
+struct compact_rbtree_node_traits_impl
+{
+ typedef compact_rbtree_node<VoidPointer> node;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ typedef pointer_plus_bits<node_ptr, 1> ptr_bit;
+
+ typedef typename node::color color;
+
+ static node_ptr get_parent(const_node_ptr n)
+ { return ptr_bit::get_pointer(n->parent_); }
+
+ static void set_parent(node_ptr n, node_ptr p)
+ { ptr_bit::set_pointer(n->parent_, p); }
+
+ static node_ptr get_left(const_node_ptr n)
+ { return n->left_; }
+
+ static void set_left(node_ptr n, node_ptr l)
+ { n->left_ = l; }
+
+ static node_ptr get_right(const_node_ptr n)
+ { return n->right_; }
+
+ static void set_right(node_ptr n, node_ptr r)
+ { n->right_ = r; }
+
+ static color get_color(const_node_ptr n)
+ { return (color)ptr_bit::get_bits(n->parent_); }
+
+ static void set_color(node_ptr n, color c)
+ { ptr_bit::set_bits(n->parent_, c != 0); }
+
+ static color black()
+ { return node::black_t; }
+
+ static color red()
+ { return node::red_t; }
+};
+
+//Dispatches the implementation based on the boolean
+template<class VoidPointer, bool Compact>
+struct rbtree_node_traits_dispatch
+ : public default_rbtree_node_traits_impl<VoidPointer>
+{};
+
+template<class VoidPointer>
+struct rbtree_node_traits_dispatch<VoidPointer, true>
+ : public compact_rbtree_node_traits_impl<VoidPointer>
+{};
+
+//Inherit from the detail::link_dispatch depending on the embedding capabilities
+template<class VoidPointer, bool OptimizeSize = false>
+struct rbtree_node_traits
+ : public rbtree_node_traits_dispatch
+ < VoidPointer
+ , OptimizeSize &&
+ (max_pointer_plus_bits
+ < VoidPointer
+ , detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
+ >::value >= 1)
+ >
+{};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_RBTREE_NODE_HPP

Added: sandbox/boost/intrusive/detail/slist_node.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/slist_node.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,163 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_SLIST_NODE_HPP
+#define BOOST_INTRUSIVE_SLIST_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct slist_node
+{
+ typedef typename boost::pointer_to_other
+ <VoidPointer, slist_node>::type node_ptr;
+ node_ptr next_;
+};
+
+// slist_node_traits can be used with circular_slist_algorithms and supplies
+// a slist_node holding the pointers needed for a singly-linked list
+// it is used by slist_base_hook and slist_member_hook
+template<class VoidPointer>
+struct slist_node_traits
+{
+ typedef slist_node<VoidPointer> node;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ static node_ptr get_next(const_node_ptr n)
+ { return n->next_; }
+
+ static void set_next(node_ptr n, node_ptr next)
+ { n->next_ = next; }
+};
+
+// slist_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class slist_iterator
+ : public std::iterator
+ < std::forward_iterator_tag
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>
+ ::type value_type;
+ typedef value_type & reference;
+ typedef value_type * pointer;
+
+ slist_iterator()
+ : members_ (node_ptr(0), 0)
+ {}
+
+ explicit slist_iterator(node_ptr node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ slist_iterator(slist_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ slist_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<slist_iterator&>(*this); }
+
+ public:
+ slist_iterator& operator++()
+ {
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return static_cast<slist_iterator&> (*this);
+ }
+
+ slist_iterator operator++(int)
+ {
+ slist_iterator result (*this);
+ members_.nodeptr_ = node_traits::get_next(members_.nodeptr_);
+ return result;
+ }
+
+ bool operator== (const slist_iterator& i) const
+ { return members_.nodeptr_ == i.pointed_node(); }
+
+ bool operator!= (const slist_iterator& i) const
+ { return !operator== (i); }
+
+ value_type& operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(members_.nodeptr_)); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(members_.get_ptr());
+ else
+ return 0;
+ }
+
+ slist_iterator<Container, false> unconst() const
+ { return slist_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SLIST_NODE_HPP

Added: sandbox/boost/intrusive/detail/transform_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/transform_iterator.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,173 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_TRANSFORM_ITERATOR_HPP
+#define BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template <class PseudoReference>
+struct operator_arrow_proxy
+{
+ operator_arrow_proxy(const PseudoReference &px)
+ : m_value(px)
+ {}
+
+ PseudoReference* operator->() const { return &m_value; }
+ // This function is needed for MWCW and BCC, which won't call operator->
+ // again automatically per 13.3.1.2 para 8
+// operator T*() const { return &m_value; }
+ mutable PseudoReference m_value;
+};
+
+template <class T>
+struct operator_arrow_proxy<T&>
+{
+ operator_arrow_proxy(T &px)
+ : m_value(px)
+ {}
+
+ T* operator->() const { return &m_value; }
+ // This function is needed for MWCW and BCC, which won't call operator->
+ // again automatically per 13.3.1.2 para 8
+// operator T*() const { return &m_value; }
+ mutable T &m_value;
+};
+
+template <class Iterator, class UnaryFunction>
+class transform_iterator
+ : public std::iterator
+ < typename Iterator::iterator_category
+ , typename detail::remove_reference<typename UnaryFunction::result_type>::type
+ , typename Iterator::difference_type
+ , operator_arrow_proxy<typename UnaryFunction::result_type>
+ , typename UnaryFunction::result_type>
+{
+ public:
+ explicit transform_iterator(const Iterator &it, const UnaryFunction &f = UnaryFunction())
+ : members_(it, f)
+ {}
+
+ explicit transform_iterator()
+ : members_()
+ {}
+
+ Iterator get_it() const
+ { return members_.m_it; }
+
+ //Constructors
+ transform_iterator& operator++()
+ { increment(); return *this; }
+
+ transform_iterator operator++(int)
+ {
+ transform_iterator result (*this);
+ increment();
+ return result;
+ }
+
+ friend bool operator== (const transform_iterator& i, const transform_iterator& i2)
+ { return i.equal(i2); }
+
+ friend bool operator!= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i == i2); }
+
+/*
+ friend bool operator> (const transform_iterator& i, const transform_iterator& i2)
+ { return i2 < i; }
+
+ friend bool operator<= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i > i2); }
+
+ friend bool operator>= (const transform_iterator& i, const transform_iterator& i2)
+ { return !(i < i2); }
+*/
+ friend typename Iterator::difference_type operator- (const transform_iterator& i, const transform_iterator& i2)
+ { return i2.distance_to(i); }
+
+ //Arithmetic
+ transform_iterator& operator+=(typename Iterator::difference_type off)
+ { this->advance(off); return *this; }
+
+ transform_iterator operator+(typename Iterator::difference_type off) const
+ {
+ transform_iterator other(*this);
+ other.advance(off);
+ return other;
+ }
+
+ friend transform_iterator operator+(typename Iterator::difference_type off, const transform_iterator& right)
+ { return right + off; }
+
+ transform_iterator& operator-=(typename Iterator::difference_type off)
+ { this->advance(-off); return *this; }
+
+ transform_iterator operator-(typename Iterator::difference_type off) const
+ { return *this + (-off); }
+
+ typename UnaryFunction::result_type operator*() const
+ { return dereference(); }
+
+ operator_arrow_proxy<typename UnaryFunction::result_type>
+ operator->() const
+ { return operator_arrow_proxy<typename UnaryFunction::result_type>(dereference()); }
+
+ private:
+ struct members
+ : UnaryFunction
+ {
+ members(const Iterator &it, const UnaryFunction &f)
+ : UnaryFunction(f), m_it(it)
+ {}
+
+ members()
+ {}
+
+ Iterator m_it;
+ } members_;
+
+
+ void increment()
+ { ++members_.m_it; }
+
+ void decrement()
+ { --members_.m_it; }
+
+ bool equal(const transform_iterator &other) const
+ { return members_.m_it == other.members_.m_it; }
+
+ bool less(const transform_iterator &other) const
+ { return other.members_.m_it < members_.m_it; }
+
+ typename UnaryFunction::result_type dereference() const
+ { return members_(*members_.m_it); }
+
+ void advance(typename Iterator::difference_type n)
+ { std::advance(members_.m_it, n); }
+
+ typename Iterator::difference_type distance_to(const transform_iterator &other)const
+ { return std::distance(other.members_.m_it, members_.m_it); }
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_DETAIL_TRANSFORM_ITERATOR_HPP

Added: sandbox/boost/intrusive/detail/tree_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/tree_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1629 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+
+#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>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+//! 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
+//! implementation of iterator a pointer to a node.
+//! At the top of the tree a node is used specially. This node's parent pointer
+//! is pointing to the root of the tree. Its left pointer points to the
+//! leftmost node in the tree and the right pointer to the rightmost one.
+//! This node is used to represent the end-iterator.
+//!
+//! +---------+
+//! header------------------------------>| |
+//! | |
+//! +----------(left)--------| |--------(right)---------+
+//! | +---------+ |
+//! | | |
+//! | | (parent) |
+//! | | |
+//! | | |
+//! | +---------+ |
+//! root of tree ..|......................> | | |
+//! | | D | |
+//! | | | |
+//! | +-------+---------+-------+ |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | +---------+ +---------+ |
+//! | | | | | |
+//! | | B | | F | |
+//! | | | | | |
+//! | +--+---------+--+ +--+---------+--+ |
+//! | | | | | |
+//! | | | | | |
+//! | | | | | |
+//! | +---+-----+ +-----+---+ +---+-----+ +-----+---+ |
+//! +-->| | | | | | | |<--+
+//! | A | | C | | E | | G |
+//! | | | | | | | |
+//! +---------+ +---------+ +---------+ +---------+
+//!
+
+//! tree_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_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class tree_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(0)
+ {}
+ bool link_left;
+ node_ptr node;
+ };
+
+ struct nop_erase_fixup
+ {
+ void operator()(node_ptr, node_ptr){}
+ };
+
+ /// @cond
+ private:
+ template<class Disposer>
+ struct dispose_subtree_disposer
+ {
+ dispose_subtree_disposer(Disposer &disp, node_ptr subtree)
+ : disposer_(&disp), subtree_(subtree)
+ {}
+
+ void release()
+ { disposer_ = 0; }
+
+ ~dispose_subtree_disposer()
+ {
+ if(disposer_){
+ dispose_subtree(subtree_, *disposer_);
+ }
+ }
+ Disposer *disposer_;
+ node_ptr subtree_;
+ };
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return node_traits::get_left(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return uncast(header); }
+
+ //! <b>Requires</b>: node is a node of the tree or an node initialized
+ //! by init(...) or init_node.
+ //!
+ //! <b>Effects</b>: Returns true if the node is initialized by init() or init_node().
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool unique(const_node_ptr node)
+ { return NodeTraits::get_parent(node) == 0; }
+
+ static node_ptr get_header(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);
+ }
+ return h;
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(get_header(node1)), header2(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
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ {
+ if(node1 == node2)
+ return;
+
+ //node1 and node2 must not be header nodes
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT((header1 != node1 && header2 != node2));
+ if(header1 != header2){
+ //Update header1 if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+
+ //Update header2 if necessary
+ if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+ }
+ else{
+ //If both nodes are from the same tree
+ //Update header if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+
+ //Adjust data in nodes to be swapped
+ //so that final link swap works as expected
+ if(node1 == NodeTraits::get_parent(node2)){
+ NodeTraits::set_parent(node2, node2);
+
+ if(node2 == NodeTraits::get_right(node1)){
+ NodeTraits::set_right(node1, node1);
+ }
+ else{
+ NodeTraits::set_left(node1, node1);
+ }
+ }
+ else if(node2 == NodeTraits::get_parent(node1)){
+ NodeTraits::set_parent(node1, node1);
+
+ if(node1 == NodeTraits::get_right(node2)){
+ NodeTraits::set_right(node2, node2);
+ }
+ else{
+ NodeTraits::set_left(node2, node2);
+ }
+ }
+ }
+
+ //Now swap all the links
+ node_ptr temp;
+ //swap left link
+ temp = NodeTraits::get_left(node1);
+ NodeTraits::set_left(node1, NodeTraits::get_left(node2));
+ NodeTraits::set_left(node2, temp);
+ //swap right link
+ temp = NodeTraits::get_right(node1);
+ NodeTraits::set_right(node1, NodeTraits::get_right(node2));
+ NodeTraits::set_right(node2, temp);
+ //swap parent link
+ temp = NodeTraits::get_parent(node1);
+ NodeTraits::set_parent(node1, NodeTraits::get_parent(node2));
+ NodeTraits::set_parent(node2, temp);
+
+ //Now adjust adjacent nodes for newly inserted node 1
+ if((temp = NodeTraits::get_left(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_right(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_parent(node1)) &&
+ //The header has been already updated so avoid it
+ temp != header2){
+ if(NodeTraits::get_left(temp) == node2){
+ NodeTraits::set_left(temp, node1);
+ }
+ if(NodeTraits::get_right(temp) == node2){
+ NodeTraits::set_right(temp, node1);
+ }
+ }
+ //Now adjust adjacent nodes for newly inserted node 2
+ if((temp = NodeTraits::get_left(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_right(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_parent(node2)) &&
+ //The header has been already updated so avoid it
+ temp != header1){
+ if(NodeTraits::get_left(temp) == node1){
+ NodeTraits::set_left(temp, node2);
+ }
+ if(NodeTraits::get_right(temp) == node1){
+ NodeTraits::set_right(temp, node2);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+ replace_node(node_to_be_replaced, 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
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+
+ //Update header if necessary
+ if(node_to_be_replaced == NodeTraits::get_left(header)){
+ NodeTraits::set_left(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_right(header)){
+ NodeTraits::set_right(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_parent(header)){
+ NodeTraits::set_parent(header, new_node);
+ }
+
+ //Now set data from the original node
+ node_ptr temp;
+ NodeTraits::set_left(new_node, NodeTraits::get_left(node_to_be_replaced));
+ NodeTraits::set_right(new_node, NodeTraits::get_right(node_to_be_replaced));
+ NodeTraits::set_parent(new_node, NodeTraits::get_parent(node_to_be_replaced));
+
+ //Now adjust adjacent nodes for newly inserted node
+ if((temp = NodeTraits::get_left(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_right(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_parent(new_node)) &&
+ //The header has been already updated so avoid it
+ temp != header){
+ if(NodeTraits::get_left(temp) == node_to_be_replaced){
+ NodeTraits::set_left(temp, new_node);
+ }
+ if(NodeTraits::get_right(temp) == node_to_be_replaced){
+ NodeTraits::set_right(temp, new_node);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ {
+ node_ptr p_right(NodeTraits::get_right(p));
+ if(p_right){
+ return minimum(p_right);
+ }
+ else {
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_right(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return NodeTraits::get_right(p) != x ? x : uncast(p);
+ }
+ }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ {
+ if(is_header(p)){
+ return maximum(NodeTraits::get_parent(p));
+ }
+ else if(NodeTraits::get_left(p)){
+ return maximum(NodeTraits::get_left(p));
+ }
+ else {
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_left(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return x;
+ }
+ }
+
+ //! <b>Requires</b>: p is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the minimum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr minimum (node_ptr p)
+ {
+ for(node_ptr p_left = NodeTraits::get_left(p)
+ ;p_left
+ ;p_left = NodeTraits::get_left(p)){
+ p = p_left;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: p is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the maximum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr maximum(node_ptr p)
+ {
+ for(node_ptr p_right = NodeTraits::get_right(p)
+ ;p_right
+ ;p_right = NodeTraits::get_right(p)){
+ p = p_right;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ {
+ NodeTraits::set_parent(node, node_ptr(0));
+ NodeTraits::set_left(node, node_ptr(0));
+ NodeTraits::set_right(node, node_ptr(0));
+ };
+
+ //! <b>Effects</b>: Returns true if node is in the same state as if called init(node)
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool inited(const_node_ptr node)
+ {
+ return !NodeTraits::get_parent(node) &&
+ !NodeTraits::get_left(node) &&
+ !NodeTraits::get_right(node) ;
+ };
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ {
+ NodeTraits::set_parent(header, node_ptr(0));
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+
+ //! <b>Requires</b>: "disposer" must be an object function
+ //! taking a node_ptr parameter and shouldn't throw.
+ //!
+ //! <b>Effects</b>: Empties the target tree calling
+ //! <tt>void disposer::operator()(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.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ {
+ node_ptr source_root = NodeTraits::get_parent(header);
+ if(!source_root)
+ return;
+ dispose_subtree(source_root, disposer);
+ init_header(header);
+ }
+
+ //! <b>Requires</b>: header is the header of a tree.
+ //!
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree, and
+ //! updates the header link to the new leftmost node.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ static node_ptr unlink_leftmost_without_rebalance(node_ptr header)
+ {
+ node_ptr leftmost = NodeTraits::get_left(header);
+ if (leftmost == header)
+ return node_ptr(0);
+ node_ptr leftmost_parent(NodeTraits::get_parent(leftmost));
+ node_ptr leftmost_right (NodeTraits::get_right(leftmost));
+ bool is_root = leftmost_parent == header;
+
+ if (leftmost_right){
+ NodeTraits::set_parent(leftmost_right, leftmost_parent);
+ NodeTraits::set_left(header, tree_algorithms::minimum(leftmost_right));
+
+ if (is_root)
+ NodeTraits::set_parent(header, leftmost_right);
+ else
+ NodeTraits::set_left(NodeTraits::get_parent(header), leftmost_right);
+ }
+ else if (is_root){
+ NodeTraits::set_parent(header, node_ptr(0));
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+ else{
+ NodeTraits::set_left(leftmost_parent, node_ptr(0));
+ NodeTraits::set_left(header, leftmost_parent);
+ }
+ return leftmost;
+ }
+
+ //! <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_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_node_ptr header)
+ {
+ node_ptr beg(begin_node(header));
+ node_ptr end(end_node(header));
+ std::size_t i = 0;
+ for(;beg != end; beg = next_node(beg)) ++i;
+ return i;
+ }
+
+ //! <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(node_ptr header1, node_ptr header2)
+ {
+ if(header1 == header2)
+ return;
+
+ node_ptr tmp;
+
+ //Parent swap
+ tmp = NodeTraits::get_parent(header1);
+ NodeTraits::set_parent(header1, NodeTraits::get_parent(header2));
+ NodeTraits::set_parent(header2, tmp);
+ //Left swap
+ tmp = NodeTraits::get_left(header1);
+ NodeTraits::set_left(header1, NodeTraits::get_left(header2));
+ NodeTraits::set_left(header2, tmp);
+ //Right swap
+ tmp = NodeTraits::get_right(header1);
+ NodeTraits::set_right(header1, NodeTraits::get_right(header2));
+ NodeTraits::set_right(header2, tmp);
+
+ //Now test parent
+ node_ptr h1_parent(NodeTraits::get_parent(header1));
+ if(h1_parent){
+ NodeTraits::set_parent(h1_parent, header1);
+ }
+ else{
+ NodeTraits::set_left(header1, header1);
+ NodeTraits::set_right(header1, header1);
+ }
+
+ node_ptr h2_parent(NodeTraits::get_parent(header2));
+ if(h2_parent){
+ NodeTraits::set_parent(h2_parent, header2);
+ }
+ else{
+ NodeTraits::set_left(header2, header2);
+ NodeTraits::set_right(header2, header2);
+ }
+ }
+
+ static bool is_header(const_node_ptr p)
+ {
+ bool is_header = false;
+ if(NodeTraits::get_parent(p) == p){
+ is_header = true;
+ }
+ else if(NodeTraits::get_parent(NodeTraits::get_parent(p)) == p){
+ if(NodeTraits::get_left(p) != 0){
+ if(NodeTraits::get_parent(NodeTraits::get_left(p)) != p){
+ is_header = true;
+ }
+ if(NodeTraits::get_parent(p) == NodeTraits::get_left(p)){
+ is_header = true;
+ }
+ }
+ }
+ return is_header;
+ }
+
+ //! <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.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr end = uncast(header);
+ node_ptr y = lower_bound(header, key, comp);
+ return (y == end || comp(key, y)) ? end : y;
+ }
+
+ //! <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.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else{
+ node_ptr xu(x), yu(y);
+ y = x, x = NodeTraits::get_left(x);
+ xu = NodeTraits::get_right(xu);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+
+ while(xu){
+ if(comp(key, xu)){
+ yu = xu;
+ xu = NodeTraits::get_left(xu);
+ }
+ else {
+ xu = NodeTraits::get_right(xu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, yu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, y);
+ }
+
+ //! <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.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else {
+ x = NodeTraits::get_right(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_value, 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 != 0);
+ link(header, new_value, commit_data.node, commit_data.link_left);
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ std::size_t depth = 0;
+ node_ptr h(uncast(header));
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+ node_ptr prev(0);
+
+ //Find the upper bound, cache the previous value and if we should
+ //store it in the left or right node
+ bool left_child = true;
+ while(x){
+ ++depth;
+ y = x;
+ x = (left_child = comp(key, x)) ?
+ NodeTraits::get_left(x) : (prev = y, NodeTraits::get_right(x));
+ }
+
+ if(pdepth) *pdepth = depth;
+
+ //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)){
+ 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);
+ }
+ }
+
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, node_ptr hint, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data, std::size_t *pdepth = 0)
+ {
+ //hint must be bigger than the key
+ if(hint == header || comp(key, hint)){
+ node_ptr prev = hint;
+ //The previous value should be less than the key
+ if(prev == NodeTraits::get_left(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){
+ *pdepth = commit_data.node == header ? 0 : depth(commit_data.node) + 1;
+ }
+ return std::pair<node_ptr, bool>(node_ptr(), true);
+ }
+ else{
+ return insert_unique_check(header, key, comp, commit_data, pdepth);
+ }
+ }
+ //The hint was wrong, use hintless insert
+ else{
+ return insert_unique_check(header, key, comp, commit_data, pdepth);
+ }
+ }
+
+ template<class NodePtrCompare>
+ static void insert_equal_check
+ ( node_ptr header, node_ptr hint, 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
+ (node_ptr h, 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
+ (node_ptr h, 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); }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal
+ (node_ptr h, node_ptr hint, node_ptr new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_check(h, hint, new_node, comp, commit_data, pdepth);
+ link(h, new_node, commit_data.node, commit_data.link_left);
+ return new_node;
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_upper_bound_check(h, new_node, comp, commit_data, pdepth);
+ link(h, new_node, commit_data.node, commit_data.link_left);
+ return new_node;
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp, std::size_t *pdepth = 0)
+ {
+ insert_commit_data commit_data;
+ insert_equal_lower_bound_check(h, new_node, comp, commit_data, pdepth);
+ link(h, new_node, commit_data.node, commit_data.link_left);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: p can't be a header node.
+ //!
+ //! <b>Effects</b>: Calculates the depth of a node: the depth of a
+ //! node is the length (number of edges) of the path from the root
+ //! to that node. (The root node is at depth 0.)
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of nodes in the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t depth(const_node_ptr p)
+ {
+ std::size_t depth = 0;
+ node_ptr p_parent;
+ while(p != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(p))){
+ ++depth;
+ p = p_parent;
+ }
+ return depth;
+ }
+
+ //! <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()(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()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ {
+ if(!unique(target_header)){
+ clear_and_dispose(target_header, disposer);
+ }
+
+ node_ptr leftmost, rightmost;
+ node_ptr new_root = clone_subtree
+ (source_header, target_header, cloner, disposer, leftmost, rightmost);
+
+ //Now update header node
+ NodeTraits::set_parent(target_header, new_root);
+ NodeTraits::set_left (target_header, leftmost);
+ NodeTraits::set_right (target_header, rightmost);
+ }
+
+ template <class Cloner, class Disposer>
+ static node_ptr clone_subtree
+ ( const_node_ptr source_parent, 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(0));
+ NodeTraits::set_right(target_sub_root, node_ptr(0));
+ 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(0));
+ NodeTraits::set_right (insertion_point, node_ptr(0));
+ //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(0));
+ NodeTraits::set_right (insertion_point, node_ptr(0));
+ //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)
+ {
+ node_ptr save;
+ while (x){
+ 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;
+ }
+ }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a left child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_left_child(node_ptr p)
+ { return NodeTraits::get_left(NodeTraits::get_parent(p)) == p; }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a right child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_right_child (node_ptr p)
+ { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; }
+
+ static void replace_own (node_ptr own, node_ptr x, node_ptr header)
+ {
+ if(NodeTraits::get_parent(header) == own)
+ NodeTraits::set_parent(header, x);
+ else if(is_left_child(own))
+ NodeTraits::set_left(NodeTraits::get_parent(own), x);
+ else
+ NodeTraits::set_right(NodeTraits::get_parent(own), x);
+ }
+
+ static void rotate_left(node_ptr p, node_ptr header)
+ {
+ node_ptr x = NodeTraits::get_right(p);
+ NodeTraits::set_right(p, NodeTraits::get_left(x));
+ if(NodeTraits::get_left(x) != 0)
+ NodeTraits::set_parent(NodeTraits::get_left(x), p);
+ NodeTraits::set_parent(x, NodeTraits::get_parent(p));
+ replace_own (p, x, header);
+ NodeTraits::set_left(x, p);
+ NodeTraits::set_parent(p, x);
+ }
+
+ static void rotate_right(node_ptr p, node_ptr header)
+ {
+ 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);
+ NodeTraits::set_parent(x, NodeTraits::get_parent(p));
+ replace_own (p, x, header);
+ NodeTraits::set_right(x, p);
+ NodeTraits::set_parent(p, x);
+ }
+
+ // rotate node t with left child | complexity : constant | exception : nothrow
+ static node_ptr rotate_left(node_ptr t)
+ {
+ node_ptr x = NodeTraits::get_right(t);
+ NodeTraits::set_right(t, NodeTraits::get_left(x));
+
+ if( NodeTraits::get_right(t) != 0 ){
+ NodeTraits::set_parent(NodeTraits::get_right(t), t );
+ }
+ NodeTraits::set_left(x, t);
+ NodeTraits::set_parent(t, x);
+ return x;
+ }
+
+ // rotate node t with right child | complexity : constant | exception : nothrow
+ static node_ptr rotate_right(node_ptr t)
+ {
+ node_ptr x = NodeTraits::get_left(t);
+ NodeTraits::set_left(t, NodeTraits::get_right(x));
+ if( NodeTraits::get_left(t) != 0 ){
+ NodeTraits::set_parent(NodeTraits::get_left(t), t);
+ }
+ NodeTraits::set_right(x, t);
+ NodeTraits::set_parent(t, x);
+ return x;
+ }
+
+ static void link(node_ptr header, node_ptr z, node_ptr par, bool left)
+ {
+ if(par == header){
+ NodeTraits::set_parent(header, z);
+ NodeTraits::set_right(header, z);
+ NodeTraits::set_left(header, z);
+ }
+ else if(left){
+ NodeTraits::set_left(par, z);
+ if(par == NodeTraits::get_left(header))
+ NodeTraits::set_left(header, z);
+ }
+ else{
+ NodeTraits::set_right(par, z);
+ if(par == NodeTraits::get_right(header))
+ NodeTraits::set_right(header, z);
+ }
+ NodeTraits::set_parent(z, par);
+ NodeTraits::set_right(z, node_ptr(0));
+ NodeTraits::set_left(z, node_ptr(0));
+ }
+
+ static void erase(node_ptr header, node_ptr z)
+ {
+ data_for_rebalance ignored;
+ erase(header, z, nop_erase_fixup(), ignored);
+ }
+
+ struct data_for_rebalance
+ {
+ node_ptr x;
+ node_ptr x_parent;
+ node_ptr y;
+ };
+
+ template<class F>
+ static void erase(node_ptr header, node_ptr z, F z_and_successor_fixup, data_for_rebalance &info)
+ {
+ erase_impl(header, z, info);
+ if(info.y != z){
+ z_and_successor_fixup(z, info.y);
+ }
+ }
+
+ static void unlink(node_ptr node)
+ {
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x))
+ x = NodeTraits::get_parent(x);
+ erase(x, node);
+ }
+ }
+
+ static void tree_to_vine(node_ptr header)
+ { subtree_to_vine(NodeTraits::get_parent(header)); }
+
+ static void vine_to_tree(node_ptr header, std::size_t count)
+ { vine_to_subtree(NodeTraits::get_parent(header), count); }
+
+ static void rebalance(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);
+ }
+
+ static node_ptr rebalance_subtree(node_ptr old_root)
+ {
+ std::size_t len = 0;
+ node_ptr new_root = subtree_to_vine(old_root, &len);
+ return vine_to_subtree(new_root, len);
+ }
+
+ static node_ptr subtree_to_vine(node_ptr old_root, std::size_t *plen = 0)
+ {
+ std::size_t len;
+ len = 0;
+ if(!old_root) return node_ptr(0);
+
+ //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 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);
+
+ 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);
+ ++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);
+ }
+ if(plen) *plen = len;
+ return new_root;
+ }
+
+ static node_ptr vine_to_subtree(node_ptr old_root, std::size_t count)
+ {
+ std::size_t leaf_nodes = count + 1 - ((size_t) 1 << floor_log2 (count + 1));
+ 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);
+ }
+ return new_root;
+ }
+
+ static node_ptr compress_subtree(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;
+ }
+
+ 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.
+ //!
+ //! <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_root(node_ptr node)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT((!inited(node)));
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x)){
+ x = NodeTraits::get_parent(x);
+ }
+ return x;
+ }
+ else{
+ return node;
+ }
+ }
+
+ private:
+ template<class NodePtrCompare>
+ static void insert_equal_check_impl
+ (bool upper, node_ptr h, node_ptr new_node, NodePtrCompare comp, insert_commit_data & commit_data, std::size_t *pdepth = 0)
+ {
+ 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);
+ }
+ 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);
+ }
+
+ commit_data.link_left = link_left;
+ commit_data.node = y;
+ if(pdepth) *pdepth = depth;
+ }
+
+ static void erase_impl(node_ptr header, node_ptr z, data_for_rebalance &info)
+ {
+ node_ptr y(z);
+ node_ptr x;
+ node_ptr x_parent(0);
+ 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.
+ }
+
+ 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) == 0 ? // 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) == 0 ? // z->get_right() must be null also
+ NodeTraits::get_parent(z) : // makes rightmost == header if z == root
+ tree_algorithms::maximum(x));
+ }
+ }
+
+ info.x = x;
+ info.x_parent = x_parent;
+ info.y = y;
+ }
+};
+
+} //namespace detail {
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/detail/tree_node.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/tree_node.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,200 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_NODE_HPP
+#define BOOST_INTRUSIVE_TREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct tree_node
+{
+ typedef typename pointer_to_other
+ <VoidPointer
+ ,tree_node<VoidPointer> >::type node_ptr;
+
+ node_ptr parent_, left_, right_;
+};
+
+template<class VoidPointer>
+struct tree_node_traits
+{
+ typedef tree_node<VoidPointer> node;
+
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ static node_ptr get_parent(const_node_ptr n)
+ { return n->parent_; }
+
+ static void set_parent(node_ptr n, node_ptr p)
+ { n->parent_ = p; }
+
+ static node_ptr get_left(const_node_ptr n)
+ { return n->left_; }
+
+ static void set_left(node_ptr n, node_ptr l)
+ { n->left_ = l; }
+
+ static node_ptr get_right(const_node_ptr n)
+ { return n->right_; }
+
+ static void set_right(node_ptr n, node_ptr r)
+ { n->right_ = r; }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Implementation of the tree iterator //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+// tree_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class tree_iterator
+ : public std::iterator
+ < std::bidirectional_iterator_tag
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::node_algorithms node_algorithms;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ public:
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>
+ ::type value_type;
+ typedef value_type & reference;
+ typedef value_type * pointer;
+
+ tree_iterator()
+ : members_ (0, 0)
+ {}
+
+ explicit tree_iterator(node_ptr node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ tree_iterator(tree_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ tree_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<tree_iterator&>(*this); }
+
+ public:
+ tree_iterator& operator++()
+ {
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator++(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return result;
+ }
+
+ tree_iterator& operator--()
+ {
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator--(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return result;
+ }
+
+ bool operator== (const tree_iterator& i) const
+ { return members_.nodeptr_ == i.pointed_node(); }
+
+ bool operator!= (const tree_iterator& i) const
+ { return !operator== (i); }
+
+ value_type& operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(members_.nodeptr_)); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(members_.get_ptr());
+ else
+ return 0;
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ tree_iterator end_iterator_from_it() const
+ {
+ return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_container());
+ }
+
+ tree_iterator<Container, false> unconst() const
+ { return tree_iterator<Container, false>(this->pointed_node(), this->get_container()); }
+
+ private:
+ struct members
+ : public detail::select_constptr
+ <void_pointer, store_container_ptr>::type
+ {
+ typedef typename detail::select_constptr
+ <void_pointer, store_container_ptr>::type Base;
+
+ members(const node_ptr &n_ptr, const void *cont)
+ : Base(cont), nodeptr_(n_ptr)
+ {}
+
+ node_ptr nodeptr_;
+ } members_;
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TREE_NODE_HPP

Added: sandbox/boost/intrusive/detail/utilities.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/utilities.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,634 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP
+#define BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/parent_from_member.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/cstdint.hpp>
+#include <cstddef>
+#include <climits>
+#include <iterator>
+#include <boost/cstdint.hpp>
+#include <boost/static_assert.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+template <class T>
+struct internal_member_value_traits
+{
+ template <class U> static detail::one test(...);
+ template <class U> static detail::two test(typename U::member_value_traits* = 0);
+ static const bool value = sizeof(test<T>(0)) == sizeof(detail::two);
+};
+
+template <class T>
+struct internal_base_hook_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::boost_intrusive_tags::is_base_hook>
+ test (detail::bool_<U::boost_intrusive_tags::is_base_hook>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct internal_base_hook_bool_is_true
+{
+ static const bool value = internal_base_hook_bool<T>::value > sizeof(one)*2;
+};
+
+template <class T>
+struct internal_any_hook_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::is_any_hook>
+ test (detail::bool_<U::is_any_hook>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct internal_any_hook_bool_is_true
+{
+ static const bool value = internal_any_hook_bool<T>::value > sizeof(one)*2;
+};
+
+
+template <class T>
+struct external_value_traits_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::external_value_traits>
+ test (detail::bool_<U::external_value_traits>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct external_bucket_traits_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::external_bucket_traits>
+ test (detail::bool_<U::external_bucket_traits>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct external_value_traits_is_true
+{
+ static const bool value = external_value_traits_bool<T>::value > sizeof(one)*2;
+};
+
+template<class Node, class Tag, link_mode_type LinkMode, int>
+struct node_holder
+ : public Node
+{};
+
+template<class SmartPtr>
+struct smart_ptr_type
+{
+ typedef typename SmartPtr::value_type value_type;
+ typedef value_type *pointer;
+ static pointer get (const SmartPtr &smartptr)
+ { return smartptr.get();}
+};
+
+template<class T>
+struct smart_ptr_type<T*>
+{
+ typedef T value_type;
+ typedef value_type *pointer;
+ static pointer get (pointer ptr)
+ { return ptr;}
+};
+
+//!Overload for smart pointers to avoid ADL problems with get_pointer
+template<class Ptr>
+inline typename smart_ptr_type<Ptr>::pointer
+get_pointer(const Ptr &ptr)
+{ return smart_ptr_type<Ptr>::get(ptr); }
+
+//This functor compares a stored value
+//and the one passed as an argument
+template<class ConstReference>
+class equal_to_value
+{
+ ConstReference t_;
+
+ public:
+ equal_to_value(ConstReference t)
+ : t_(t)
+ {}
+
+ bool operator()(ConstReference t)const
+ { return t_ == t; }
+};
+
+class null_disposer
+{
+ public:
+ template <class Pointer>
+ void operator()(Pointer)
+ {}
+};
+
+template<class NodeAlgorithms>
+class init_disposer
+{
+ typedef typename NodeAlgorithms::node_ptr node_ptr;
+
+ public:
+ void operator()(node_ptr p)
+ { NodeAlgorithms::init(p); }
+};
+
+template<bool ConstantSize, class SizeType>
+struct size_holder
+{
+ static const bool constant_time_size = ConstantSize;
+ typedef SizeType size_type;
+
+ SizeType get_size() const
+ { return size_; }
+
+ void set_size(SizeType size)
+ { size_ = size; }
+
+ void decrement()
+ { --size_; }
+
+ void increment()
+ { ++size_; }
+
+ SizeType size_;
+};
+
+template<class SizeType>
+struct size_holder<false, SizeType>
+{
+ static const bool constant_time_size = false;
+ typedef SizeType size_type;
+
+ size_type get_size() const
+ { return 0; }
+
+ void set_size(size_type)
+ {}
+
+ void decrement()
+ {}
+
+ void increment()
+ {}
+};
+
+template<class KeyValueCompare, class Container>
+struct key_nodeptr_comp
+ : private detail::ebo_functor_holder<KeyValueCompare>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef typename real_value_traits::const_node_ptr const_node_ptr;
+ typedef detail::ebo_functor_holder<KeyValueCompare> base_t;
+ key_nodeptr_comp(KeyValueCompare kcomp, const Container *cont)
+ : base_t(kcomp), cont_(cont)
+ {}
+
+ template<class KeyType>
+ bool operator()( const_node_ptr node, const KeyType &key
+ , typename enable_if_c
+ <!is_convertible<KeyType, const_node_ptr>::value>::type * = 0) const
+ { return base_t::get()(*cont_->get_real_value_traits().to_value_ptr(node), key); }
+
+ template<class KeyType>
+ bool operator()(const KeyType &key, const_node_ptr node
+ , typename enable_if_c
+ <!is_convertible<KeyType, const_node_ptr>::value>::type * = 0) const
+ { return base_t::get()(key, *cont_->get_real_value_traits().to_value_ptr(node)); }
+
+ bool operator()(const_node_ptr node1, const_node_ptr node2) const
+ {
+ return base_t::get()
+ ( *cont_->get_real_value_traits().to_value_ptr(node1)
+ , *cont_->get_real_value_traits().to_value_ptr(node2)
+ );
+ }
+
+ const Container *cont_;
+};
+
+template<class F, class Container>
+struct node_cloner
+ : private detail::ebo_functor_holder<F>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::node_algorithms node_algorithms;
+ typedef typename real_value_traits::value_type value_type;
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::node_traits::node node;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef typename real_value_traits::const_node_ptr const_node_ptr;
+ typedef detail::ebo_functor_holder<F> base_t;
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ node_cloner(F f, const Container *cont)
+ : base_t(f), cont_(cont)
+ {}
+
+ node_ptr operator()(node_ptr p)
+ { return this->operator()(*p); }
+
+ node_ptr operator()(const node &to_clone)
+ {
+ const value_type &v =
+ *cont_->get_real_value_traits().to_value_ptr(const_node_ptr(&to_clone));
+ node_ptr n = cont_->get_real_value_traits().to_node_ptr(*base_t::get()(v));
+ //Cloned node must be in default mode if the linking mode requires it
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
+ return n;
+ }
+
+ const Container *cont_;
+};
+
+template<class F, class Container>
+struct node_disposer
+ : private detail::ebo_functor_holder<F>
+{
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::node_ptr node_ptr;
+ typedef detail::ebo_functor_holder<F> base_t;
+ typedef typename Container::node_algorithms node_algorithms;
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ node_disposer(F f, const Container *cont)
+ : base_t(f), cont_(cont)
+ {}
+
+ void operator()(node_ptr p)
+ {
+ if(safemode_or_autounlink)
+ node_algorithms::init(p);
+ base_t::get()(cont_->get_real_value_traits().to_value_ptr(p));
+ }
+ const Container *cont_;
+};
+
+struct dummy_constptr
+{
+ dummy_constptr(const void *)
+ {}
+
+ const void *get_ptr() const
+ { return 0; }
+};
+
+template<class VoidPointer>
+struct constptr
+{
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const void>::type ConstVoidPtr;
+
+ constptr(const void *ptr)
+ : const_void_ptr_(ptr)
+ {}
+
+ const void *get_ptr() const
+ { return detail::get_pointer(const_void_ptr_); }
+
+ ConstVoidPtr const_void_ptr_;
+};
+
+template <class VoidPointer, bool store_ptr>
+struct select_constptr
+{
+ typedef typename detail::if_c
+ < store_ptr
+ , constptr<VoidPointer>
+ , dummy_constptr
+ >::type type;
+};
+
+template <class Container>
+struct store_cont_ptr_on_it
+{
+ typedef typename Container::value_traits value_traits;
+ static const bool value =
+ !detail::is_empty_class<value_traits>::value
+ || detail::external_value_traits_is_true<value_traits>::value
+ ;
+};
+
+template<class T, bool Add>
+struct add_const_if_c
+{
+ typedef typename detail::if_c
+ < Add
+ , typename detail::add_const<T>::type
+ , T
+ >::type type;
+};
+
+template<class Container, bool IsConst>
+struct node_to_value
+ : public detail::select_constptr
+ < typename boost::pointer_to_other
+ <typename Container::pointer, void>::type
+ , detail::store_cont_ptr_on_it<Container>::value
+ >::type
+{
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename real_value_traits::value_type value_type;
+ typedef typename detail::select_constptr
+ < typename boost::pointer_to_other
+ <typename Container::pointer, void>::type
+ , store_container_ptr >::type Base;
+ typedef typename real_value_traits::node_traits::node node;
+ typedef typename detail::add_const_if_c
+ <value_type, IsConst>::type vtype;
+ typedef typename detail::add_const_if_c
+ <node, IsConst>::type ntype;
+ typedef typename boost::pointer_to_other
+ <typename Container::pointer, ntype>::type npointer;
+
+ node_to_value(const Container *cont)
+ : Base(cont)
+ {}
+
+ typedef vtype & result_type;
+ typedef ntype & first_argument_type;
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(Base::get_ptr());
+ else
+ return 0;
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ result_type operator()(first_argument_type arg) const
+ { return *(this->get_real_value_traits()->to_value_ptr(npointer(&arg))); }
+};
+
+template <link_mode_type LinkMode>
+struct link_dispatch
+{};
+
+template<class Hook>
+void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
+{ //If this assertion raises, you might have destroyed an object
+ //while it was still inserted in a container that is alive.
+ //If so, remove the object from the container before destroying it.
+ (void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
+}
+
+template<class Hook>
+void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>)
+{ hook.unlink(); }
+
+template<class Hook>
+void destructor_impl(Hook &, detail::link_dispatch<normal_link>)
+{}
+
+template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, int HookType>
+struct base_hook_traits
+{
+ public:
+ typedef detail::node_holder
+ <typename NodeTraits::node, Tag, LinkMode, HookType> node_holder;
+ typedef NodeTraits node_traits;
+ typedef T value_type;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename boost::pointer_to_other<node_ptr, T>::type pointer;
+ typedef typename boost::pointer_to_other<node_ptr, const T>::type const_pointer;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ static const link_mode_type link_mode = LinkMode;
+
+ static node_ptr to_node_ptr(reference value)
+ { return static_cast<node_holder*>(&value); }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ { return static_cast<const node_holder*>(&value); }
+
+ static pointer to_value_ptr(node_ptr n)
+ { return static_cast<T*>(static_cast<node_holder*>(&*n)); }
+
+ static const_pointer to_value_ptr(const_node_ptr n)
+ { return static_cast<const T*>(static_cast<const node_holder*>(&*n)); }
+};
+
+template<class T, class Hook, Hook T::* P>
+struct member_hook_traits
+{
+ public:
+ typedef Hook hook_type;
+ typedef typename hook_type::boost_intrusive_tags::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef T value_type;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename boost::pointer_to_other<node_ptr, T>::type pointer;
+ typedef typename boost::pointer_to_other<node_ptr, const T>::type const_pointer;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ static const link_mode_type link_mode = Hook::boost_intrusive_tags::link_mode;
+
+ static node_ptr to_node_ptr(reference value)
+ {
+ return reinterpret_cast<node*>(&(value.*P));
+ }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ {
+ return static_cast<const node*>(&(value.*P));
+ }
+
+ static pointer to_value_ptr(node_ptr n)
+ {
+ return detail::parent_from_member<T, Hook>
+ (static_cast<Hook*>(detail::get_pointer(n)), P);
+ }
+
+ static const_pointer to_value_ptr(const_node_ptr n)
+ {
+ return detail::parent_from_member<T, Hook>
+ (static_cast<const Hook*>(detail::get_pointer(n)), P);
+ }
+};
+
+//This function uses binary search to discover the
+//highest set bit of the integer
+inline std::size_t floor_log2 (std::size_t x)
+{
+ const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT;
+ const bool Size_t_Bits_Power_2= !(Bits & (Bits-1));
+ BOOST_STATIC_ASSERT(Size_t_Bits_Power_2);
+
+ std::size_t n = x;
+ std::size_t log2 = 0;
+
+ for(std::size_t shift = Bits >> 1; shift; shift >>= 1){
+ std::size_t tmp = n >> shift;
+ if (tmp)
+ log2 += shift, n = tmp;
+ }
+
+ return log2;
+}
+
+inline float fast_log2 (float val)
+{
+ boost::uint32_t * exp_ptr =
+ static_cast<boost::uint32_t *>(static_cast<void*>(&val));
+ boost::uint32_t x = *exp_ptr;
+ const int log_2 = (int)(((x >> 23) & 255) - 128);
+ x &= ~(255 << 23);
+ x += 127 << 23;
+ *exp_ptr = x;
+
+ val = ((-1.0f/3) * val + 2) * val - 2.0f/3;
+
+ return (val + log_2);
+}
+
+inline std::size_t ceil_log2 (std::size_t x)
+{
+ return ((x & (x-1))!= 0) + floor_log2(x);
+}
+
+template<class SizeType, std::size_t N>
+struct numbits_eq
+{
+ static const bool value = sizeof(SizeType)*CHAR_BIT == N;
+};
+
+template<class SizeType, class Enabler = void >
+struct sqrt2_pow_max;
+
+template <class SizeType>
+struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 32> >::type>
+{
+ static const boost::uint32_t value = 0xb504f334;
+ static const std::size_t pow = 31;
+};
+
+template <class SizeType>
+struct sqrt2_pow_max<SizeType, typename enable_if< numbits_eq<SizeType, 64> >::type>
+{
+ static const boost::uint64_t value = 0xb504f333f9de6484ull;
+ static const std::size_t pow = 63;
+};
+
+// Returns floor(pow(sqrt(2), x * 2 + 1)).
+// Defined for X from 0 up to the number of bits in size_t minus 1.
+inline std::size_t sqrt2_pow_2xplus1 (std::size_t x)
+{
+ const std::size_t value = (std::size_t)sqrt2_pow_max<std::size_t>::value;
+ const std::size_t pow = (std::size_t)sqrt2_pow_max<std::size_t>::pow;
+ return (value >> (pow - x)) + 1;
+}
+
+template<class Container, class Disposer>
+class exception_disposer
+{
+ Container *cont_;
+ Disposer &disp_;
+
+ exception_disposer(const exception_disposer&);
+ exception_disposer &operator=(const exception_disposer&);
+
+ public:
+ exception_disposer(Container &cont, Disposer &disp)
+ : cont_(&cont), disp_(disp)
+ {}
+
+ void release()
+ { cont_ = 0; }
+
+ ~exception_disposer()
+ {
+ if(cont_){
+ cont_->clear_and_dispose(disp_);
+ }
+ }
+};
+
+template<class Container, class Disposer>
+class exception_array_disposer
+{
+ Container *cont_;
+ Disposer &disp_;
+ typename Container::size_type &constructed_;
+
+ exception_array_disposer(const exception_array_disposer&);
+ exception_array_disposer &operator=(const exception_array_disposer&);
+
+ public:
+ typedef typename Container::size_type size_type;
+ exception_array_disposer
+ (Container &cont, Disposer &disp, size_type &constructed)
+ : cont_(&cont), disp_(disp), constructed_(constructed)
+ {}
+
+ void release()
+ { cont_ = 0; }
+
+ ~exception_array_disposer()
+ {
+ size_type n = constructed_;
+ if(cont_){
+ while(n--){
+ cont_[n].clear_and_dispose(disp_);
+ }
+ }
+ }
+};
+
+} //namespace detail
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP

Added: sandbox/boost/intrusive/detail/workaround.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/detail/workaround.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2005-2008. 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/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP
+#define BOOST_INTRUSIVE_DETAIL_WRKRND_HPP
+
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2)
+// C++0x features are only enabled when -std=c++0x or -std=gnu++0x are
+// passed on the command line, which in turn defines
+// __GXX_EXPERIMENTAL_CXX0X__. Note: __GXX_EXPERIMENTAL_CPP0X__ is
+// defined by some very early development versions of GCC 4.3; we will
+// remove this part of the check in the near future.
+# if defined(__GXX_EXPERIMENTAL_CPP0X__) || defined(__GXX_EXPERIMENTAL_CXX0X__)
+# define BOOST_INTRUSIVE_RVALUE_REFERENCE
+# define BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+# endif
+#endif
+
+#if defined(BOOST_INTRUSIVE_RVALUE_REFERENCE) && defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+#define BOOST_INTRUSIVE_PERFECT_FORWARDING
+#endif
+
+#endif //#ifndef BOOST_INTRUSIVE_DETAIL_WRKRND_HPP

Added: sandbox/boost/intrusive/hashtable.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/hashtable.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,3021 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_HASHTABLE_HPP
+#define BOOST_INTRUSIVE_HASHTABLE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+//std C++
+#include <functional> //std::equal_to
+#include <utility> //std::pair
+#include <algorithm> //std::swap, std::lower_bound, std::upper_bound
+#include <cstddef> //std::size_t
+#include <iterator> //std::iterator_traits
+//boost
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/functional/hash.hpp>
+//General intrusive utilities
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/hashtable_node.hpp>
+#include <boost/intrusive/detail/transform_iterator.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+//Implementation utilities
+#include <boost/intrusive/trivial_value_traits.hpp>
+#include <boost/intrusive/unordered_set_hook.hpp>
+#include <boost/intrusive/slist.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+namespace detail {
+
+struct hash_bool_flags
+{
+ static const std::size_t unique_keys_pos = 1u;
+ static const std::size_t constant_time_size_pos = 2u;
+ static const std::size_t power_2_buckets_pos = 4u;
+ static const std::size_t cache_begin_pos = 8u;
+ static const std::size_t compare_hash_pos = 16u;
+ static const std::size_t incremental_pos = 32u;
+};
+
+template
+ < class ValueTraits
+ , class Hash
+ , class Equal
+ , class SizeType
+ , class BucketTraits
+ , std::size_t BoolFlags
+ >
+struct usetopt
+{
+ typedef ValueTraits value_traits;
+ typedef Hash hash;
+ typedef Equal equal;
+ typedef SizeType size_type;
+ typedef BucketTraits bucket_traits;
+ static const std::size_t bool_flags = BoolFlags;
+};
+
+template
+ < class UsetOpt
+ , std::size_t BoolMask
+ >
+struct usetopt_mask
+{
+ typedef usetopt
+ <typename UsetOpt::value_traits
+ ,typename UsetOpt::hash
+ ,typename UsetOpt::equal
+ ,typename UsetOpt::size_type
+ ,typename UsetOpt::bucket_traits
+ ,UsetOpt::bool_flags & BoolMask
+ > type;
+};
+
+template <class NodeTraits>
+struct hash_reduced_slist_node_traits
+{
+ template <class U> static detail::one test(...);
+ template <class U> static detail::two test(typename U::reduced_slist_node_traits* = 0);
+ static const bool value = sizeof(test<NodeTraits>(0)) == sizeof(detail::two);
+};
+
+template <class NodeTraits>
+struct apply_reduced_slist_node_traits
+{
+ typedef typename NodeTraits::reduced_slist_node_traits type;
+};
+
+template <class NodeTraits>
+struct reduced_slist_node_traits
+{
+ typedef typename detail::eval_if_c
+ < hash_reduced_slist_node_traits<NodeTraits>::value
+ , apply_reduced_slist_node_traits<NodeTraits>
+ , detail::identity<NodeTraits>
+ >::type type;
+};
+
+template<class NodeTraits>
+struct get_slist_impl
+{
+ typedef trivial_value_traits<NodeTraits, normal_link> trivial_traits;
+
+ //Reducing symbol length
+ struct type : make_slist
+ < typename NodeTraits::node
+ , boost::intrusive::value_traits<trivial_traits>
+ , boost::intrusive::constant_time_size<false>
+ , boost::intrusive::size_type<std::size_t>
+ >::type
+ {};
+};
+
+template<class SupposedValueTraits>
+struct real_from_supposed_value_traits
+{
+ typedef typename detail::eval_if_c
+ < detail::external_value_traits_is_true
+ <SupposedValueTraits>::value
+ , detail::eval_value_traits
+ <SupposedValueTraits>
+ , detail::identity
+ <SupposedValueTraits>
+ >::type type;
+};
+
+template<class SupposedValueTraits>
+struct get_slist_impl_from_supposed_value_traits
+{
+ typedef typename
+ real_from_supposed_value_traits
+ < SupposedValueTraits>::type real_value_traits;
+ typedef typename detail::get_node_traits
+ <real_value_traits>::type node_traits;
+ typedef typename get_slist_impl
+ <typename reduced_slist_node_traits
+ <node_traits>::type
+ >::type type;
+};
+
+template<class SupposedValueTraits>
+struct unordered_bucket_impl
+{
+ /// @cond
+ typedef typename
+ get_slist_impl_from_supposed_value_traits
+ <SupposedValueTraits>::type slist_impl;
+ typedef detail::bucket_impl<slist_impl> implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+template<class SupposedValueTraits>
+struct unordered_bucket_ptr_impl
+{
+ /// @cond
+ typedef typename detail::get_node_traits
+ <SupposedValueTraits>::type::node_ptr node_ptr;
+ typedef typename unordered_bucket_impl
+ <SupposedValueTraits>::type bucket_type;
+ typedef typename boost::pointer_to_other
+ <node_ptr, bucket_type>::type implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+template <class T>
+struct store_hash_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::store_hash>
+ test (detail::bool_<U::store_hash>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct store_hash_is_true
+{
+ static const bool value = store_hash_bool<T>::value > sizeof(one)*2;
+};
+
+template <class T>
+struct optimize_multikey_bool
+{
+ template<bool Add>
+ struct two_or_three {one _[2 + Add];};
+ template <class U> static one test(...);
+ template <class U> static two_or_three<U::optimize_multikey>
+ test (detail::bool_<U::optimize_multikey>* = 0);
+ static const std::size_t value = sizeof(test<T>(0));
+};
+
+template <class T>
+struct optimize_multikey_is_true
+{
+ static const bool value = optimize_multikey_bool<T>::value > sizeof(one)*2;
+};
+
+template<class Config>
+struct bucket_plus_size
+ : public detail::size_holder
+ < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos)
+ , typename Config::size_type>
+{
+ typedef detail::size_holder
+ < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos)
+ , typename Config::size_type> size_traits;
+ typedef typename Config::bucket_traits bucket_traits;
+
+ bucket_plus_size(const bucket_traits &b_traits)
+ : bucket_traits_(b_traits)
+ {}
+ bucket_traits bucket_traits_;
+};
+
+template<class Config>
+struct bucket_hash_t
+ : public detail::ebo_functor_holder<typename Config::hash>
+{
+ typedef typename Config::hash hasher;
+ typedef detail::size_holder
+ < 0 != (Config::bool_flags & hash_bool_flags::constant_time_size_pos)
+ , typename Config::size_type> size_traits;
+ typedef typename Config::bucket_traits bucket_traits;
+
+ bucket_hash_t(const bucket_traits &b_traits, const hasher & h)
+ : detail::ebo_functor_holder<hasher>(h), bucket_plus_size_(b_traits)
+ {}
+
+ bucket_plus_size<Config> bucket_plus_size_;
+};
+
+template<class Config, bool>
+struct bucket_hash_equal_t : public detail::ebo_functor_holder<typename Config::equal>
+{
+ typedef typename Config::equal equal;
+ typedef typename Config::hash hasher;
+ typedef typename Config::bucket_traits bucket_traits;
+
+ bucket_hash_equal_t(const bucket_traits &b_traits, const hasher & h, const equal &e)
+ : detail::ebo_functor_holder<typename Config::equal>(e), bucket_hash(b_traits, h)
+ {}
+ bucket_hash_t<Config> bucket_hash;
+};
+
+template<class Config> //cache_begin == true version
+struct bucket_hash_equal_t<Config, true>
+ : public detail::ebo_functor_holder<typename Config::equal>
+{
+ typedef typename Config::equal equal;
+ typedef typename Config::hash hasher;
+ typedef typename Config::bucket_traits bucket_traits;
+ typedef typename unordered_bucket_ptr_impl
+ <typename Config::value_traits>::type bucket_ptr;
+
+ bucket_hash_equal_t(const bucket_traits &b_traits, const hasher & h, const equal &e)
+ : detail::ebo_functor_holder<typename Config::equal>(e), bucket_hash(b_traits, h)
+ {}
+ bucket_hash_t<Config> bucket_hash;
+ bucket_ptr cached_begin_;
+};
+
+template<class Config>
+struct hashtable_data_t : public Config::value_traits
+{
+ static const std::size_t bool_flags = Config::bool_flags;
+ typedef typename Config::value_traits value_traits;
+ typedef typename Config::equal equal;
+ typedef typename Config::hash hasher;
+ typedef typename Config::bucket_traits bucket_traits;
+
+ hashtable_data_t( const bucket_traits &b_traits, const hasher & h
+ , const equal &e, const value_traits &val_traits)
+ : Config::value_traits(val_traits), internal_(b_traits, h, e)
+ {}
+ typedef typename detail::usetopt_mask
+ < Config
+ , detail::hash_bool_flags::constant_time_size_pos
+ | detail::hash_bool_flags::incremental_pos
+ >::type masked_config_t;
+ struct internal
+ : public detail::size_holder
+ < 0 != (Config::bool_flags & hash_bool_flags::incremental_pos)
+ , typename Config::size_type>
+ {
+ internal(const bucket_traits &b_traits, const hasher & h, const equal &e)
+ : bucket_hash_equal_(b_traits, h, e)
+ {}
+
+ bucket_hash_equal_t
+ < masked_config_t
+ , 0 != (bool_flags & hash_bool_flags::cache_begin_pos)
+ > bucket_hash_equal_;
+ } internal_;
+};
+
+struct insert_commit_data_impl
+{
+ std::size_t hash;
+};
+
+template<class NodeTraits>
+struct group_functions
+{
+ typedef NodeTraits node_traits;
+ typedef unordered_group_adapter<node_traits> group_traits;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::node node;
+ typedef typename reduced_slist_node_traits
+ <node_traits>::type reduced_node_traits;
+ typedef typename reduced_node_traits::node_ptr slist_node_ptr;
+ typedef typename reduced_node_traits::node slist_node;
+ typedef circular_slist_algorithms<group_traits> group_algorithms;
+
+ static node_ptr dcast_bucket_ptr(slist_node_ptr p)
+ { return node_ptr(&static_cast<node&>(*p)); }
+
+ static slist_node_ptr priv_get_bucket_before_begin
+ (slist_node_ptr bucket_beg, slist_node_ptr bucket_end, node_ptr p)
+ {
+ //First find the last node of p's group.
+ //This requires checking the first node of the next group or
+ //the bucket node.
+ node_ptr prev_node = p;
+ node_ptr nxt(node_traits::get_next(p));
+ while(!(bucket_beg <= nxt && nxt <= bucket_end) &&
+ (group_traits::get_next(nxt) == prev_node)){
+ prev_node = nxt;
+ nxt = node_traits::get_next(nxt);
+ }
+
+ //If we've reached the bucket node just return it.
+ if(bucket_beg <= nxt && nxt <= bucket_end){
+ return nxt;
+ }
+
+ //Otherwise, iterate using group links until the bucket node
+ node_ptr first_node_of_group = nxt;
+ node_ptr last_node_group = group_traits::get_next(first_node_of_group);
+ slist_node_ptr possible_end = node_traits::get_next(last_node_group);
+
+ while(!(bucket_beg <= possible_end && possible_end <= bucket_end)){
+ first_node_of_group = dcast_bucket_ptr(possible_end);
+ last_node_group = group_traits::get_next(first_node_of_group);
+ possible_end = node_traits::get_next(last_node_group);
+ }
+ return possible_end;
+ }
+
+ static node_ptr priv_get_prev_to_first_in_group(slist_node_ptr bucket_node, node_ptr first_in_group)
+ {
+ //Just iterate using group links and obtain the node
+ //before "first_in_group)"
+ node_ptr prev_node = dcast_bucket_ptr(bucket_node);
+ node_ptr nxt(node_traits::get_next(prev_node));
+ while(nxt != first_in_group){
+ prev_node = group_traits::get_next(nxt);
+ nxt = node_traits::get_next(prev_node);
+ }
+ return prev_node;
+ }
+
+ static node_ptr priv_get_first_in_group_of_last_in_group(node_ptr last_in_group)
+ {
+ //Just iterate using group links and obtain the node
+ //before "last_in_group"
+ node_ptr possible_first = group_traits::get_next(last_in_group);
+ node_ptr possible_first_prev = group_traits::get_next(possible_first);
+ // The deleted node is at the end of the group, so the
+ // node in the group pointing to it is at the beginning
+ // of the group. Find that to change its pointer.
+ while(possible_first_prev != last_in_group){
+ possible_first = possible_first_prev;
+ possible_first_prev = group_traits::get_next(possible_first);
+ }
+ return possible_first;
+ }
+
+
+ static void priv_erase_from_group(slist_node_ptr end_ptr, node_ptr to_erase_ptr, detail::true_)
+ {
+ node_ptr nxt_ptr(node_traits::get_next(to_erase_ptr));
+ node_ptr prev_in_group_ptr(group_traits::get_next(to_erase_ptr));
+ bool last_in_group = (end_ptr == nxt_ptr) ||
+ (group_traits::get_next(nxt_ptr) != to_erase_ptr);
+ bool first_in_group = node_traits::get_next(prev_in_group_ptr) != to_erase_ptr;
+
+ if(first_in_group && last_in_group){
+ group_algorithms::init(to_erase_ptr);
+ }
+ else if(first_in_group){
+ group_algorithms::unlink_after(nxt_ptr);
+ }
+ else if(last_in_group){
+ node_ptr first_in_group =
+ priv_get_first_in_group_of_last_in_group(to_erase_ptr);
+ group_algorithms::unlink_after(first_in_group);
+ }
+ else{
+ group_algorithms::unlink_after(nxt_ptr);
+ }
+ }
+
+ static void priv_erase_from_group(slist_node_ptr, node_ptr, detail::false_)
+ {}
+
+ static node_ptr priv_get_last_in_group(node_ptr first_in_group, detail::true_)
+ { return group_traits::get_next(first_in_group); }
+
+ static node_ptr priv_get_last_in_group(node_ptr n, detail::false_)
+ { return n; }
+};
+
+template<class BucketType, class SplitTraits>
+class incremental_rehash_rollback
+{
+ private:
+ typedef BucketType bucket_type;
+ typedef SplitTraits split_traits;
+
+ incremental_rehash_rollback();
+ incremental_rehash_rollback & operator=(const incremental_rehash_rollback &);
+ incremental_rehash_rollback (const incremental_rehash_rollback &);
+
+ public:
+ incremental_rehash_rollback
+ (bucket_type &source_bucket, bucket_type &destiny_bucket, split_traits &split_traits)
+ : source_bucket_(source_bucket), destiny_bucket_(destiny_bucket)
+ , split_traits_(split_traits), released_(false)
+ {}
+
+ void release()
+ { released_ = true; }
+
+ ~incremental_rehash_rollback()
+ {
+ if(!released_){
+ //If an exception is thrown, just put all moved nodes back in the old bucket
+ //and move back the split mark.
+ destiny_bucket_.splice_after(destiny_bucket_.before_begin(), source_bucket_);
+ split_traits_.decrement();
+ }
+ }
+
+ private:
+ bucket_type &source_bucket_;
+ bucket_type &destiny_bucket_;
+ split_traits &split_traits_;
+ bool released_;
+};
+
+} //namespace detail {
+
+//!This metafunction will obtain the type of a bucket
+//!from the value_traits or hook option to be used with
+//!a hash container.
+template<class ValueTraitsOrHookOption>
+struct unordered_bucket
+ : public detail::unordered_bucket_impl
+ <typename ValueTraitsOrHookOption::
+ template pack<none>::value_traits
+ >
+{};
+
+//!This metafunction will obtain the type of a bucket pointer
+//!from the value_traits or hook option to be used with
+//!a hash container.
+template<class ValueTraitsOrHookOption>
+struct unordered_bucket_ptr
+ : public detail::unordered_bucket_ptr_impl
+ <typename ValueTraitsOrHookOption::
+ template pack<none>::value_traits
+ >
+{};
+
+//!This metafunction will obtain the type of the default bucket traits
+//!(when the user does not specify the bucket_traits<> option) from the
+//!value_traits or hook option to be used with
+//!a hash container.
+template<class ValueTraitsOrHookOption>
+struct unordered_default_bucket_traits
+{
+ /// @cond
+ typedef typename ValueTraitsOrHookOption::
+ template pack<none>::value_traits supposed_value_traits;
+ typedef typename detail::
+ get_slist_impl_from_supposed_value_traits
+ <supposed_value_traits>::type slist_impl;
+ typedef detail::bucket_traits_impl
+ <slist_impl> implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+struct default_bucket_traits;
+
+template <class T>
+struct uset_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_uset_hook>
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ , equal<std::equal_to<T> >
+ , hash<boost::hash<T> >
+ , bucket_traits<default_bucket_traits>
+ , power_2_buckets<false>
+ , cache_begin<false>
+ , compare_hash<false>
+ , incremental<false>
+ >::type
+{};
+
+/// @endcond
+
+//! The class template hashtable is an intrusive hash table container, that
+//! is used to construct intrusive unordered_set and unordered_multiset containers. The
+//! no-throw guarantee holds only, if the Equal object and Hasher don't throw.
+//!
+//! hashtable is a semi-intrusive container: each object to be stored in the
+//! container must contain a proper hook, but the container also needs
+//! additional auxiliary memory to work: hashtable needs a pointer to an array
+//! of type `bucket_type` to be passed in the constructor. This bucket array must
+//! have at least the same lifetime as the container. This makes the use of
+//! hashtable more complicated than purely intrusive containers.
+//! `bucket_type` is default-constructible, copyable and assignable
+//!
+//! 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<>, \c hash<> and \c equal<>
+//! \c bucket_traits<>, power_2_buckets<>, cache_begin<> and incremental<>.
+//!
+//! hashtable only provides forward iterators but it provides 4 iterator types:
+//! iterator and const_iterator to navigate through the whole container and
+//! local_iterator and const_local_iterator to navigate through the values
+//! stored in a single bucket. Local iterators are faster and smaller.
+//!
+//! It's not recommended to use non constant-time size hashtables because several
+//! key functions, like "empty()", become non-constant time functions. Non
+//! constant_time size hashtables are mainly provided to support auto-unlink hooks.
+//!
+//! hashtables, does not make automatic rehashings nor
+//! offers functions related to a load factor. Rehashing can be explicitly requested
+//! and the user must provide a new bucket array that will be used from that moment.
+//!
+//! Since no automatic rehashing is done, iterators are never invalidated when
+//! inserting or erasing elements. Iterators are only invalidated when rehashing.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class hashtable_impl
+ : private detail::clear_on_destructor_base<hashtable_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ public:
+ typedef typename Config::value_traits value_traits;
+
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ typedef typename Config::bucket_traits bucket_traits;
+ static const bool external_bucket_traits =
+ detail::external_bucket_traits_is_true<bucket_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_bucket_traits
+ , detail::eval_bucket_traits<bucket_traits>
+ , detail::identity<bucket_traits>
+ >::type real_bucket_traits;
+ typedef typename detail::get_slist_impl
+ <typename detail::reduced_slist_node_traits
+ <typename real_value_traits::node_traits>::type
+ >::type slist_impl;
+ /// @endcond
+
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+ typedef typename Config::size_type size_type;
+ typedef value_type key_type;
+ typedef typename Config::equal key_equal;
+ typedef typename Config::hash hasher;
+ typedef detail::bucket_impl<slist_impl> bucket_type;
+ typedef typename boost::pointer_to_other
+ <pointer, bucket_type>::type bucket_ptr;
+ typedef typename slist_impl::iterator siterator;
+ typedef typename slist_impl::const_iterator const_siterator;
+ typedef detail::hashtable_iterator<hashtable_impl, false> iterator;
+ typedef detail::hashtable_iterator<hashtable_impl, true> const_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef typename slist_impl::node_algorithms node_algorithms;
+
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<hashtable_impl>::value;
+ static const bool store_hash = detail::store_hash_is_true<node_traits>::value;
+
+ static const bool unique_keys = 0 != (Config::bool_flags & detail::hash_bool_flags::unique_keys_pos);
+ static const bool constant_time_size = 0 != (Config::bool_flags & detail::hash_bool_flags::constant_time_size_pos);
+ static const bool cache_begin = 0 != (Config::bool_flags & detail::hash_bool_flags::cache_begin_pos);
+ static const bool compare_hash = 0 != (Config::bool_flags & detail::hash_bool_flags::compare_hash_pos);
+ static const bool incremental = 0 != (Config::bool_flags & detail::hash_bool_flags::incremental_pos);
+ static const bool power_2_buckets = incremental || (0 != (Config::bool_flags & detail::hash_bool_flags::power_2_buckets_pos));
+
+ static const bool optimize_multikey
+ = detail::optimize_multikey_is_true<node_traits>::value && !unique_keys;
+
+ /// @cond
+ private:
+
+ //Configuration error: compare_hash<> can't be specified without store_hash<>
+ //See documentation for more explanations
+ BOOST_STATIC_ASSERT((!compare_hash || store_hash));
+
+ typedef typename slist_impl::node_ptr slist_node_ptr;
+ typedef typename boost::pointer_to_other
+ <slist_node_ptr, void>::type void_pointer;
+ //We'll define group traits, but these won't be instantiated if
+ //optimize_multikey is not true
+ typedef unordered_group_adapter<node_traits> group_traits;
+ typedef circular_slist_algorithms<group_traits> group_algorithms;
+ typedef detail::bool_<store_hash> store_hash_t;
+ typedef detail::bool_<optimize_multikey> optimize_multikey_t;
+ typedef detail::bool_<cache_begin> cache_begin_t;
+ typedef detail::bool_<power_2_buckets> power_2_buckets_t;
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+ typedef detail::size_holder<incremental, size_type> split_traits;
+ typedef detail::group_functions<node_traits> group_functions_t;
+
+ static const std::size_t hashtable_data_bool_flags_mask =
+ ( detail::hash_bool_flags::cache_begin_pos
+ | detail::hash_bool_flags::constant_time_size_pos
+ | detail::hash_bool_flags::incremental_pos
+ );
+ typedef typename detail::usetopt_mask
+ <Config, hashtable_data_bool_flags_mask>::type masked_config_t;
+ detail::hashtable_data_t<masked_config_t> data_;
+
+ template<bool IsConst>
+ struct downcast_node_to_value
+ : public detail::node_to_value<hashtable_impl, IsConst>
+ {
+ typedef detail::node_to_value<hashtable_impl, IsConst> base_t;
+ typedef typename base_t::result_type result_type;
+ typedef typename detail::add_const_if_c
+ <typename slist_impl::node, IsConst>::type &first_argument_type;
+ typedef typename detail::add_const_if_c
+ <node, IsConst>::type &intermediate_argument_type;
+
+ downcast_node_to_value(const hashtable_impl *cont)
+ : base_t(cont)
+ {}
+
+ result_type operator()(first_argument_type arg) const
+ { return this->base_t::operator()(static_cast<intermediate_argument_type>(arg)); }
+ };
+
+ template<class F>
+ struct node_cast_adaptor
+ : private detail::ebo_functor_holder<F>
+ {
+ typedef detail::ebo_functor_holder<F> base_t;
+
+ template<class ConvertibleToF>
+ node_cast_adaptor(const ConvertibleToF &c2f, const hashtable_impl *cont)
+ : base_t(base_t(c2f, cont))
+ {}
+
+ typename base_t::node_ptr operator()(const typename slist_impl::node &to_clone)
+ { return base_t::operator()(static_cast<const node &>(to_clone)); }
+
+ void operator()(typename slist_impl::node_ptr to_clone)
+ { base_t::operator()(node_ptr(&static_cast<node &>(*to_clone))); }
+ };
+
+ private:
+ //noncopyable
+ hashtable_impl (const hashtable_impl&);
+ hashtable_impl operator =(const hashtable_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+ //Cache begin is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(cache_begin && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ template<class Disposer>
+ node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> >
+ make_node_disposer(const Disposer &disposer) const
+ { return node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> >(disposer, this); }
+
+ /// @endcond
+
+ public:
+ typedef detail::insert_commit_data_impl insert_commit_data;
+
+ typedef detail::transform_iterator
+ < typename slist_impl::iterator
+ , downcast_node_to_value<false> > local_iterator;
+
+ typedef detail::transform_iterator
+ < typename slist_impl::iterator
+ , downcast_node_to_value<true> > const_local_iterator;
+
+ /// @cond
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return this->data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return this->data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ //! <b>Requires</b>: buckets must not be being used by any other resource.
+ //!
+ //! <b>Effects</b>: Constructs an empty unordered_set, storing a reference
+ //! to the bucket array and copies of the key_hasher and equal_func functors.
+ //!
+ //! <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 or invocation of hash_func or equal_func throws.
+ //!
+ //! <b>Notes</b>: buckets array must be disposed only after
+ //! *this is disposed.
+ hashtable_impl ( const bucket_traits &b_traits
+ , const hasher & hash_func = hasher()
+ , const key_equal &equal_func = key_equal()
+ , const value_traits &v_traits = value_traits())
+ : data_(b_traits, hash_func, equal_func, v_traits)
+ {
+ priv_initialize_buckets();
+ this->priv_size_traits().set_size(size_type(0));
+ size_type bucket_size = this->priv_buckets_len();
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(bucket_size != 0);
+ //Check power of two bucket array if the option is activated
+ BOOST_INTRUSIVE_INVARIANT_ASSERT
+ (!power_2_buckets || (0 == (bucket_size & (bucket_size-1))));
+ priv_split_traits().set_size(bucket_size>>1);
+ }
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the unordered_set, if
+ //! it's a safe-mode or auto-unlink value. Otherwise constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~hashtable_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //! Worst case (empty unordered_set): O(this->bucket_count())
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return iterator(this->priv_begin(), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
+ //! of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //! Worst case (empty unordered_set): O(this->bucket_count())
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return this->cbegin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
+ //! of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //! Worst case (empty unordered_set): O(this->bucket_count())
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return const_iterator(this->priv_begin(), this); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return iterator(priv_invalid_local_it(), 0); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return this->cend(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return const_iterator(priv_invalid_local_it(), 0); }
+
+ //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If hasher copy-constructor throws.
+ hasher hash_function() const
+ { return this->priv_hasher(); }
+
+ //! <b>Effects</b>: Returns the key_equal object used by the unordered_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_equal copy-constructor throws.
+ key_equal key_eq() const
+ { return this->priv_equal(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: if constant-time size and cache_begin options are disabled,
+ //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
+ //! Otherwise constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ {
+ if(constant_time_size){
+ return !this->size();
+ }
+ else if(cache_begin){
+ return this->begin() == this->end();
+ }
+ else{
+ size_type buckets_len = this->priv_buckets_len();
+ const bucket_type *b = detail::get_pointer(this->priv_buckets());
+ for (size_type n = 0; n < buckets_len; ++n, ++b){
+ if(!b->empty()){
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the unordered_set.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if
+ //! constant_time_size is false. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ {
+ if(constant_time_size)
+ return this->priv_size_traits().get_size();
+ else{
+ size_type len = 0;
+ size_type buckets_len = this->priv_buckets_len();
+ const bucket_type *b = detail::get_pointer(this->priv_buckets());
+ for (size_type n = 0; n < buckets_len; ++n, ++b){
+ len += b->size();
+ }
+ return len;
+ }
+ }
+
+ //! <b>Requires</b>: the hasher and the equality function unqualified swap
+ //! call should not throw.
+ //!
+ //! <b>Effects</b>: Swaps the contents of two unordered_sets.
+ //! Swaps also the contained bucket array and equality and hasher functors.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison or hash functors
+ //! found using ADL throw. Basic guarantee.
+ void swap(hashtable_impl& other)
+ {
+ using std::swap;
+ //These can throw
+ swap(this->priv_equal(), other.priv_equal());
+ swap(this->priv_hasher(), other.priv_hasher());
+ //These can't throw
+ swap(this->priv_real_bucket_traits(), other.priv_real_bucket_traits());
+ priv_swap_cache(cache_begin_t(), other);
+ if(constant_time_size){
+ size_type backup = this->priv_size_traits().get_size();
+ this->priv_size_traits().set_size(other.priv_size_traits().get_size());
+ other.priv_size_traits().set_size(backup);
+ }
+ else if(incremental){
+ size_type backup = this->priv_split_traits().get_size();
+ this->priv_split_traits().set_size(other.priv_split_traits().get_size());
+ other.priv_split_traits().set_size(backup);
+ }
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw
+ //! Cloner should yield to nodes that compare equal and produce the same
+ //! hash than the original node.
+ //!
+ //! <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. The hash function and the equality
+ //! predicate are copied from the source.
+ //!
+ //! If store_hash option is true, this method does not use the hash function.
+ //!
+ //! If any operation 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 or hasher throw or hash or equality predicate copying
+ //! throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const hashtable_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!constant_time_size || !src.empty()){
+ const size_type src_bucket_count = src.bucket_count();
+ const size_type dst_bucket_count = this->bucket_count();
+ //Check power of two bucket array if the option is activated
+ BOOST_INTRUSIVE_INVARIANT_ASSERT
+ (!power_2_buckets || (0 == (src_bucket_count & (src_bucket_count-1))));
+ BOOST_INTRUSIVE_INVARIANT_ASSERT
+ (!power_2_buckets || (0 == (dst_bucket_count & (dst_bucket_count-1))));
+
+ //If src bucket count is bigger or equal, structural copy is possible
+ if(!incremental && (src_bucket_count >= dst_bucket_count)){
+ //First clone the first ones
+ const bucket_ptr src_buckets = src.priv_buckets();
+ const bucket_ptr dst_buckets = this->priv_buckets();
+ size_type constructed;
+ typedef node_cast_adaptor<detail::node_disposer<Disposer, hashtable_impl> > NodeDisposer;
+ typedef node_cast_adaptor<detail::node_cloner<Cloner, hashtable_impl> > NodeCloner;
+ NodeDisposer node_disp(disposer, this);
+
+ detail::exception_array_disposer<bucket_type, NodeDisposer>
+ rollback(dst_buckets[0], node_disp, constructed);
+ for( constructed = 0
+ ; constructed < dst_bucket_count
+ ; ++constructed){
+ dst_buckets[constructed].clone_from
+ ( src_buckets[constructed]
+ , NodeCloner(cloner, this), node_disp);
+ }
+ if(src_bucket_count != dst_bucket_count){
+ //Now insert the remaining ones using the modulo trick
+ for(//"constructed" comes from the previous loop
+ ; constructed < src_bucket_count
+ ; ++constructed){
+ bucket_type &dst_b =
+ dst_buckets[priv_hash_to_bucket(constructed, dst_bucket_count, dst_bucket_count)];
+ bucket_type &src_b = src_buckets[constructed];
+ for( siterator b(src_b.begin()), e(src_b.end())
+ ; b != e
+ ; ++b){
+ dst_b.push_front(*(NodeCloner(cloner, this)(*b.pointed_node())));
+ }
+ }
+ }
+ this->priv_hasher() = src.priv_hasher();
+ this->priv_equal() = src.priv_equal();
+ rollback.release();
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ this->priv_split_traits().set_size(dst_bucket_count);
+ priv_insertion_update_cache(0u);
+ priv_erasure_update_cache();
+ }
+ else if(store_hash){
+ //Unlike previous cloning algorithm, this can throw
+ //if cloner, hasher or comparison functor throw
+ const_iterator b(src.begin()), e(src.end());
+ detail::exception_disposer<hashtable_impl, Disposer>
+ rollback(*this, disposer);
+ for(; b != e; ++b){
+ std::size_t hash_value = this->priv_stored_or_compute_hash(*b, store_hash_t());;
+ this->priv_insert_equal_with_hash(*cloner(*b), hash_value);
+ }
+ rollback.release();
+ }
+ else{
+ //Unlike previous cloning algorithm, this can throw
+ //if cloner, hasher or comparison functor throw
+ const_iterator b(src.begin()), e(src.end());
+ detail::exception_disposer<hashtable_impl, Disposer>
+ rollback(*this, disposer);
+ for(; b != e; ++b){
+ this->insert_equal(*cloner(*b));
+ }
+ rollback.release();
+ }
+ }
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts the value into the unordered_set.
+ //!
+ //! <b>Returns</b>: An iterator to the inserted value.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor 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)
+ {
+ size_type bucket_num;
+ std::size_t hash_value;
+ siterator prev;
+ siterator it = this->priv_find
+ (value, this->priv_hasher(), this->priv_equal(), bucket_num, hash_value, prev);
+ return priv_insert_equal_find(value, bucket_num, hash_value, it);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Equivalent to this->insert_equal(t) for each element in [b, e).
+ //!
+ //! <b>Complexity</b>: Average case O(N), where N is std::distance(b, e).
+ //! Worst case O(N*this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
+ //!
+ //! <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)
+ {
+ for (; b != e; ++b)
+ this->insert_equal(*b);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to inserts value into the unordered_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 case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
+ //!
+ //! <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->priv_hasher(), this->priv_equal(), commit_data);
+ if(!ret.second)
+ return ret;
+ return std::pair<iterator, bool>
+ (this->insert_unique_commit(value, commit_data), true);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Equivalent to this->insert_unique(t) for each element in [b, e).
+ //!
+ //! <b>Complexity</b>: Average case O(N), where N is std::distance(b, e).
+ //! Worst case O(N*this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
+ //!
+ //! <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)
+ {
+ for (; b != e; ++b)
+ this->insert_unique(*b);
+ }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the unordered_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 case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal_func throw. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the hash or the equality is much cheaper to
+ //! construct than the value_type and this function offers the possibility to
+ //! use that the 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.
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the unordered_set.
+ //!
+ //! After a successful rehashing insert_commit_data remains valid.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ std::pair<iterator, bool> insert_unique_check
+ ( const KeyType &key
+ , KeyHasher hash_func
+ , KeyValueEqual equal_func
+ , insert_commit_data &commit_data)
+ {
+ size_type bucket_num;
+ siterator prev;
+ siterator prev_pos =
+ this->priv_find(key, hash_func, equal_func, bucket_num, commit_data.hash, prev);
+ bool success = prev_pos == priv_invalid_local_it();
+ if(success){
+ prev_pos = prev;
+ }
+ return std::pair<iterator, bool>(iterator(prev_pos, this),success);
+ }
+
+ //! <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 unordered_set between
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
+ //!
+ //! <b>Effects</b>: Inserts the value in the unordered_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.
+ //!
+ //! After a successful rehashing insert_commit_data remains valid.
+ iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
+ {
+ size_type bucket_num = priv_hash_to_bucket(commit_data.hash);
+ bucket_type &b = this->priv_buckets()[bucket_num];
+ this->priv_size_traits().increment();
+ node_ptr n = node_ptr(&priv_value_to_node(value));
+ this->priv_store_hash(n, commit_data.hash, store_hash_t());
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
+ priv_insertion_update_cache(bucket_num);
+ this->priv_insert_in_group(node_ptr(0), n, optimize_multikey_t());
+ return iterator(b.insert_after(b.before_begin(), *n), this);
+ }
+
+ //! <b>Effects</b>: Erases the element pointed to by i.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased element. No destructors are called.
+ void erase(const_iterator i)
+ { this->erase_and_dispose(i, detail::null_disposer()); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average case O(std::distance(b, e)),
+ //! worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ void erase(const_iterator b, const_iterator e)
+ { this->erase_and_dispose(b, e, detail::null_disposer()); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(value)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor 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 this->erase(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Erases all the elements that have the same hash and
+ //! compare equal with the given key.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(value)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
+ { return this->erase_and_dispose(key, hash_func, equal_func, detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the element pointed to by i.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ void erase_and_dispose(const_iterator i, Disposer disposer)
+ {
+ priv_erase(i, disposer, optimize_multikey_t());
+ this->priv_size_traits().decrement();
+ priv_erasure_update_cache();
+ }
+
+ #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 the range pointed to by b end e.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Complexity</b>: Average case O(std::distance(b, e)),
+ //! worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
+ {
+ if(b == e) return;
+
+ //Get the bucket number and local iterator for both iterators
+ siterator first_local_it(b.slist_it());
+ size_type first_bucket_num = this->priv_get_bucket_num(first_local_it);
+
+ siterator before_first_local_it
+ = priv_get_previous(priv_buckets()[first_bucket_num], first_local_it);
+ size_type last_bucket_num;
+ siterator last_local_it;
+
+ //For the end iterator, we will assign the end iterator
+ //of the last bucket
+ if(e == this->end()){
+ last_bucket_num = this->bucket_count() - 1;
+ last_local_it = priv_buckets()[last_bucket_num].end();
+ }
+ else{
+ last_local_it = e.slist_it();
+ last_bucket_num = this->priv_get_bucket_num(last_local_it);
+ }
+ priv_erase_range(before_first_local_it, first_bucket_num, last_local_it, last_bucket_num, disposer);
+ priv_erasure_update_cache(first_bucket_num, last_bucket_num);
+ }
+
+ //! <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>: Average case O(this->count(value)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ //! Basic guarantee.
+ //!
+ //! <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)
+ { return this->erase_and_dispose(value, priv_hasher(), priv_equal(), 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 "equal_func".
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(value)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer>
+ size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func
+ ,KeyValueEqual equal_func, Disposer disposer)
+ {
+ size_type bucket_num;
+ std::size_t h;
+ siterator prev;
+ siterator it =
+ this->priv_find(key, hash_func, equal_func, bucket_num, h, prev);
+ bool success = it != priv_invalid_local_it();
+ size_type count(0);
+ if(!success){
+ return 0;
+ }
+ else if(optimize_multikey){
+ siterator last = bucket_type::s_iterator_to
+ (*node_traits::get_next(group_functions_t::priv_get_last_in_group
+ (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t())));
+ this->priv_erase_range_impl(bucket_num, prev, last, disposer, count);
+ }
+ else{
+ //If found erase all equal values
+ bucket_type &b = this->priv_buckets()[bucket_num];
+ for(siterator end = b.end(); it != end; ++count, ++it){
+ slist_node_ptr n(it.pointed_node());
+ const value_type &v = priv_value_from_slist_node(n);
+ if(compare_hash){
+ std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t());
+ if(h != vh || !equal_func(key, v)){
+ break;
+ }
+ }
+ else if(!equal_func(key, v)){
+ break;
+ }
+ this->priv_size_traits().decrement();
+ }
+ b.erase_after_and_dispose(prev, it, make_node_disposer(disposer));
+ }
+ priv_erasure_update_cache();
+ return count;
+ }
+
+ //! <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()
+ {
+ priv_clear_buckets();
+ this->priv_size_traits().set_size(size_type(0));
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all of the elements.
+ //!
+ //! <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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ if(!constant_time_size || !this->empty()){
+ size_type num_buckets = this->bucket_count();
+ bucket_ptr b = this->priv_buckets();
+ for(; num_buckets--; ++b){
+ b->clear_and_dispose(make_node_disposer(disposer));
+ }
+ this->priv_size_traits().set_size(size_type(0));
+ }
+ priv_initialize_cache();
+ }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given value
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ size_type count(const_reference value) const
+ { return this->count(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal throw.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ size_type count(const KeyType &key, const KeyHasher &hash_func, const KeyValueEqual &equal_func) const
+ {
+ size_type bucket_n1, bucket_n2, count;
+ this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count);
+ return count;
+ }
+
+ //! <b>Effects</b>: Finds an iterator to the first element is equal to
+ //! "value" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ iterator find(const_reference value)
+ { return this->find(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! "key" according to the given hash and equality functor or end() if
+ //! that element does not exist.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal_func throw.
+ //!
+ //! <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.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ iterator find(const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func)
+ {
+ size_type bucket_n;
+ std::size_t hash;
+ siterator prev;
+ siterator local_it = this->priv_find(key, hash_func, equal_func, bucket_n, hash, prev);
+ return iterator(local_it, this);
+ }
+
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
+ //! "key" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ const_iterator find(const_reference value) const
+ { return this->find(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! "key" according to the given hasher and equality functor or end() if
+ //! that element does not exist.
+ //!
+ //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or equal_func throw.
+ //!
+ //! <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.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ const_iterator find
+ (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const
+ {
+ size_type bucket_n;
+ std::size_t hash_value;
+ siterator prev;
+ siterator sit = this->priv_find(key, hash_func, equal_func, bucket_n, hash_value, prev);
+ return const_iterator(sit, this);
+ }
+
+ //! <b>Effects</b>: Returns a range containing all elements with values equivalent
+ //! to value. Returns std::make_pair(this->end(), this->end()) if no such
+ //! elements exist.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ std::pair<iterator,iterator> equal_range(const_reference value)
+ { return this->equal_range(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Returns a range containing all elements with equivalent
+ //! keys. Returns std::make_pair(this->end(), this->end()) if no such
+ //! elements exist.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If hash_func or the equal_func throw.
+ //!
+ //! <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.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ std::pair<iterator,iterator> equal_range
+ (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func)
+ {
+ size_type bucket_n1, bucket_n2, count;
+ std::pair<siterator, siterator> ret = this->priv_equal_range
+ (key, hash_func, equal_func, bucket_n1, bucket_n2, count);
+ return std::pair<iterator, iterator>
+ (iterator(ret.first, this), iterator(ret.second, this));
+ }
+
+ //! <b>Effects</b>: Returns a range containing all elements with values equivalent
+ //! to value. Returns std::make_pair(this->end(), this->end()) if no such
+ //! elements exist.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the internal hasher or the equality functor throws.
+ std::pair<const_iterator, const_iterator>
+ equal_range(const_reference value) const
+ { return this->equal_range(value, this->priv_hasher(), this->priv_equal()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! "equal_func" must be a equality function that induces
+ //! the same equality as key_equal. The difference is that
+ //! "equal_func" compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Returns a range containing all elements with equivalent
+ //! keys. Returns std::make_pair(this->end(), this->end()) if no such
+ //! elements exist.
+ //!
+ //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
+ //! Worst case O(this->size()).
+ //!
+ //! <b>Throws</b>: If the hasher or equal_func throw.
+ //!
+ //! <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.
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ std::pair<const_iterator,const_iterator> equal_range
+ (const KeyType &key, KeyHasher hash_func, KeyValueEqual equal_func) const
+ {
+ size_type bucket_n1, bucket_n2, count;
+ std::pair<siterator, siterator> ret =
+ this->priv_equal_range(key, hash_func, equal_func, bucket_n1, bucket_n2, count);
+ return std::pair<const_iterator, const_iterator>
+ (const_iterator(ret.first, this), const_iterator(ret.second, this));
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the internal hash function throws.
+ iterator iterator_to(reference value)
+ {
+ return iterator(bucket_type::s_iterator_to(priv_value_to_node(value)), this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
+ //! unordered_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the internal hash function throws.
+ const_iterator iterator_to(const_reference value) const
+ {
+ return const_iterator(bucket_type::s_iterator_to(priv_value_to_node(const_cast<reference>(value))), this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_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 local_iterator s_local_iterator_to(reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(value));
+ return local_iterator(sit, (hashtable_impl*)0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
+ //! the unordered_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_local_iterator s_local_iterator_to(const_reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ siterator sit = bucket_type::s_iterator_to(((hashtable_impl*)0)->priv_value_to_node(const_cast<value_type&>(value)));
+ return const_local_iterator(sit, (hashtable_impl*)0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ local_iterator local_iterator_to(reference value)
+ {
+ siterator sit = bucket_type::s_iterator_to(this->priv_value_to_node(value));
+ return local_iterator(sit, this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
+ //! the unordered_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_local_iterator local_iterator_to(const_reference value) const
+ {
+ siterator sit = bucket_type::s_iterator_to
+ (const_cast<node &>(this->priv_value_to_node(value)));
+ return const_local_iterator(sit, this);
+ }
+
+ //! <b>Effects</b>: Returns the number of buckets passed in the constructor
+ //! or the last rehash function.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type bucket_count() const
+ { return this->priv_buckets_len(); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns the number of elements in the nth bucket.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type bucket_size(size_type n) const
+ { return this->priv_buckets()[n].size(); }
+
+ //! <b>Effects</b>: Returns the index of the bucket in which elements
+ //! with keys equivalent to k would be found, if any such element existed.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the hash functor throws.
+ //!
+ //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
+ size_type bucket(const key_type& k) const
+ { return this->bucket(k, this->priv_hasher()); }
+
+ //! <b>Requires</b>: "hash_func" must be a hash function that induces
+ //! the same hash values as the stored hasher. The difference is that
+ //! "hash_func" hashes the given key instead of the value_type.
+ //!
+ //! <b>Effects</b>: Returns the index of the bucket in which elements
+ //! with keys equivalent to k would be found, if any such element existed.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If hash_func throws.
+ //!
+ //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
+ template<class KeyType, class KeyHasher>
+ size_type bucket(const KeyType& k, const KeyHasher &hash_func) const
+ { return priv_hash_to_bucket(hash_func(k)); }
+
+ //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
+ //! or the last rehash function.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bucket_ptr bucket_pointer() const
+ { return this->priv_buckets(); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ local_iterator begin(size_type n)
+ { return local_iterator(this->priv_buckets()[n].begin(), this); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ const_local_iterator begin(size_type n) const
+ { return this->cbegin(n); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ const_local_iterator cbegin(size_type n) const
+ {
+ siterator sit = const_cast<bucket_type&>(this->priv_buckets()[n]).begin();
+ return const_local_iterator(sit, this);
+ }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a local_iterator pointing to the end
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ local_iterator end(size_type n)
+ { return local_iterator(this->priv_buckets()[n].end(), this); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ const_local_iterator end(size_type n) const
+ { return this->cend(n); }
+
+ //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
+ //!
+ //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
+ //! of the sequence stored in the bucket n.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
+ //! containing all of the elements in the nth bucket.
+ const_local_iterator cend(size_type n) const
+ { return const_local_iterator(const_cast<bucket_type&>(this->priv_buckets()[n]).end(), this); }
+
+ //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array
+ //! or the same as the old bucket array. new_size is the length of the
+ //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer()
+ //! n can be bigger or smaller than this->bucket_count().
+ //! 'new_bucket_traits' copy constructor should not throw.
+ //!
+ //! <b>Effects</b>: Updates the internal reference with the new bucket erases
+ //! the values from the old bucket and inserts then in the new one.
+ //! Bucket traits hold by *this is assigned from new_bucket_traits.
+ //! If the container is configured as incremental<>, the split bucket is set
+ //! to the new bucket_len().
+ //!
+ //! If store_hash option is true, this method does not use the hash function.
+ //!
+ //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
+ //!
+ //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
+ void rehash(const bucket_traits &new_bucket_traits)
+ {
+ bucket_ptr new_buckets = new_bucket_traits.bucket_begin();
+ size_type new_buckets_len = new_bucket_traits.bucket_count();
+ bucket_ptr old_buckets = this->priv_buckets();
+ size_type old_buckets_len = this->priv_buckets_len();
+
+ //Check power of two bucket array if the option is activated
+ BOOST_INTRUSIVE_INVARIANT_ASSERT
+ (!power_2_buckets || (0 == (new_buckets_len & (new_buckets_len-1u))));
+
+ size_type n = priv_get_cache_bucket_num();
+ const bool same_buffer = old_buckets == new_buckets;
+ //If the new bucket length is a common factor
+ //of the old one we can avoid hash calculations.
+ const bool fast_shrink = (!incremental) && (old_buckets_len > new_buckets_len) &&
+ (power_2_buckets ||(old_buckets_len % new_buckets_len) == 0);
+ //If we are shrinking the same bucket array and it's
+ //is a fast shrink, just rehash the last nodes
+ size_type new_first_bucket_num = new_buckets_len;
+ if(same_buffer && fast_shrink && (n < new_buckets_len)){
+ n = new_buckets_len;
+ new_first_bucket_num = priv_get_cache_bucket_num();
+ }
+
+ //Anti-exception stuff: they destroy the elements if something goes wrong.
+ //If the source and destination buckets are the same, the second rollback function
+ //is harmless, because all elements have been already unlinked and destroyed
+ typedef detail::init_disposer<node_algorithms> NodeDisposer;
+ NodeDisposer node_disp;
+ detail::exception_array_disposer<bucket_type, NodeDisposer>
+ rollback1(new_buckets[0], node_disp, new_buckets_len);
+ detail::exception_array_disposer<bucket_type, NodeDisposer>
+ rollback2(old_buckets[0], node_disp, old_buckets_len);
+
+ //Put size in a safe value for rollback exception
+ size_type size_backup = this->priv_size_traits().get_size();
+ this->priv_size_traits().set_size(0);
+ //Put cache to safe position
+ priv_initialize_cache();
+ priv_insertion_update_cache(size_type(0u));
+
+ //Iterate through nodes
+ for(; n < old_buckets_len; ++n){
+ bucket_type &old_bucket = old_buckets[n];
+
+ if(!fast_shrink){
+ siterator before_i(old_bucket.before_begin());
+ siterator end(old_bucket.end());
+ siterator i(old_bucket.begin());
+ for(;i != end; ++i){
+ const value_type &v = priv_value_from_slist_node(i.pointed_node());
+ const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
+ const size_type new_n = priv_hash_to_bucket(hash_value, new_buckets_len, new_buckets_len);
+ if(cache_begin && new_n < new_first_bucket_num)
+ new_first_bucket_num = new_n;
+ siterator last = bucket_type::s_iterator_to
+ (*group_functions_t::priv_get_last_in_group
+ (dcast_bucket_ptr(i.pointed_node()), optimize_multikey_t()));
+ if(same_buffer && new_n == n){
+ before_i = last;
+ }
+ else{
+ bucket_type &new_b = new_buckets[new_n];
+ new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
+ }
+ i = before_i;
+ }
+ }
+ else{
+ const size_type new_n = priv_hash_to_bucket(n, new_buckets_len, new_buckets_len);
+ if(cache_begin && new_n < new_first_bucket_num)
+ new_first_bucket_num = new_n;
+ bucket_type &new_b = new_buckets[new_n];
+ if(!old_bucket.empty()){
+ new_b.splice_after( new_b.before_begin()
+ , old_bucket
+ , old_bucket.before_begin()
+ , priv_get_last(old_bucket));
+ }
+ }
+ }
+
+ this->priv_size_traits().set_size(size_backup);
+ this->priv_split_traits().set_size(new_buckets_len);
+ this->priv_real_bucket_traits() = new_bucket_traits;
+ priv_initialize_cache();
+ priv_insertion_update_cache(new_first_bucket_num);
+ rollback1.release();
+ rollback2.release();
+ }
+
+ //! <b>Requires</b>:
+ //!
+ //! <b>Effects</b>:
+ //!
+ //! <b>Complexity</b>:
+ //!
+ //! <b>Throws</b>:
+ //!
+ //! <b>Note</b>: this method is only available if incremental<true> option is activated.
+ bool incremental_rehash(bool grow = true)
+ {
+ //This function is only available for containers with incremental hashing
+ BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
+ size_type split_idx = priv_split_traits().get_size();
+ size_type bucket_len = priv_buckets_len();
+
+ if(grow){
+ //Test if the split variable can be changed
+ if(split_idx >= bucket_len)
+ return false;
+
+ size_type bucket_len = priv_buckets_len();
+ size_type bucket_to_rehash = split_idx - bucket_len/2;
+ bucket_type &old_bucket = this->priv_buckets()[bucket_to_rehash];
+ siterator before_i(old_bucket.before_begin());
+ siterator end(old_bucket.end());
+ siterator i(old_bucket.begin());
+ priv_split_traits().increment();
+
+ //Anti-exception stuff: if an exception is thrown while
+ //moving elements from old_bucket to the target bucket, all moved
+ //elements are moved back to the original one.
+ detail::incremental_rehash_rollback<bucket_type, split_traits> rollback
+ ( this->priv_buckets()[split_idx], old_bucket, priv_split_traits());
+ for(;i != end; ++i){
+ const value_type &v = priv_value_from_slist_node(i.pointed_node());
+ const std::size_t hash_value = this->priv_stored_or_compute_hash(v, store_hash_t());
+ const size_type new_n = priv_hash_to_bucket(hash_value);
+ siterator last = bucket_type::s_iterator_to
+ (*group_functions_t::priv_get_last_in_group
+ (dcast_bucket_ptr(i.pointed_node()), optimize_multikey_t()));
+ if(new_n == bucket_to_rehash){
+ before_i = last;
+ }
+ else{
+ bucket_type &new_b = this->priv_buckets()[new_n];
+ new_b.splice_after(new_b.before_begin(), old_bucket, before_i, last);
+ }
+ i = before_i;
+ }
+ rollback.release();
+ priv_erasure_update_cache();
+ return true;
+ }
+ else{
+ //Test if the split variable can be changed
+ if(split_idx <= bucket_len/2)
+ return false;
+ const size_type target_bucket_num = split_idx - 1 - bucket_len/2;
+ bucket_type &target_bucket = this->priv_buckets()[target_bucket_num];
+ bucket_type &source_bucket = this->priv_buckets()[split_idx-1];
+ target_bucket.splice_after(target_bucket.cbefore_begin(), source_bucket);
+ priv_split_traits().decrement();
+ priv_insertion_update_cache(target_bucket_num);
+ return true;
+ }
+ }
+
+ //! <b>Effects</b>: If new_bucket_traits.bucket_count() is not
+ //! this->bucket_count()/2 or this->bucket_count()*2, or
+ //! this->split_bucket() != new_bucket_traits.bucket_count() returns false
+ //! and does nothing.
+ //!
+ //! Otherwise, copy assigns new_bucket_traits to the internal bucket_traits
+ //! and transfers all the objects from old buckets to the new ones.
+ //!
+ //! <b>Complexity</b>: Linear to size().
+ //!
+ //! <b>Throws</b>: Nothing
+ //!
+ //! <b>Note</b>: this method is only available if incremental<true> option is activated.
+ bool incremental_rehash(const bucket_traits &new_bucket_traits)
+ {
+ //This function is only available for containers with incremental hashing
+ BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
+ size_type new_bucket_traits_size = new_bucket_traits.bucket_count();
+ size_type cur_bucket_traits = this->priv_buckets_len();
+ if(new_bucket_traits_size/2 != cur_bucket_traits && new_bucket_traits_size != cur_bucket_traits/2){
+ return false;
+ }
+
+ const size_type split_idx = this->split_count();
+
+ if(new_bucket_traits_size/2 == cur_bucket_traits){
+ //Test if the split variable can be changed
+ if(!(split_idx >= cur_bucket_traits))
+ return false;
+ }
+ else{
+ //Test if the split variable can be changed
+ if(!(split_idx <= cur_bucket_traits/2))
+ return false;
+ }
+
+ const size_type ini_n = priv_get_cache_bucket_num();
+ const bucket_ptr old_buckets = this->priv_buckets();
+ this->priv_real_bucket_traits() = new_bucket_traits;
+ if(new_bucket_traits.bucket_begin() != old_buckets){
+ for(size_type n = ini_n; n < split_idx; ++n){
+ bucket_type &new_bucket = new_bucket_traits.bucket_begin()[n];
+ bucket_type &old_bucket = old_buckets[n];
+ new_bucket.splice_after(new_bucket.cbefore_begin(), old_bucket);
+ }
+ //Put cache to safe position
+ priv_initialize_cache();
+ priv_insertion_update_cache(ini_n);
+ }
+ return true;
+ }
+
+ //! <b>Requires</b>:
+ //!
+ //! <b>Effects</b>:
+ //!
+ //! <b>Complexity</b>:
+ //!
+ //! <b>Throws</b>:
+ size_type split_count() const
+ {
+ //This function is only available if incremental hashing is activated
+ BOOST_STATIC_ASSERT(( incremental && power_2_buckets ));
+ return this->priv_split_traits().get_size();
+ }
+
+ //! <b>Effects</b>: Returns the nearest new bucket count optimized for
+ //! the container that is bigger than n. This suggestion can be used
+ //! to create bucket arrays with a size that will usually improve
+ //! container's performance. If such value does not exist, the
+ //! higher possible value is returned.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static size_type suggested_upper_bucket_count(size_type n)
+ {
+ const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0];
+ const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size;
+ size_type const* bound = std::lower_bound(primes, primes_end, n);
+ if(bound == primes_end)
+ bound--;
+ return size_type(*bound);
+ }
+
+ //! <b>Effects</b>: Returns the nearest new bucket count optimized for
+ //! the container that is smaller than n. This suggestion can be used
+ //! to create bucket arrays with a size that will usually improve
+ //! container's performance. If such value does not exist, the
+ //! lower possible value is returned.
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static size_type suggested_lower_bucket_count(size_type n)
+ {
+ const std::size_t *primes = &detail::prime_list_holder<0>::prime_list[0];
+ const std::size_t *primes_end = primes + detail::prime_list_holder<0>::prime_list_size;
+ size_type const* bound = std::upper_bound(primes, primes_end, n);
+ if(bound != primes_end)
+ bound--;
+ return size_type(*bound);
+ }
+
+ /// @cond
+ private:
+
+ std::size_t priv_hash_to_bucket(std::size_t hash_value) const
+ { return priv_hash_to_bucket(hash_value, this->priv_real_bucket_traits().bucket_count(), priv_split_traits().get_size()); }
+
+ std::size_t priv_hash_to_bucket(std::size_t hash_value, std::size_t bucket_len, std::size_t split) const
+ {
+ std::size_t bucket_number = priv_hash_to_bucket_impl(hash_value, bucket_len, power_2_buckets_t());
+ if(incremental)
+ if(bucket_number >= split)
+ bucket_number -= bucket_len/2;
+ return bucket_number;
+ }
+
+ std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_len, detail::bool_<false>) const
+ { return hash_value % bucket_len; }
+
+ std::size_t priv_hash_to_bucket_impl(std::size_t hash_value, std::size_t bucket_len, detail::bool_<true>) const
+ { return hash_value & (bucket_len - 1); }
+
+ const key_equal &priv_equal() const
+ { return static_cast<const key_equal&>(this->data_.internal_.bucket_hash_equal_.get()); }
+
+ key_equal &priv_equal()
+ { return static_cast<key_equal&>(this->data_.internal_.bucket_hash_equal_.get()); }
+
+ value_type &priv_value_from_slist_node(slist_node_ptr n)
+ { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); }
+
+ const value_type &priv_value_from_slist_node(slist_node_ptr n) const
+ { return *this->get_real_value_traits().to_value_ptr(dcast_bucket_ptr(n)); }
+
+ const real_bucket_traits &priv_real_bucket_traits(detail::bool_<false>) const
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; }
+
+ const real_bucket_traits &priv_real_bucket_traits(detail::bool_<true>) const
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); }
+
+ real_bucket_traits &priv_real_bucket_traits(detail::bool_<false>)
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_; }
+
+ real_bucket_traits &priv_real_bucket_traits(detail::bool_<true>)
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_.bucket_traits_.get_bucket_traits(*this); }
+
+ const real_bucket_traits &priv_real_bucket_traits() const
+ { return this->priv_real_bucket_traits(detail::bool_<external_bucket_traits>()); }
+
+ real_bucket_traits &priv_real_bucket_traits()
+ { return this->priv_real_bucket_traits(detail::bool_<external_bucket_traits>()); }
+
+ const hasher &priv_hasher() const
+ { return static_cast<const hasher&>(this->data_.internal_.bucket_hash_equal_.bucket_hash.get()); }
+
+ hasher &priv_hasher()
+ { return static_cast<hasher&>(this->data_.internal_.bucket_hash_equal_.bucket_hash.get()); }
+
+ bucket_ptr priv_buckets() const
+ { return this->priv_real_bucket_traits().bucket_begin(); }
+
+ size_type priv_buckets_len() const
+ { return this->priv_real_bucket_traits().bucket_count(); }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ { return node_ptr(const_cast<node*>(detail::get_pointer(ptr))); }
+
+ node &priv_value_to_node(value_type &v)
+ { return *this->get_real_value_traits().to_node_ptr(v); }
+
+ const node &priv_value_to_node(const value_type &v) const
+ { return *this->get_real_value_traits().to_node_ptr(v); }
+
+ size_traits &priv_size_traits()
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return this->data_.internal_.bucket_hash_equal_.bucket_hash.bucket_plus_size_; }
+
+ split_traits &priv_split_traits()
+ { return this->data_.internal_; }
+
+ const split_traits &priv_split_traits() const
+ { return this->data_.internal_; }
+
+ template<class Disposer>
+ void priv_erase_range_impl
+ (size_type bucket_num, siterator before_first_it, siterator end, Disposer disposer, size_type &num_erased)
+ {
+ const bucket_ptr buckets = priv_buckets();
+ bucket_type &b = buckets[bucket_num];
+
+ if(before_first_it == b.before_begin() && end == b.end()){
+ priv_erase_range_impl(bucket_num, 1, disposer, num_erased);
+ }
+ else{
+ num_erased = 0;
+ siterator to_erase(before_first_it);
+ ++to_erase;
+ slist_node_ptr end_ptr = end.pointed_node();
+ while(to_erase != end){
+ group_functions_t::priv_erase_from_group(end_ptr, dcast_bucket_ptr(to_erase.pointed_node()), optimize_multikey_t());
+ to_erase = b.erase_after_and_dispose(before_first_it, make_node_disposer(disposer));
+ ++num_erased;
+ }
+ this->priv_size_traits().set_size(this->priv_size_traits().get_size()-num_erased);
+ }
+ }
+
+ template<class Disposer>
+ void priv_erase_range_impl
+ (size_type first_bucket_num, size_type num_buckets, Disposer disposer, size_type &num_erased)
+ {
+ //Now fully clear the intermediate buckets
+ const bucket_ptr buckets = priv_buckets();
+ num_erased = 0;
+ for(size_type i = first_bucket_num; i < (num_buckets + first_bucket_num); ++i){
+ bucket_type &b = buckets[i];
+ siterator b_begin(b.before_begin());
+ siterator nxt(b_begin);
+ ++nxt;
+ siterator end(b.end());
+ while(nxt != end){
+ priv_init_group(nxt.pointed_node(), optimize_multikey_t());
+ nxt = b.erase_after_and_dispose
+ (b_begin, make_node_disposer(disposer));
+ this->priv_size_traits().decrement();
+ ++num_erased;
+ }
+ }
+ }
+
+ template<class Disposer>
+ void priv_erase_range( siterator before_first_it, size_type first_bucket
+ , siterator last_it, size_type last_bucket
+ , Disposer disposer)
+ {
+ size_type num_erased;
+ if (first_bucket == last_bucket){
+ priv_erase_range_impl(first_bucket, before_first_it, last_it, disposer, num_erased);
+ }
+ else {
+ bucket_type *b = (&this->priv_buckets()[0]);
+ priv_erase_range_impl(first_bucket, before_first_it, b[first_bucket].end(), disposer, num_erased);
+ if(size_type n = (last_bucket - first_bucket - 1))
+ priv_erase_range_impl(first_bucket + 1, n, disposer, num_erased);
+ priv_erase_range_impl(last_bucket, b[last_bucket].before_begin(), last_it, disposer, num_erased);
+ }
+ }
+
+ static node_ptr dcast_bucket_ptr(typename slist_impl::node_ptr p)
+ { return node_ptr(&static_cast<node&>(*p)); }
+
+ std::size_t priv_stored_or_compute_hash(const value_type &v, detail::true_) const
+ { return node_traits::get_hash(this->get_real_value_traits().to_node_ptr(v)); }
+
+ std::size_t priv_stored_or_compute_hash(const value_type &v, detail::false_) const
+ { return priv_hasher()(v); }
+
+ std::size_t priv_stored_hash(slist_node_ptr n, detail::true_) const
+ { return node_traits::get_hash(dcast_bucket_ptr(n)); }
+
+ std::size_t priv_stored_hash(slist_node_ptr, detail::false_) const
+ {
+ //This code should never be reached!
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(0);
+ return 0;
+ }
+
+ static void priv_store_hash(node_ptr p, std::size_t h, detail::true_)
+ { return node_traits::set_hash(p, h); }
+
+ static void priv_store_hash(node_ptr, std::size_t, detail::false_)
+ {}
+
+ static void priv_clear_group_nodes(bucket_type &b, detail::true_)
+ {
+ siterator it(b.begin()), itend(b.end());
+ while(it != itend){
+ node_ptr to_erase(dcast_bucket_ptr(it.pointed_node()));
+ ++it;
+ group_algorithms::init(to_erase);
+ }
+ }
+
+ static void priv_clear_group_nodes(bucket_type &, detail::false_)
+ {}
+
+ std::size_t priv_get_bucket_num(siterator it)
+ { return priv_get_bucket_num_hash_dispatch(it, store_hash_t()); }
+
+ std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::true_)
+ {
+ return this->priv_hash_to_bucket
+ (this->priv_stored_hash(it.pointed_node(), store_hash_t()));
+ }
+
+ std::size_t priv_get_bucket_num_hash_dispatch(siterator it, detail::false_)
+ { return priv_get_bucket_num_no_hash_store(it, optimize_multikey_t()); }
+
+ std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::true_)
+ {
+ bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1);
+ slist_node_ptr bb = group_functions_t::priv_get_bucket_before_begin
+ ( f->end().pointed_node()
+ , l->end().pointed_node()
+ , dcast_bucket_ptr(it.pointed_node()));
+ //Now get the bucket_impl from the iterator
+ const bucket_type &b = static_cast<const bucket_type&>
+ (bucket_type::slist_type::container_from_end_iterator(bucket_type::s_iterator_to(*bb)));
+ //Now just calculate the index b has in the bucket array
+ return static_cast<size_type>(&b - &*f);
+ }
+
+ std::size_t priv_get_bucket_num_no_hash_store(siterator it, detail::false_)
+ {
+ bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1);
+ slist_node_ptr first_ptr(f->cend().pointed_node())
+ , last_ptr(l->cend().pointed_node());
+
+ //The end node is embedded in the singly linked list:
+ //iterate until we reach it.
+ while(!(first_ptr <= it.pointed_node() && it.pointed_node() <= last_ptr)){
+ ++it;
+ }
+ //Now get the bucket_impl from the iterator
+ const bucket_type &b = static_cast<const bucket_type&>
+ (bucket_type::container_from_end_iterator(it));
+
+ //Now just calculate the index b has in the bucket array
+ return static_cast<std::size_t>(&b - &*f);
+ }
+
+ void priv_init_group(slist_node_ptr n, detail::true_)
+ { group_algorithms::init(dcast_bucket_ptr(n)); }
+
+ void priv_init_group(slist_node_ptr, detail::false_)
+ {}
+
+ void priv_insert_in_group(node_ptr first_in_group, node_ptr n, detail::true_)
+ {
+ if(first_in_group){
+ if(group_algorithms::unique(first_in_group))
+ group_algorithms::link_after(first_in_group, n);
+ else{
+ group_algorithms::link_after(node_traits::get_next(first_in_group), n);
+ }
+ }
+ else{
+ group_algorithms::init_header(n);
+ }
+ }
+
+ void priv_insert_in_group(node_ptr, node_ptr, detail::false_)
+ {}
+
+ siterator priv_get_previous
+ (bucket_type &b, siterator i)
+ { return priv_get_previous(b, i, optimize_multikey_t()); }
+
+ siterator priv_get_previous
+ (bucket_type &b, siterator i, detail::true_)
+ {
+ node_ptr elem(dcast_bucket_ptr(i.pointed_node()));
+ node_ptr prev_in_group(group_traits::get_next(elem));
+ bool first_in_group = node_traits::get_next(prev_in_group) != elem;
+ typename bucket_type::node &n = first_in_group
+ ? *group_functions_t::priv_get_prev_to_first_in_group(b.end().pointed_node(), elem)
+ : *group_traits::get_next(elem)
+ ;
+ return bucket_type::s_iterator_to(n);
+ }
+
+ siterator priv_get_previous
+ (bucket_type &b, siterator i, detail::false_)
+ { return b.previous(i); }
+
+ static siterator priv_get_last(bucket_type &b)
+ { return priv_get_last(b, optimize_multikey_t()); }
+
+ static siterator priv_get_last(bucket_type &b, detail::true_)
+ {
+ //First find the last node of p's group.
+ //This requires checking the first node of the next group or
+ //the bucket node.
+ slist_node_ptr end_ptr(b.end().pointed_node());
+ node_ptr possible_end(node_traits::get_next( dcast_bucket_ptr(end_ptr)));
+ node_ptr last_node_group(possible_end);
+
+ while(end_ptr != possible_end){
+ last_node_group = group_traits::get_next(dcast_bucket_ptr(possible_end));
+ possible_end = node_traits::get_next(last_node_group);
+ }
+ return bucket_type::s_iterator_to(*last_node_group);
+ }
+
+ static siterator priv_get_last(bucket_type &b, detail::false_)
+ { return b.previous(b.end()); }
+
+ siterator priv_get_previous_and_next_in_group
+ (siterator i, node_ptr &nxt_in_group)
+ {
+ siterator prev;
+ node_ptr elem(dcast_bucket_ptr(i.pointed_node()));
+ bucket_ptr f(priv_buckets()), l(f + priv_buckets_len() - 1);
+
+ slist_node_ptr first_end_ptr(f->cend().pointed_node());
+ slist_node_ptr last_end_ptr (l->cend().pointed_node());
+
+ node_ptr nxt(node_traits::get_next(elem));
+ node_ptr prev_in_group(group_traits::get_next(elem));
+ bool last_in_group = (first_end_ptr <= nxt && nxt <= last_end_ptr) ||
+ (group_traits::get_next(nxt) != elem);
+ bool first_in_group = node_traits::get_next(prev_in_group) != elem;
+
+ if(first_in_group){
+ node_ptr start_pos;
+ if(last_in_group){
+ start_pos = elem;
+ nxt_in_group = 0;
+ }
+ else{
+ start_pos = prev_in_group;
+ nxt_in_group = node_traits::get_next(elem);
+ }
+ slist_node_ptr bucket_node;
+ if(store_hash){
+ bucket_node = this->priv_buckets()
+ [this->priv_hash_to_bucket
+ (this->priv_stored_hash(elem, store_hash_t()))
+ ].before_begin().pointed_node();
+ }
+ else{
+ bucket_node = group_functions_t::priv_get_bucket_before_begin
+ (first_end_ptr, last_end_ptr, start_pos);
+ }
+ prev = bucket_type::s_iterator_to
+ (*group_functions_t::priv_get_prev_to_first_in_group(bucket_node, elem));
+ }
+ else{
+ if(last_in_group){
+ nxt_in_group = group_functions_t::priv_get_first_in_group_of_last_in_group(elem);
+ }
+ else{
+ nxt_in_group = node_traits::get_next(elem);
+ }
+ prev = bucket_type::s_iterator_to(*group_traits::get_next(elem));
+ }
+ return prev;
+ }
+
+ template<class Disposer>
+ void priv_erase(const_iterator i, Disposer disposer, detail::true_)
+ {
+ siterator elem(i.slist_it());
+ node_ptr nxt_in_group;
+ siterator prev = priv_get_previous_and_next_in_group(elem, nxt_in_group);
+ bucket_type::s_erase_after_and_dispose(prev, make_node_disposer(disposer));
+ if(nxt_in_group)
+ group_algorithms::unlink_after(nxt_in_group);
+ if(safemode_or_autounlink)
+ group_algorithms::init(dcast_bucket_ptr(elem.pointed_node()));
+ }
+
+ template <class Disposer>
+ void priv_erase(const_iterator i, Disposer disposer, detail::false_)
+ {
+ siterator to_erase(i.slist_it());
+ bucket_type &b = this->priv_buckets()[this->priv_get_bucket_num(to_erase)];
+ siterator prev(priv_get_previous(b, to_erase));
+ b.erase_after_and_dispose(prev, make_node_disposer(disposer));
+ }
+
+ bucket_ptr priv_invalid_bucket() const
+ {
+ const real_bucket_traits &rbt = this->priv_real_bucket_traits();
+ return rbt.bucket_begin() + rbt.bucket_count();
+ }
+
+ siterator priv_invalid_local_it() const
+ { return priv_invalid_bucket()->end(); }
+
+ siterator priv_begin() const
+ { return priv_begin(cache_begin_t()); }
+
+ siterator priv_begin(detail::bool_<false>) const
+ {
+ size_type n = 0;
+ size_type buckets_len = this->priv_buckets_len();
+ for (n = 0; n < buckets_len; ++n){
+ bucket_type &b = this->priv_buckets()[n];
+ if(!b.empty()){
+ return b.begin();
+ }
+ }
+ return priv_invalid_local_it();
+ }
+
+ siterator priv_begin(detail::bool_<true>) const
+ {
+ if(this->data_.internal_.bucket_hash_equal_.cached_begin_ == priv_invalid_bucket()){
+ return priv_invalid_local_it();
+ }
+ else{
+ return this->data_.internal_.bucket_hash_equal_.cached_begin_->begin();
+ }
+ }
+
+ void priv_initialize_cache()
+ { priv_initialize_cache(cache_begin_t()); }
+
+ void priv_initialize_cache(detail::bool_<true>)
+ { this->data_.internal_.bucket_hash_equal_.cached_begin_ = priv_invalid_bucket(); }
+
+ void priv_initialize_cache(detail::bool_<false>)
+ {}
+
+ void priv_insertion_update_cache(size_type insertion_bucket)
+ { priv_insertion_update_cache(insertion_bucket, cache_begin_t()); }
+
+ void priv_insertion_update_cache(size_type insertion_bucket, detail::bool_<true>)
+ {
+ bucket_ptr p = priv_buckets() + insertion_bucket;
+ if(p < this->data_.internal_.bucket_hash_equal_.cached_begin_){
+ this->data_.internal_.bucket_hash_equal_.cached_begin_ = p;
+ }
+ }
+
+ void priv_insertion_update_cache(size_type, detail::bool_<false>)
+ {}
+
+ void priv_erasure_update_cache(size_type first_bucket, size_type last_bucket)
+ { priv_erasure_update_cache(first_bucket, last_bucket, cache_begin_t()); }
+
+ void priv_erasure_update_cache(size_type first_bucket_num, size_type last_bucket_num, detail::bool_<true>)
+ {
+ //If the last bucket is the end, the cache must be updated
+ //to the last position if all
+ if(priv_get_cache_bucket_num() == first_bucket_num &&
+ priv_buckets()[first_bucket_num].empty() ){
+ priv_set_cache(priv_buckets() + last_bucket_num);
+ priv_erasure_update_cache();
+ }
+ }
+
+ void priv_erasure_update_cache(size_type, size_type, detail::bool_<false>)
+ {}
+
+ void priv_erasure_update_cache()
+ { priv_erasure_update_cache(cache_begin_t()); }
+
+ void priv_erasure_update_cache(detail::bool_<true>)
+ {
+ if(constant_time_size && !size()){
+ priv_initialize_cache();
+ }
+ else{
+ size_type current_n = this->data_.internal_.bucket_hash_equal_.cached_begin_ - priv_buckets();
+ for( const size_type num_buckets = this->priv_buckets_len()
+ ; current_n < num_buckets
+ ; ++current_n, ++this->data_.internal_.bucket_hash_equal_.cached_begin_){
+ if(!this->data_.internal_.bucket_hash_equal_.cached_begin_->empty()){
+ return;
+ }
+ }
+ priv_initialize_cache();
+ }
+ }
+
+ void priv_erasure_update_cache(detail::bool_<false>)
+ {}
+
+ void priv_swap_cache(detail::bool_<true>, hashtable_impl &other)
+ {
+ std::swap( this->data_.internal_.bucket_hash_equal_.cached_begin_
+ , other.data_.internal_.bucket_hash_equal_.cached_begin_);
+ }
+
+ void priv_swap_cache(detail::bool_<false>, hashtable_impl &)
+ {}
+
+ bucket_ptr priv_get_cache()
+ { return priv_get_cache(cache_begin_t()); }
+
+ bucket_ptr priv_get_cache(detail::bool_<true>)
+ { return this->data_.internal_.bucket_hash_equal_.cached_begin_; }
+
+ bucket_ptr priv_get_cache(detail::bool_<false>)
+ { return this->priv_buckets(); }
+
+ void priv_set_cache(bucket_ptr p)
+ { priv_set_cache(p, cache_begin_t()); }
+
+ void priv_set_cache(bucket_ptr p, detail::bool_<true>)
+ { this->data_.internal_.bucket_hash_equal_.cached_begin_ = p; }
+
+ void priv_set_cache(bucket_ptr, detail::bool_<false>)
+ {}
+
+ size_type priv_get_cache_bucket_num()
+ { return priv_get_cache_bucket_num(cache_begin_t()); }
+
+ size_type priv_get_cache_bucket_num(detail::bool_<true>)
+ { return this->data_.internal_.bucket_hash_equal_.cached_begin_ - this->priv_buckets(); }
+
+ size_type priv_get_cache_bucket_num(detail::bool_<false>)
+ { return 0u; }
+
+ void priv_clear_buckets()
+ {
+ this->priv_clear_buckets
+ ( priv_get_cache()
+ , this->priv_buckets_len() - (priv_get_cache() - priv_buckets()));
+ }
+
+ void priv_initialize_buckets()
+ { this->priv_clear_buckets(priv_buckets(), this->priv_buckets_len()); }
+
+ void priv_clear_buckets(bucket_ptr buckets_ptr, size_type buckets_len)
+ {
+ for(; buckets_len--; ++buckets_ptr){
+ if(safemode_or_autounlink){
+ priv_clear_group_nodes(*buckets_ptr, optimize_multikey_t());
+ buckets_ptr->clear_and_dispose(detail::init_disposer<node_algorithms>());
+ }
+ else{
+ buckets_ptr->clear();
+ }
+ }
+ priv_initialize_cache();
+ }
+
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ siterator priv_find
+ ( const KeyType &key, KeyHasher hash_func
+ , KeyValueEqual equal_func, size_type &bucket_number, std::size_t &h, siterator &previt) const
+ {
+ h = hash_func(key);
+ return priv_find_with_hash(key, equal_func, bucket_number, h, previt);
+ }
+
+ template<class KeyType, class KeyValueEqual>
+ siterator priv_find_with_hash
+ ( const KeyType &key, KeyValueEqual equal_func, size_type &bucket_number, const std::size_t h, siterator &previt) const
+ {
+ bucket_number = priv_hash_to_bucket(h);
+ bucket_type &b = this->priv_buckets()[bucket_number];
+ previt = b.before_begin();
+ if(constant_time_size && this->empty()){
+ return priv_invalid_local_it();
+ }
+
+ siterator it = previt;
+ ++it;
+
+ while(it != b.end()){
+ const value_type &v = priv_value_from_slist_node(it.pointed_node());
+ if(compare_hash){
+ std::size_t vh = this->priv_stored_or_compute_hash(v, store_hash_t());
+ if(h == vh && equal_func(key, v)){
+ return it;
+ }
+ }
+ else if(equal_func(key, v)){
+ return it;
+ }
+ if(optimize_multikey){
+ previt = bucket_type::s_iterator_to
+ (*group_functions_t::priv_get_last_in_group
+ (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t()));
+ it = previt;
+ }
+ else{
+ previt = it;
+ }
+ ++it;
+ }
+ previt = b.before_begin();
+ return priv_invalid_local_it();
+ }
+
+ iterator priv_insert_equal_with_hash(reference value, std::size_t hash_value)
+ {
+ size_type bucket_num;
+ siterator prev;
+ siterator it = this->priv_find_with_hash
+ (value, this->priv_equal(), bucket_num, hash_value, prev);
+ return priv_insert_equal_find(value, bucket_num, hash_value, it);
+ }
+
+ iterator priv_insert_equal_find(reference value, size_type bucket_num, std::size_t hash_value, siterator it)
+ {
+ bucket_type &b = this->priv_buckets()[bucket_num];
+ bool found_equal = it != priv_invalid_local_it();
+ if(!found_equal){
+ it = b.before_begin();
+ }
+ //Now store hash if needed
+ node_ptr n = node_ptr(&priv_value_to_node(value));
+ this->priv_store_hash(n, hash_value, store_hash_t());
+ //Checks for some modes
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(n));
+ //Shorcut for optimize_multikey cases
+ if(optimize_multikey){
+ node_ptr first_in_group = found_equal ?
+ dcast_bucket_ptr(it.pointed_node()) : node_ptr(0);
+ this->priv_insert_in_group(first_in_group, n, optimize_multikey_t());
+ }
+ //Update cache and increment size if needed
+ priv_insertion_update_cache(bucket_num);
+ this->priv_size_traits().increment();
+ //Insert the element in the bucket after it
+ return iterator(b.insert_after(it, *n), this);
+ }
+
+ template<class KeyType, class KeyHasher, class KeyValueEqual>
+ std::pair<siterator, siterator> priv_equal_range
+ ( const KeyType &key
+ , KeyHasher hash_func
+ , KeyValueEqual equal_func
+ , size_type &bucket_number_first
+ , size_type &bucket_number_second
+ , size_type &count) const
+ {
+ std::size_t h;
+ count = 0;
+ siterator prev;
+ //Let's see if the element is present
+ std::pair<siterator, siterator> to_return
+ ( priv_find(key, hash_func, equal_func, bucket_number_first, h, prev)
+ , priv_invalid_local_it());
+ if(to_return.first == to_return.second){
+ bucket_number_second = bucket_number_first;
+ return to_return;
+ }
+ //If it's present, find the first that it's not equal in
+ //the same bucket
+ bucket_type &b = this->priv_buckets()[bucket_number_first];
+ siterator it = to_return.first;
+ if(optimize_multikey){
+ to_return.second = bucket_type::s_iterator_to
+ (*node_traits::get_next(group_functions_t::priv_get_last_in_group
+ (dcast_bucket_ptr(it.pointed_node()), optimize_multikey_t())));
+ count = std::distance(it, to_return.second);
+ if(to_return.second != b.end()){
+ bucket_number_second = bucket_number_first;
+ return to_return;
+ }
+ }
+ else{
+ ++count;
+ ++it;
+ while(it != b.end()){
+ const value_type &v = priv_value_from_slist_node(it.pointed_node());
+ if(compare_hash){
+ std::size_t hv = this->priv_stored_or_compute_hash(v, store_hash_t());
+ if(hv != h || !equal_func(key, v)){
+ to_return.second = it;
+ bucket_number_second = bucket_number_first;
+ return to_return;
+ }
+ }
+ else if(!equal_func(key, v)){
+ to_return.second = it;
+ bucket_number_second = bucket_number_first;
+ return to_return;
+ }
+ ++it;
+ ++count;
+ }
+ }
+
+ //If we reached the end, find the first, non-empty bucket
+ for(bucket_number_second = bucket_number_first+1
+ ; bucket_number_second != this->priv_buckets_len()
+ ; ++bucket_number_second){
+ bucket_type &b = this->priv_buckets()[bucket_number_second];
+ if(!b.empty()){
+ to_return.second = b.begin();
+ return to_return;
+ }
+ }
+
+ //Otherwise, return the end node
+ to_return.second = priv_invalid_local_it();
+ return to_return;
+ }
+ /// @endcond
+};
+
+/// @cond
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template < class T
+ , bool UniqueKeys
+ , class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none
+ , class O5 = none, class O6 = none
+ , class O7 = none, class O8 = none
+ , class O9 = none, class O10= none
+ >
+#else
+template <class T, bool UniqueKeys, class ...Options>
+#endif
+struct make_hashtable_opt
+{
+ typedef typename pack_options
+ < uset_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ //Real value traits must be calculated from options
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ typedef typename packed_options::bucket_traits specified_bucket_traits;
+ /// @endcond
+
+ //Real bucket traits must be calculated from options and calculated value_traits
+ typedef typename detail::get_slist_impl
+ <typename detail::reduced_slist_node_traits
+ <typename real_value_traits::node_traits>::type
+ >::type slist_impl;
+
+ typedef typename
+ detail::if_c< detail::is_same
+ < specified_bucket_traits
+ , default_bucket_traits
+ >::value
+ , detail::bucket_traits_impl<slist_impl>
+ , specified_bucket_traits
+ >::type real_bucket_traits;
+
+ typedef detail::usetopt
+ < value_traits
+ , typename packed_options::hash
+ , typename packed_options::equal
+ , typename packed_options::size_type
+ , real_bucket_traits
+ , (std::size_t(UniqueKeys)*detail::hash_bool_flags::unique_keys_pos)
+ | (std::size_t(packed_options::constant_time_size)*detail::hash_bool_flags::constant_time_size_pos)
+ | (std::size_t(packed_options::power_2_buckets)*detail::hash_bool_flags::power_2_buckets_pos)
+ | (std::size_t(packed_options::cache_begin)*detail::hash_bool_flags::cache_begin_pos)
+ | (std::size_t(packed_options::compare_hash)*detail::hash_bool_flags::compare_hash_pos)
+ | (std::size_t(packed_options::incremental)*detail::hash_bool_flags::incremental_pos)
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c hashtable 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
+ , class O5 = none, class O6 = none
+ , class O7 = none, class O8 = none
+ , class O9 = none, class O10= none
+ >
+#endif
+struct make_hashtable
+{
+ /// @cond
+ typedef hashtable_impl
+ < typename make_hashtable_opt
+ <T, false,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+
+#if defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
+#endif
+class hashtable
+ : public make_hashtable<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_hashtable<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ public:
+ typedef typename Base::value_traits value_traits;
+ typedef typename Base::real_value_traits real_value_traits;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+ typedef typename Base::bucket_ptr bucket_ptr;
+ typedef typename Base::size_type size_type;
+ typedef typename Base::hasher hasher;
+ typedef typename Base::bucket_traits bucket_traits;
+ typedef typename Base::key_equal key_equal;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ hashtable ( const bucket_traits &b_traits
+ , const hasher & hash_func = hasher()
+ , const key_equal &equal_func = key_equal()
+ , const value_traits &v_traits = value_traits())
+ : Base(b_traits, hash_func, equal_func, v_traits)
+ {}
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_HASHTABLE_HPP

Added: sandbox/boost/intrusive/intrusive_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/intrusive_fwd.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,531 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_FWD_HPP
+#define BOOST_INTRUSIVE_FWD_HPP
+
+#include <cstddef>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/workaround.hpp>
+
+/// @cond
+
+namespace boost {
+
+namespace intrusive {
+
+struct none;
+
+} //namespace intrusive{
+} //namespace boost{
+
+namespace boost {
+namespace intrusive {
+
+////////////////////////////
+// Node algorithms
+////////////////////////////
+
+//Algorithms predeclarations
+template<class NodeTraits>
+class circular_list_algorithms;
+
+template<class NodeTraits>
+class circular_slist_algorithms;
+
+template<class NodeTraits>
+class rbtree_algorithms;
+
+////////////////////////////
+// Containers
+////////////////////////////
+
+//slist
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ , class O5 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class slist;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class slist_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class slist_member_hook;
+
+//list
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class list;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class list_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class list_member_hook;
+
+//rbtree/set/multiset
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class rbtree;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class multiset;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class set_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class set_member_hook;
+
+//splaytree/splay_set/splay_multiset
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class splaytree;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class splay_set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class splay_multiset;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class splay_set_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class splay_set_member_hook;
+
+//avltree/avl_set/avl_multiset
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class avltree;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class avl_set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class avl_multiset;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class avl_set_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class avl_set_member_hook;
+
+
+//treap/treap_set/treap_multiset
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class treap;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class treap_set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class treap_multiset;
+
+//Default priority comparison functor
+template <class T>
+struct priority_compare;
+
+//sgtree/sg_set/sg_multiset
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class sgtree;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class sg_set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class sg_multiset;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class bs_set_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class bs_set_member_hook;
+
+//hashtable/unordered_set/unordered_multiset
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ , class O5 = none
+ , class O6 = none
+ , class O7 = none
+ , class O8 = none
+ , class O9 = none
+ , class O10 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class hashtable;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ , class O5 = none
+ , class O6 = none
+ , class O7 = none
+ , class O8 = none
+ , class O9 = none
+ , class O10 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class unordered_set;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ , class O5 = none
+ , class O6 = none
+ , class O7 = none
+ , class O8 = none
+ , class O9 = none
+ , class O10 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+class unordered_multiset;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class unordered_set_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+#else
+template<class ...Options>
+#endif
+class unordered_set_member_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class any_base_hook;
+
+#ifndef BOOST_INTRUSIVE_VARIADIC_TEMPLATES
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+#else
+template<class ...Options>
+#endif
+class any_member_hook;
+
+} //namespace intrusive {
+} //namespace boost {
+
+/// @endcond
+
+#endif //#ifndef BOOST_INTRUSIVE_FWD_HPP

Added: sandbox/boost/intrusive/linear_slist_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/linear_slist_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,327 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_LINEAR_SLIST_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/common_slist_algorithms.hpp>
+#include <cstddef>
+#include <utility>
+
+namespace boost {
+namespace intrusive {
+
+//! linear_slist_algorithms provides basic algorithms to manipulate nodes
+//! forming a linear singly linked list.
+//!
+//! linear_slist_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 linear list
+//!
+//! <tt>node_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_next(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_next(node_ptr n, node_ptr next);</tt>
+template<class NodeTraits>
+class linear_slist_algorithms
+ /// @cond
+ : public detail::common_slist_algorithms<NodeTraits>
+ /// @endcond
+{
+ /// @cond
+ typedef detail::common_slist_algorithms<NodeTraits> base_t;
+ /// @endcond
+ public:
+ typedef typename NodeTraits::node node;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+ typedef NodeTraits node_traits;
+
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+
+ //! <b>Effects</b>: Constructs an non-used list element, putting the next
+ //! pointer to null:
+ //! <tt>NodeTraits::get_next(this_node) == 0
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void init(node_ptr this_node);
+
+ //! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
+ //!
+ //! <b>Effects</b>: Returns true is "this_node" is the only node of a circular list:
+ //! or it's a not inserted node:
+ //! <tt>return !NodeTraits::get_next(this_node) || NodeTraits::get_next(this_node) == this_node</tt>
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool unique(const_node_ptr this_node);
+
+ //! <b>Effects</b>: Returns true is "this_node" has the same state as if
+ //! it was inited using "init(node_ptr)"
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool inited(const_node_ptr this_node);
+
+ //! <b>Requires</b>: prev_node must be in a circular list or be an empty circular list.
+ //!
+ //! <b>Effects</b>: Unlinks the next node of prev_node from the circular list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void unlink_after(node_ptr prev_node);
+
+ //! <b>Requires</b>: prev_node and last_node must be in a circular list
+ //! or be an empty circular list.
+ //!
+ //! <b>Effects</b>: Unlinks the range (prev_node, last_node) from the linear list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void unlink_after(node_ptr prev_node, node_ptr last_node);
+
+ //! <b>Requires</b>: prev_node must be a node of a linear list.
+ //!
+ //! <b>Effects</b>: Links this_node after prev_node in the linear list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void link_after(node_ptr prev_node, node_ptr this_node);
+
+ //! <b>Requires</b>: b and e must be nodes of the same linear list or an empty range.
+ //! and p must be a node of a different linear list.
+ //!
+ //! <b>Effects</b>: Removes the nodes from (b, e] range from their linear list and inserts
+ //! them after p in p's linear list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void transfer_after(node_ptr p, node_ptr b, node_ptr e);
+
+ #endif //#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+
+ //! <b>Effects</b>: Constructs an empty list, making this_node the only
+ //! node of the circular list:
+ //! <tt>NodeTraits::get_next(this_node) == this_node</tt>.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void init_header(node_ptr this_node)
+ { NodeTraits::set_next(this_node, node_ptr(0)); }
+
+ //! <b>Requires</b>: this_node and prev_init_node must be in the same linear list.
+ //!
+ //! <b>Effects</b>: Returns the previous node of this_node in the linear list starting.
+ //! the search from prev_init_node. The first node checked for equality
+ //! is NodeTraits::get_next(prev_init_node).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements between prev_init_node and this_node.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr get_previous_node(node_ptr prev_init_node, node_ptr this_node)
+ { return base_t::get_previous_node(prev_init_node, this_node); }
+
+ //! <b>Requires</b>: this_node must be in a linear list or be an empty linear list.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes in a linear list. If the linear list
+ //! is empty, returns 1.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr this_node)
+ {
+ std::size_t result = 0;
+ const_node_ptr p = this_node;
+ do{
+ p = NodeTraits::get_next(p);
+ ++result;
+ } while (p);
+ return result;
+ }
+
+ //! <b>Requires</b>: this_node and other_node must be nodes inserted
+ //! in linear lists or be empty linear lists.
+ //!
+ //! <b>Effects</b>: Moves all the nodes previously chained after this_node after other_node
+ //! and vice-versa.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_trailing_nodes(node_ptr this_node, node_ptr other_node)
+ {
+ node_ptr this_nxt = NodeTraits::get_next(this_node);
+ node_ptr other_nxt = NodeTraits::get_next(other_node);
+ NodeTraits::set_next(this_node, other_nxt);
+ NodeTraits::set_next(other_node, this_nxt);
+ }
+
+ //! <b>Effects</b>: Reverses the order of elements in the list.
+ //!
+ //! <b>Returns</b>: The new first node of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: This function is linear to the contained elements.
+ static node_ptr reverse(node_ptr p)
+ {
+ if(!p) return node_ptr(0);
+ node_ptr i = NodeTraits::get_next(p);
+ node_ptr first(p);
+ while(i){
+ node_ptr nxti(NodeTraits::get_next(i));
+ base_t::unlink_after(p);
+ NodeTraits::set_next(i, first);
+ first = i;
+ i = nxti;
+ }
+ return first;
+ }
+
+ //! <b>Effects</b>: Moves the first n nodes starting at p to the end of the list.
+ //!
+ //! <b>Returns</b>: A pair containing the new first and last node of the list or
+ //! if there has been any movement, a null pair if n leads to no movement.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements plus the number moved positions.
+ static std::pair<node_ptr, node_ptr> move_first_n_backwards(node_ptr p, std::size_t n)
+ {
+ std::pair<node_ptr, node_ptr> ret(node_ptr(0), node_ptr(0));
+ //Null shift, or count() == 0 or 1, nothing to do
+ if(!n || !p || !NodeTraits::get_next(p)){
+ return ret;
+ }
+
+ node_ptr first = p;
+ bool end_found = false;
+ node_ptr new_last(0);
+ node_ptr old_last(0);
+
+ //Now find the new last node according to the shift count.
+ //If we find 0 before finding the new last node
+ //unlink p, shortcut the search now that we know the size of the list
+ //and continue.
+ for(std::size_t i = 1; i <= n; ++i){
+ new_last = first;
+ first = NodeTraits::get_next(first);
+ if(first == 0){
+ //Shortcut the shift with the modulo of the size of the list
+ n %= i;
+ if(!n) return ret;
+ old_last = new_last;
+ i = 0;
+ //Unlink p and continue the new first node search
+ first = p;
+ //unlink_after(new_last);
+ end_found = true;
+ }
+ }
+
+ //If the p has not been found in the previous loop, find it
+ //starting in the new first node and unlink it
+ if(!end_found){
+ old_last = base_t::get_previous_node(first, node_ptr(0));
+ }
+
+ //Now link p after the new last node
+ NodeTraits::set_next(old_last, p);
+ NodeTraits::set_next(new_last, node_ptr(0));
+ ret.first = first;
+ ret.second = new_last;
+ return ret;
+ }
+
+ //! <b>Effects</b>: Moves the first n nodes starting at p to the beginning of the list.
+ //!
+ //! <b>Returns</b>: A pair containing the new first and last node of the list or
+ //! if there has been any movement, a null pair if n leads to no movement.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements plus the number moved positions.
+ static std::pair<node_ptr, node_ptr> move_first_n_forward(node_ptr p, std::size_t n)
+ {
+ std::pair<node_ptr, node_ptr> ret(node_ptr(0), node_ptr(0));
+ //Null shift, or count() == 0 or 1, nothing to do
+ if(!n || !p || !NodeTraits::get_next(p))
+ return ret;
+
+ node_ptr first = p;
+
+ //Iterate until p is found to know where the current last node is.
+ //If the shift count is less than the size of the list, we can also obtain
+ //the position of the new last node after the shift.
+ node_ptr old_last(first), next_to_it, new_last(p);
+ std::size_t distance = 1;
+ while(!!(next_to_it = node_traits::get_next(old_last))){
+ if(distance++ > n)
+ new_last = node_traits::get_next(new_last);
+ old_last = next_to_it;
+ }
+ //If the shift was bigger or equal than the size, obtain the equivalent
+ //forward shifts and find the new last node.
+ if(distance <= n){
+ //Now find the equivalent forward shifts.
+ //Shortcut the shift with the modulo of the size of the list
+ std::size_t new_before_last_pos = (distance - (n % distance))% distance;
+ //If the shift is a multiple of the size there is nothing to do
+ if(!new_before_last_pos)
+ return ret;
+
+ for( new_last = p
+ ; --new_before_last_pos
+ ; new_last = node_traits::get_next(new_last)){
+ //empty
+ }
+ }
+
+ //Get the first new node
+ node_ptr new_first(node_traits::get_next(new_last));
+ //Now put the old beginning after the old end
+ NodeTraits::set_next(old_last, p);
+ NodeTraits::set_next(new_last, node_ptr(0));
+ ret.first = new_first;
+ ret.second = new_last;
+ return ret;
+ }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_LINEAR_SLIST_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/link_mode.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/link_mode.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,46 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_VALUE_LINK_TYPE_HPP
+#define BOOST_INTRUSIVE_VALUE_LINK_TYPE_HPP
+
+namespace boost {
+namespace intrusive {
+
+//!This enumeration defines the type of value_traits that can be defined
+//!for Boost.Intrusive containers
+enum link_mode_type{
+ //!If this linking policy is specified in a value_traits class
+ //!as the link_mode, containers
+ //!configured with such value_traits won't set the hooks
+ //!of the erased values to a default state. Containers also won't
+ //!check that the hooks of the new values are default initialized.
+ normal_link,
+
+ //!If this linking policy is specified in a value_traits class
+ //!as the link_mode, containers
+ //!configured with such value_traits will set the hooks
+ //!of the erased values to a default state. Containers also will
+ //!check that the hooks of the new values are default initialized.
+ safe_link,
+
+ //!Same as "safe_link" but the user type is an auto-unlink
+ //!type, so the containers with constant-time size features won't be
+ //!compatible with value_traits configured with this policy.
+ //!Containers also know that the a value can be silently erased from
+ //!the container without using any function provided by the containers.
+ auto_unlink
+};
+} //namespace intrusive
+} //namespace boost
+
+#endif //BOOST_INTRUSIVE_VALUE_LINK_TYPE_HPP

Added: sandbox/boost/intrusive/list.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/list.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1481 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_HPP
+#define BOOST_INTRUSIVE_LIST_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/list_hook.hpp>
+#include <boost/intrusive/circular_list_algorithms.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <iterator>
+#include <algorithm>
+#include <functional>
+#include <cstddef>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class ValueTraits, class SizeType, bool ConstantTimeSize>
+struct listopt
+{
+ typedef ValueTraits value_traits;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+};
+
+
+template <class T>
+struct list_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_list_hook>
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ >::type
+{};
+
+/// @endcond
+
+//! The class template list is an intrusive container that mimics most of the
+//! interface of std::list 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<> and \c size_type<>.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class list_impl
+ : private detail::clear_on_destructor_base< list_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ //Public typedefs
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+ typedef typename Config::size_type size_type;
+ typedef list_iterator<list_impl, false> iterator;
+ typedef list_iterator<list_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef circular_list_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<list_impl>::value;
+
+ /// @cond
+
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //Non-copyable and non-moveable
+ list_impl (const list_impl&);
+ list_impl &operator =(const list_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size &&
+ ((int)real_value_traits::link_mode == (int)auto_unlink)
+ ));
+
+ //Const cast emulation for smart pointers
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ //return node_ptr(detail::get_pointer(ptr)));
+ return const_cast<node*>(detail::get_pointer(ptr));
+ }
+
+ node_ptr get_root_node()
+ { return node_ptr(&data_.root_plus_size_.root_); }
+
+ const_node_ptr get_root_node() const
+ { return const_node_ptr(&data_.root_plus_size_.root_); }
+
+ struct root_plus_size : public size_traits
+ {
+ node root_;
+ };
+
+ struct data_t : public value_traits
+ {
+ typedef typename list_impl::value_traits value_traits;
+ data_t(const value_traits &val_traits)
+ : value_traits(val_traits)
+ {}
+
+ root_plus_size root_plus_size_;
+ } data_;
+
+ size_traits &priv_size_traits()
+ { return data_.root_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.root_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ //! <b>Effects</b>: constructs an empty list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: If real_value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
+ list_impl(const value_traits &v_traits = value_traits())
+ : data_(v_traits)
+ {
+ this->priv_size_traits().set_size(size_type(0));
+ node_algorithms::init_header(this->get_root_node());
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Constructs a list equal to the range [first,last).
+ //!
+ //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called.
+ //!
+ //! <b>Throws</b>: If real_value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
+ template<class Iterator>
+ list_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
+ : data_(v_traits)
+ {
+ this->priv_size_traits().set_size(size_type(0));
+ node_algorithms::init_header(this->get_root_node());
+ this->insert(this->cend(), b, e);
+ }
+
+ //! <b>Effects</b>: If it's not a safe-mode or an auto-unlink value_type
+ //! the destructor does nothing
+ //! (ie. no code is generated). Otherwise it detaches all elements from this.
+ //! In this case the objects in the list are not deleted (i.e. no destructors
+ //! are called), but the hooks according to the ValueTraits template parameter
+ //! are set to their default value.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the list, if
+ //! it's a safe-mode or auto-unlink value . Otherwise constant.
+ ~list_impl()
+ {}
+
+ //! <b>Requires</b>: value must be an lvalue.
+ //!
+ //! <b>Effects</b>: Inserts the value in the back of the list.
+ //! No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void push_back(reference value)
+ {
+ node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
+ node_algorithms::link_before(this->get_root_node(), to_insert);
+ this->priv_size_traits().increment();
+ }
+
+ //! <b>Requires</b>: value must be an lvalue.
+ //!
+ //! <b>Effects</b>: Inserts the value in the front of the list.
+ //! No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void push_front(reference value)
+ {
+ node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
+ node_algorithms::link_before(node_traits::get_next(this->get_root_node()), to_insert);
+ this->priv_size_traits().increment();
+ }
+
+ //! <b>Effects</b>: Erases the last element of the list.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
+ void pop_back()
+ { return this->pop_back_and_dispose(detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the last element of the list.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template<class Disposer>
+ void pop_back_and_dispose(Disposer disposer)
+ {
+ node_ptr to_erase = node_traits::get_previous(this->get_root_node());
+ node_algorithms::unlink(to_erase);
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ }
+
+ //! <b>Effects</b>: Erases the first element of the list.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
+ void pop_front()
+ { return this->pop_front_and_dispose(detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the first element of the list.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template<class Disposer>
+ void pop_front_and_dispose(Disposer disposer)
+ {
+ node_ptr to_erase = node_traits::get_next(this->get_root_node());
+ node_algorithms::unlink(to_erase);
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ }
+
+ //! <b>Effects</b>: Returns a reference to the first element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reference front()
+ { return *get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
+
+ //! <b>Effects</b>: Returns a const_reference to the first element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reference front() const
+ { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); }
+
+ //! <b>Effects</b>: Returns a reference to the last element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reference back()
+ { return *get_real_value_traits().to_value_ptr(node_traits::get_previous(this->get_root_node())); }
+
+ //! <b>Effects</b>: Returns a const_reference to the last element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reference back() const
+ { return *get_real_value_traits().to_value_ptr(uncast(node_traits::get_previous(this->get_root_node()))); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator begin()
+ { return iterator(node_traits::get_next(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator begin() const
+ { return this->cbegin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cbegin() const
+ { return const_iterator(node_traits::get_next(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns an iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator end()
+ { return iterator(this->get_root_node(), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator end() const
+ { return this->cend(); }
+
+ //! <b>Effects</b>: Returns a constant iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cend() const
+ { return const_iterator(uncast(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reverse_iterator rbegin()
+ { return reverse_iterator(this->end()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator rbegin() const
+ { return this->crbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator crbegin() const
+ { return const_reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reverse_iterator rend()
+ { return reverse_iterator(begin()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator rend() const
+ { return this->crend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reverse_iterator crend() const
+ { return const_reverse_iterator(this->begin()); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of list.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static list_impl &container_from_end_iterator(iterator end_iterator)
+ { return list_impl::priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of list.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the list associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const list_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return list_impl::priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Effects</b>: Returns the number of the elements contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements contained in the list.
+ //! if constant-time size option is disabled. Constant time otherwise.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ size_type size() const
+ {
+ if(constant_time_size)
+ return this->priv_size_traits().get_size();
+ else
+ return node_algorithms::count(this->get_root_node()) - 1;
+ }
+
+ //! <b>Effects</b>: Returns true if the list contains no elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ bool empty() const
+ { return node_algorithms::unique(this->get_root_node()); }
+
+ //! <b>Effects</b>: Swaps the elements of x and *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void swap(list_impl& other)
+ {
+ node_algorithms::swap_nodes(this->get_root_node(), other.get_root_node());
+ 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>Effects</b>: Moves backwards all the elements, so that the first
+ //! element becomes the second, the second becomes the third...
+ //! the last element becomes the first one.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of shifts.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void shift_backwards(size_type n = 1)
+ { node_algorithms::move_forward(this->get_root_node(), n); }
+
+ //! <b>Effects</b>: Moves forward all the elements, so that the second
+ //! element becomes the first, the third becomes the second...
+ //! the first element becomes the last one.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of shifts.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void shift_forward(size_type n = 1)
+ { node_algorithms::move_backwards(this->get_root_node(), n); }
+
+ //! <b>Effects</b>: Erases the element pointed by i of the list.
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed element,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase(const_iterator i)
+ { return this->erase_and_dispose(i, detail::null_disposer()); }
+
+ //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
+ //!
+ //! <b>Effects</b>: Erases the element range pointed by b and e
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
+ //! or auto-unlink value, or constant-time size is enabled. Constant-time otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased elements.
+ iterator erase(const_iterator b, const_iterator e)
+ {
+ if(safemode_or_autounlink || constant_time_size){
+ return this->erase_and_dispose(b, e, detail::null_disposer());
+ }
+ else{
+ node_algorithms::unlink(b.pointed_node(), e.pointed_node());
+ return e.unconst();
+ }
+ }
+
+ //! <b>Requires</b>: b and e must be valid iterators to elements in *this.
+ //! n must be std::distance(b, e).
+ //!
+ //! <b>Effects</b>: Erases the element range pointed by b and e
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
+ //! or auto-unlink value is enabled. Constant-time otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased elements.
+ iterator erase(const_iterator b, const_iterator e, difference_type n)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(b, e) == difference_type(n));
+ if(safemode_or_autounlink || constant_time_size){
+ return this->erase_and_dispose(b, e, detail::null_disposer());
+ }
+ else{
+ if(constant_time_size){
+ this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
+ }
+ node_algorithms::unlink(b.pointed_node(), e.pointed_node());
+ return e.unconst();
+ }
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the element pointed by i of the list.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed element,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template <class Disposer>
+ iterator erase_and_dispose(const_iterator i, Disposer disposer)
+ {
+ node_ptr to_erase(i.pointed_node());
+ ++i;
+ node_algorithms::unlink(to_erase);
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(this->get_real_value_traits().to_value_ptr(to_erase));
+ return i.unconst();
+ }
+
+ #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 the element range pointed by b and e
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements erased.
+ //!
+ //! <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)
+ {
+ node_ptr bp(b.pointed_node()), ep(e.pointed_node());
+ node_algorithms::unlink(bp, ep);
+ while(bp != ep){
+ node_ptr to_erase(bp);
+ bp = node_traits::get_next(bp);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ this->priv_size_traits().decrement();
+ }
+ return e.unconst();
+ }
+
+ //! <b>Effects</b>: Erases all the elements of the container.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements of the list.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
+ void clear()
+ {
+ if(safemode_or_autounlink){
+ this->clear_and_dispose(detail::null_disposer());
+ }
+ else{
+ node_algorithms::init_header(this->get_root_node());
+ this->priv_size_traits().set_size(size_type(0));
+ }
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements of the container.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements of the list.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased elements.
+ template <class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ const_iterator it(this->begin()), itend(this->end());
+ while(it != itend){
+ node_ptr to_erase(it.pointed_node());
+ ++it;
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ }
+ node_algorithms::init_header(this->get_root_node());
+ this->priv_size_traits().set_size(0);
+ }
+
+ //! <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.
+ //!
+ //! 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. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const list_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ detail::exception_disposer<list_impl, Disposer>
+ rollback(*this, disposer);
+ const_iterator b(src.begin()), e(src.end());
+ for(; b != e; ++b){
+ this->push_back(*cloner(*b));
+ }
+ rollback.release();
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and p must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Inserts the value before the position pointed by p.
+ //!
+ //! <b>Returns</b>: An iterator to the inserted element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time. No copy constructors are called.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ iterator insert(const_iterator p, reference value)
+ {
+ node_ptr to_insert = this->get_real_value_traits().to_node_ptr(value);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
+ node_algorithms::link_before(p.pointed_node(), to_insert);
+ this->priv_size_traits().increment();
+ return iterator(to_insert, this);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type and p must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Inserts the range pointed by b and e before the position p.
+ //! No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ template<class Iterator>
+ void insert(const_iterator p, Iterator b, Iterator e)
+ {
+ for (; b != e; ++b)
+ this->insert(p, *b);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
+ //! No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted plus
+ //! linear to the elements contained in the list if it's a safe-mode
+ //! or auto-unlink value.
+ //! Linear to the number of elements inserted in the list otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements.
+ template<class Iterator>
+ void assign(Iterator b, Iterator e)
+ {
+ this->clear();
+ this->insert(this->cend(), b, e);
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
+ //! No destructors or copy constructors are called.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted plus
+ //! linear to the elements contained in the list.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements.
+ template<class Iterator, class Disposer>
+ void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
+ {
+ this->clear_and_dispose(disposer);
+ this->insert(this->cend(), b, e);
+ }
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
+ //! the element pointed by p. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of
+ //! this list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator p, list_impl& x)
+ {
+ if(!x.empty()){
+ size_traits &thist = this->priv_size_traits();
+ size_traits &xt = x.priv_size_traits();
+ node_algorithms::transfer
+ (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
+ thist.set_size(thist.get_size() + xt.get_size());
+ xt.set_size(size_type(0));
+ }
+ }
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //! new_ele must point to an element contained in list x.
+ //!
+ //! <b>Effects</b>: Transfers the value pointed by new_ele, from list x to this list,
+ //! before the the element pointed by p. No destructors or copy constructors are called.
+ //! If p == new_ele or p == ++new_ele, this function is a null operation.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator p, list_impl&x, const_iterator new_ele)
+ {
+ node_algorithms::transfer(p.pointed_node(), new_ele.pointed_node());
+ x.priv_size_traits().decrement();
+ this->priv_size_traits().increment();
+ }
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //! start and end must point to elements contained in list x.
+ //!
+ //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list,
+ //! before the the element pointed by p. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements transferred
+ //! if constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end)
+ {
+ if(constant_time_size)
+ this->splice(p, x, start, end, std::distance(start, end));
+ else
+ this->splice(p, x, start, end, 1);//distance is a dummy value
+ }
+
+ //! <b>Requires</b>: p must be a valid iterator of *this.
+ //! start and end must point to elements contained in list x.
+ //! n == std::distance(start, end)
+ //!
+ //! <b>Effects</b>: Transfers the range pointed by start and end from list x to this list,
+ //! before the the element pointed by p. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator p, list_impl&x, const_iterator start, const_iterator end, difference_type n)
+ {
+ if(n){
+ if(constant_time_size){
+ size_traits &thist = this->priv_size_traits();
+ size_traits &xt = x.priv_size_traits();
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(start, end));
+ node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node());
+ thist.set_size(thist.get_size() + n);
+ xt.set_size(xt.get_size() - n);
+ }
+ else{
+ node_algorithms::transfer(p.pointed_node(), start.pointed_node(), end.pointed_node());
+ }
+ }
+ }
+
+ //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
+ //! The sort is stable, that is, the relative order of equivalent elements is preserved.
+ //!
+ //! <b>Throws</b>: If real_value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or std::less<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Notes</b>: Iterators and references are not invalidated.
+ //!
+ //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
+ //! is the list's size.
+ void sort()
+ { this->sort(std::less<value_type>()); }
+
+ //! <b>Requires</b>: p must be a comparison function that induces a strict weak ordering
+ //!
+ //! <b>Effects</b>: This function sorts the list *this according to p. The sort is
+ //! stable, that is, the relative order of equivalent elements is preserved.
+ //!
+ //! <b>Throws</b>: If real_value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the predicate throws. Basic guarantee.
+ //!
+ //! <b>Notes</b>: This won't throw if list_base_hook<> or
+ //! list_member_hook are used.
+ //! Iterators and references are not invalidated.
+ //!
+ //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
+ //! is the list's size.
+ template<class Predicate>
+ void sort(Predicate p)
+ {
+ if(node_traits::get_next(this->get_root_node())
+ != node_traits::get_previous(this->get_root_node())){
+ list_impl carry;
+ list_impl counter[64];
+ int fill = 0;
+ while(!this->empty()){
+ carry.splice(carry.cbegin(), *this, this->cbegin());
+ int i = 0;
+ while(i < fill && !counter[i].empty()) {
+ carry.merge(counter[i++], p);
+ }
+ carry.swap(counter[i]);
+ if(i == fill)
+ ++fill;
+ }
+ for (int i = 1; i < fill; ++i)
+ counter[i].merge(counter[i-1], p);
+ this->swap(counter[fill-1]);
+ }
+ }
+
+ //! <b>Effects</b>: This function removes all of x's elements and inserts them
+ //! in order into *this according to std::less<value_type>. The merge is stable;
+ //! that is, if an element from *this is equivalent to one from x, then the element
+ //! from *this will precede the one from x.
+ //!
+ //! <b>Throws</b>: If std::less<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: This function is linear time: it performs at most
+ //! size() + x.size() - 1 comparisons.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated
+ void merge(list_impl& x)
+ { this->merge(x, std::less<value_type>()); }
+
+ //! <b>Requires</b>: p must be a comparison function that induces a strict weak
+ //! ordering and both *this and x must be sorted according to that ordering
+ //! The lists x and *this must be distinct.
+ //!
+ //! <b>Effects</b>: This function removes all of x's elements and inserts them
+ //! in order into *this. The merge is stable; that is, if an element from *this is
+ //! equivalent to one from x, then the element from *this will precede the one from x.
+ //!
+ //! <b>Throws</b>: If the predicate throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: This function is linear time: it performs at most
+ //! size() + x.size() - 1 comparisons.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ template<class Predicate>
+ void merge(list_impl& x, Predicate p)
+ {
+ const_iterator e(this->end());
+ const_iterator bx(x.begin());
+ const_iterator ex(x.end());
+
+ for (const_iterator b = this->cbegin(); b != e; ++b) {
+ size_type n(0);
+ const_iterator ix(bx);
+ while(ix != ex && p(*ix, *b)){
+ ++ix; ++n;
+ }
+ this->splice(b, x, bx, ix, n);
+ bx = ix;
+ }
+ //Now transfer the rest at the end of the container
+ this->splice(e, x);
+ }
+
+ //! <b>Effects</b>: Reverses the order of elements in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: This function is linear time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated
+ void reverse()
+ { node_algorithms::reverse(this->get_root_node()); }
+
+ //! <b>Effects</b>: Removes all the elements that compare equal to value.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ void remove(const_reference value)
+ { this->remove_if(detail::equal_to_value<const_reference>(value)); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes all the elements that compare equal to value.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Disposer>
+ void remove_and_dispose(const_reference value, Disposer disposer)
+ { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
+
+ //! <b>Effects</b>: Removes all the elements for which a specified
+ //! predicate is satisfied. No destructors are called.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Pred>
+ void remove_if(Pred pred)
+ { this->remove_and_dispose_if(pred, detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes all the elements for which a specified
+ //! predicate is satisfied.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Pred, class Disposer>
+ void remove_and_dispose_if(Pred pred, Disposer disposer)
+ {
+ const_iterator cur(this->cbegin());
+ const_iterator last(this->cend());
+ while(cur != last) {
+ if(pred(*cur)){
+ cur = this->erase_and_dispose(cur, disposer);
+ }
+ else{
+ ++cur;
+ }
+ }
+ }
+
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that are equal from the list. No destructors are called.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ void unique()
+ { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
+
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that satisfy some binary predicate from the list.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class BinaryPredicate>
+ void unique(BinaryPredicate pred)
+ { this->unique_and_dispose(pred, detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that are equal from the list.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Disposer>
+ void unique_and_dispose(Disposer disposer)
+ { this->unique_and_dispose(std::equal_to<value_type>(), disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that satisfy some binary predicate from the list.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class BinaryPredicate, class Disposer>
+ void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
+ {
+ const_iterator itend(this->cend());
+ const_iterator cur(this->cbegin());
+
+ if(cur != itend){
+ const_iterator after(cur);
+ ++after;
+ while(after != itend){
+ if(pred(*cur, *after)){
+ after = this->erase_and_dispose(after, disposer);
+ }
+ else{
+ cur = after;
+ ++after;
+ }
+ }
+ }
+ }
+
+ //! <b>Requires</b>: value must be a reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns a const_iterator pointing to the element
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ //! 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));
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value)));
+ return iterator(real_value_traits::to_node_ptr(value), 0);
+ }
+
+ //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns an iterator pointing to the element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ //! 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));
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value))));
+ return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), 0);
+ }
+
+ //! <b>Requires</b>: value must be a reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns a const_iterator pointing to the element
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ iterator iterator_to(reference value)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(value)));
+ return iterator(real_value_traits::to_node_ptr(value), this);
+ }
+
+ //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns an iterator pointing to the element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ const_iterator iterator_to(const_reference value) const
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(!node_algorithms::inited(real_value_traits::to_node_ptr(const_cast<reference> (value))));
+ return const_iterator(real_value_traits::to_node_ptr(const_cast<reference> (value)), this);
+ }
+
+ /// @cond
+
+ private:
+ static list_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ root_plus_size *r = detail::parent_from_member<root_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &root_plus_size::root_);
+ data_t *d = detail::parent_from_member<data_t, root_plus_size>
+ ( r, &data_t::root_plus_size_);
+ list_impl *s = detail::parent_from_member<list_impl, data_t>(d, &list_impl::data_);
+ return *s;
+ }
+ /// @endcond
+};
+
+#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 list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{
+ typedef list_impl<Config> list_type;
+ typedef typename list_type::const_iterator const_iterator;
+ const bool C = list_type::constant_time_size;
+ if(C && x.size() != y.size()){
+ return false;
+ }
+ const_iterator end1 = x.end();
+
+ const_iterator i1 = x.begin();
+ const_iterator i2 = y.begin();
+ if(C){
+ 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 Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const list_impl<T, Options...> &x, const list_impl<T, Options...> &y)
+#else
+(const list_impl<Config> &x, const list_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(list_impl<T, Options...> &x, list_impl<T, Options...> &y)
+#else
+(list_impl<Config> &x, list_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c list 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>
+#endif
+struct make_list
+{
+ /// @cond
+ typedef typename pack_options
+ < list_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef list_impl
+ <
+ listopt
+ < value_traits
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ >
+ > 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>
+#else
+template<class T, class ...Options>
+#endif
+class list
+ : public make_list<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_list
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type Base;
+ typedef typename Base::real_value_traits real_value_traits;
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+ public:
+ typedef typename Base::value_traits value_traits;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+
+ list(const value_traits &v_traits = value_traits())
+ : Base(v_traits)
+ {}
+
+ template<class Iterator>
+ list(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
+ : Base(b, e, v_traits)
+ {}
+
+ static list &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<list &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const list &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const list &>(Base::container_from_end_iterator(end_iterator)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_LIST_HPP

Added: sandbox/boost/intrusive/list_hook.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/list_hook.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,288 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_HOOK_HPP
+#define BOOST_INTRUSIVE_LIST_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/list_node.hpp>
+#include <boost/intrusive/circular_list_algorithms.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/generic_hook.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+template<class VoidPointer>
+struct get_list_node_algo
+{
+ typedef circular_list_algorithms<list_node_traits<VoidPointer> > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c \c list_base_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_list_base_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_list_node_algo<typename packed_options::void_pointer>
+ , typename packed_options::tag
+ , packed_options::link_mode
+ , detail::ListBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Derive a class from this hook in order to store objects of that class
+//! in an list.
+//!
+//! The hook admits the following options: \c tag<>, \c void_pointer<> and
+//! \c link_mode<>.
+//!
+//! \c tag<> defines a tag to identify the node.
+//! The same tag value can be used in different classes, but if a class is
+//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
+//! unique tag.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class list_base_hook
+ : public make_list_base_hook
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ <O1, O2, O3>
+ #else
+ <Options...>
+ #endif
+ ::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ list_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ list_base_hook(const list_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ list_base_hook& operator=(const list_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an list an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~list_base_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(list_base_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c list::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+//! Helper metafunction to define a \c \c list_member_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_list_member_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_list_node_algo<typename packed_options::void_pointer>
+ , member_tag
+ , packed_options::link_mode
+ , detail::NoBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Store this hook in a class to be inserted
+//! in an list.
+//!
+//! The hook admits the following options: \c void_pointer<> and
+//! \c link_mode<>.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class list_member_hook
+ : public make_list_member_hook
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ <O1, O2, O3>
+ #else
+ <Options...>
+ #endif
+ ::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ list_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ list_member_hook(const list_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ list_member_hook& operator=(const list_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an list an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~list_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(list_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c list::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_LIST_HOOK_HPP

Added: sandbox/boost/intrusive/member_value_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/member_value_traits.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,65 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_MEMBER_VALUE_TRAITS_HPP
+#define BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
+
+#include <boost/intrusive/link_mode.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/parent_from_member.hpp>
+
+namespace boost {
+namespace intrusive {
+
+//!This value traits template is used to create value traits
+//!from user defined node traits where value_traits::value_type will
+//!store a node_traits::node
+template< class T, class NodeTraits
+ , typename NodeTraits::node T::* PtrToMember
+ , link_mode_type LinkMode = safe_link>
+struct member_value_traits
+{
+ public:
+ typedef NodeTraits node_traits;
+ typedef T value_type;
+ 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 std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ static const link_mode_type link_mode = LinkMode;
+
+ static node_ptr to_node_ptr(reference value)
+ { return node_ptr(&(value.*PtrToMember)); }
+
+ static const_node_ptr to_node_ptr(const_reference value)
+ { return node_ptr(&(value.*PtrToMember)); }
+
+ static pointer to_value_ptr(node_ptr n)
+ {
+ return pointer(detail::parent_from_member<value_type, node>
+ (detail::get_pointer(n), PtrToMember));
+ }
+
+ static const_pointer to_value_ptr(const_node_ptr n)
+ {
+ return pointer(detail::parent_from_member<value_type, node>
+ (detail::get_pointer(n), PtrToMember));
+ }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP

Added: sandbox/boost/intrusive/options.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/options.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,794 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_OPTIONS_HPP
+#define BOOST_INTRUSIVE_OPTIONS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/static_assert.hpp>
+
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+struct default_tag;
+struct member_tag;
+
+namespace detail{
+
+struct default_hook_tag{};
+
+#define BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER) \
+struct BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER : public default_hook_tag\
+{\
+ template <class T>\
+ struct apply\
+ { typedef typename T::BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER type; };\
+}\
+
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_list_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_slist_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_set_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_uset_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_avl_set_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_splay_set_hook);
+BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION(default_bs_set_hook);
+
+#undef BOOST_INTRUSIVE_DEFAULT_HOOK_MARKER_DEFINITION
+
+template <class ValueTraits>
+struct eval_value_traits
+{
+ typedef typename ValueTraits::value_traits type;
+};
+
+template <class T>
+struct external_bucket_traits_is_true
+{
+ static const bool value = external_bucket_traits_bool<T>::value == 3;
+};
+
+template <class BucketTraits>
+struct eval_bucket_traits
+{
+ typedef typename BucketTraits::bucket_traits type;
+};
+
+template <class T, class BaseHook>
+struct concrete_hook_base_value_traits
+{
+ typedef typename BaseHook::boost_intrusive_tags tags;
+ typedef detail::base_hook_traits
+ < T
+ , typename tags::node_traits
+ , tags::link_mode
+ , typename tags::tag
+ , tags::hook_type> type;
+};
+
+template <class BaseHook>
+struct concrete_hook_base_node_traits
+{ typedef typename BaseHook::boost_intrusive_tags::node_traits type; };
+
+template <class T, class BaseHook>
+struct any_hook_base_value_traits
+{
+ typedef typename BaseHook::boost_intrusive_tags tags;
+ typedef detail::base_hook_traits
+ < T
+ , typename BaseHook::node_traits
+ , tags::link_mode
+ , typename tags::tag
+ , tags::hook_type> type;
+};
+
+template <class BaseHook>
+struct any_hook_base_node_traits
+{ typedef typename BaseHook::node_traits type; };
+
+template<class T, class BaseHook>
+struct get_base_value_traits
+{
+ typedef typename detail::eval_if_c
+ < internal_any_hook_bool_is_true<BaseHook>::value
+ , any_hook_base_value_traits<T, BaseHook>
+ , concrete_hook_base_value_traits<T, BaseHook>
+ >::type type;
+};
+
+template<class BaseHook>
+struct get_base_node_traits
+{
+ typedef typename detail::eval_if_c
+ < internal_any_hook_bool_is_true<BaseHook>::value
+ , any_hook_base_node_traits<BaseHook>
+ , concrete_hook_base_node_traits<BaseHook>
+ >::type type;
+};
+
+template<class T, class MemberHook>
+struct get_member_value_traits
+{
+ typedef typename MemberHook::member_value_traits type;
+};
+
+template<class MemberHook>
+struct get_member_node_traits
+{
+ typedef typename MemberHook::member_value_traits::node_traits type;
+};
+
+template<class T, class SupposedValueTraits>
+struct get_value_traits
+{
+ typedef typename detail::eval_if_c
+ <detail::is_convertible<SupposedValueTraits*, detail::default_hook_tag*>::value
+ ,detail::apply<SupposedValueTraits, T>
+ ,detail::identity<SupposedValueTraits>
+ >::type supposed_value_traits;
+ //...if it's a default hook
+ typedef typename detail::eval_if_c
+ < internal_base_hook_bool_is_true<supposed_value_traits>::value
+ //...get it's internal value traits using
+ //the provided T value type.
+ , get_base_value_traits<T, supposed_value_traits>
+ //...else use it's internal value traits tag
+ //(member hooks and custom value traits are in this group)
+ , detail::eval_if_c
+ < internal_member_value_traits<supposed_value_traits>::value
+ , get_member_value_traits<T, supposed_value_traits>
+ , detail::identity<supposed_value_traits>
+ >
+ >::type type;
+};
+
+template<class ValueTraits>
+struct get_explicit_node_traits
+{
+ typedef typename ValueTraits::node_traits type;
+};
+
+template<class SupposedValueTraits>
+struct get_node_traits
+{
+ typedef SupposedValueTraits supposed_value_traits;
+ //...if it's a base hook
+ typedef typename detail::eval_if_c
+ < internal_base_hook_bool_is_true<supposed_value_traits>::value
+ //...get it's internal value traits using
+ //the provided T value type.
+ , get_base_node_traits<supposed_value_traits>
+ //...else use it's internal value traits tag
+ //(member hooks and custom value traits are in this group)
+ , detail::eval_if_c
+ < internal_member_value_traits<supposed_value_traits>::value
+ , get_member_node_traits<supposed_value_traits>
+ , get_explicit_node_traits<supposed_value_traits>
+ >
+ >::type type;
+};
+
+} //namespace detail{
+
+
+//!This type indicates that no option is being used
+//!and that the default options should be used
+struct none
+{
+ template<class Base>
+ struct pack : Base
+ { };
+};
+
+/// @endcond
+
+//!This option setter specifies if the intrusive
+//!container stores its size as a member to
+//!obtain constant-time size() member.
+template<bool Enabled>
+struct constant_time_size
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool constant_time_size = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the type that
+//!the container will use to store its size.
+template<class SizeType>
+struct size_type
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef SizeType size_type;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the strict weak ordering
+//!comparison functor for the value type
+template<class Compare>
+struct compare
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef Compare compare;
+ };
+/// @endcond
+};
+
+//!This option setter for scapegoat containers specifies if
+//!the intrusive scapegoat container should use a non-variable
+//!alpha value that does not need floating-point operations.
+//!
+//!If activated, the fixed alpha value is 1/sqrt(2). This
+//!option also saves some space in the container since
+//!the alpha value and some additional data does not need
+//!to be stored in the container.
+//!
+//!If the user only needs an alpha value near 1/sqrt(2), this
+//!option also improves performance since avoids logarithm
+//!and division operations when rebalancing the tree.
+template<bool Enabled>
+struct floating_point
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool floating_point = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the equality
+//!functor for the value type
+template<class Equal>
+struct equal
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef Equal equal;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the equality
+//!functor for the value type
+template<class Priority>
+struct priority
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef Priority priority;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the hash
+//!functor for the value type
+template<class Hash>
+struct hash
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef Hash hash;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the relationship between the type
+//!to be managed by the container (the value type) and the node to be
+//!used in the node algorithms. It also specifies the linking policy.
+template<typename ValueTraits>
+struct value_traits
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef ValueTraits value_traits;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the member hook the
+//!container must use.
+template< typename Parent
+ , typename MemberHook
+ , MemberHook Parent::* PtrToMember>
+struct member_hook
+{
+/// @cond
+ typedef detail::member_hook_traits
+ < Parent
+ , MemberHook
+ , PtrToMember
+ > member_value_traits;
+ template<class Base>
+ struct pack : Base
+ {
+ typedef member_value_traits value_traits;
+ };
+/// @endcond
+};
+
+
+//!This option setter specifies that the container
+//!must use the specified base hook
+template<typename BaseHook>
+struct base_hook
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef BaseHook value_traits;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the type of
+//!a void pointer. This will instruct the hook
+//!to use this type of pointer instead of the
+//!default one
+template<class VoidPointer>
+struct void_pointer
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef VoidPointer void_pointer;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the type of
+//!the tag of a base hook. A type cannot have two
+//!base hooks of the same type, so a tag can be used
+//!to differentiate two base hooks with otherwise same type
+template<class Tag>
+struct tag
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef Tag tag;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the link mode
+//!(normal_link, safe_link or auto_unlink)
+template<link_mode_type LinkType>
+struct link_mode
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const link_mode_type link_mode = LinkType;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the hook
+//!should be optimized for size instead of for speed.
+template<bool Enabled>
+struct optimize_size
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool optimize_size = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the list container should
+//!use a linear implementation instead of a circular one.
+template<bool Enabled>
+struct linear
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool linear = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the list container should
+//!use a linear implementation instead of a circular one.
+template<bool Enabled>
+struct cache_last
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool cache_last = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies the bucket traits
+//!class for unordered associative containers. When this option is specified,
+//!instead of using the default bucket traits, a user defined holder will be defined
+template<class BucketTraits>
+struct bucket_traits
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ typedef BucketTraits bucket_traits;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the unordered hook
+//!should offer room to store the hash value.
+//!Storing the hash in the hook will speed up rehashing
+//!processes in applications where rehashing is frequent,
+//!rehashing might throw or the value is heavy to hash.
+template<bool Enabled>
+struct store_hash
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool store_hash = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the unordered hook
+//!should offer room to store another link to another node
+//!with the same key.
+//!Storing this link will speed up lookups and insertions on
+//!unordered_multiset containers with a great number of elements
+//!with the same key.
+template<bool Enabled>
+struct optimize_multikey
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool optimize_multikey = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the bucket array will be always power of two.
+//!This allows using masks instead of the default modulo operation to determine
+//!the bucket number from the hash value, leading to better performance.
+//!In debug mode, if power of two buckets mode is activated, the bucket length
+//!will be checked to through assertions to assure the bucket length is power of two.
+template<bool Enabled>
+struct power_2_buckets
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool power_2_buckets = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the container will cache a pointer to the first
+//!non-empty bucket so that begin() is always constant-time.
+//!This is specially helpful when we can have containers with a few elements
+//!but with big bucket arrays (that is, hashtables with low load factors).
+template<bool Enabled>
+struct cache_begin
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool cache_begin = Enabled;
+ };
+/// @endcond
+};
+
+
+//!This option setter specifies if the container will compare the hash value
+//!before comparing objects. This option can't be specified if store_hash<>
+//!is not true.
+//!This is specially helpful when we have containers with a high load factor.
+//!and the comparison function is much more expensive that comparing already
+//!stored hash values.
+template<bool Enabled>
+struct compare_hash
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool compare_hash = Enabled;
+ };
+/// @endcond
+};
+
+//!This option setter specifies if the hash container will use incremental
+//!hashing. With incremental hashing the cost of hash table expansion is spread
+//!out across each hash table insertion operation, as opposed to be incurred all at once.
+//!Therefore linear hashing is well suited for interactive applications or real-time
+//!appplications where the worst-case insertion time of non-incremental hash containers
+//!(rehashing the whole bucket array) is not admisible.
+template<bool Enabled>
+struct incremental
+{
+ /// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool incremental = Enabled;
+ };
+ /// @endcond
+};
+
+/// @cond
+
+//To-do: pass to variadic templates
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+
+template<class Prev, class Next>
+struct do_pack
+{
+ //Use "pack" member template to pack options
+ typedef typename Next::template pack<Prev> type;
+};
+
+template<class Prev>
+struct do_pack<Prev, none>
+{
+ //Avoid packing "none" to shorten template names
+ typedef Prev type;
+};
+
+template
+ < class DefaultOptions
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ , class O5 = none
+ , class O6 = none
+ , class O7 = none
+ , class O8 = none
+ , class O9 = none
+ , class O10 = none
+ , class O11 = none
+ >
+struct pack_options
+{
+ // join options
+ typedef
+ typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < typename do_pack
+ < DefaultOptions
+ , O1
+ >::type
+ , O2
+ >::type
+ , O3
+ >::type
+ , O4
+ >::type
+ , O5
+ >::type
+ , O6
+ >::type
+ , O7
+ >::type
+ , O8
+ >::type
+ , O9
+ >::type
+ , O10
+ >::type
+ , O11
+ >::type
+ type;
+};
+#else
+
+//index_tuple
+template<int... Indexes>
+struct index_tuple{};
+
+//build_number_seq
+template<std::size_t Num, typename Tuple = index_tuple<> >
+struct build_number_seq;
+
+template<std::size_t Num, int... Indexes>
+struct build_number_seq<Num, index_tuple<Indexes...> >
+ : build_number_seq<Num - 1, index_tuple<Indexes..., sizeof...(Indexes)> >
+{};
+
+template<int... Indexes>
+struct build_number_seq<0, index_tuple<Indexes...> >
+{ typedef index_tuple<Indexes...> type; };
+
+template<class ...Types>
+struct typelist
+{};
+
+//invert_typelist
+template<class T>
+struct invert_typelist;
+
+template<int I, typename Tuple>
+struct typelist_element;
+
+template<int I, typename Head, typename... Tail>
+struct typelist_element<I, typelist<Head, Tail...> >
+{
+ typedef typename typelist_element<I-1, typelist<Tail...> >::type type;
+};
+
+template<typename Head, typename... Tail>
+struct typelist_element<0, typelist<Head, Tail...> >
+{
+ typedef Head type;
+};
+
+template<int ...Ints, class ...Types>
+typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>
+ inverted_typelist(index_tuple<Ints...>, typelist<Types...>)
+{
+ return typelist<typename typelist_element<(sizeof...(Types) - 1) - Ints, typelist<Types...> >::type...>();
+}
+
+//sizeof_typelist
+template<class Typelist>
+struct sizeof_typelist;
+
+template<class ...Types>
+struct sizeof_typelist< typelist<Types...> >
+{
+ static const std::size_t value = sizeof...(Types);
+};
+
+//invert_typelist_impl
+template<class Typelist, class Indexes>
+struct invert_typelist_impl;
+
+
+template<class Typelist, int ...Ints>
+struct invert_typelist_impl< Typelist, index_tuple<Ints...> >
+{
+ static const std::size_t last_idx = sizeof_typelist<Typelist>::value - 1;
+ typedef typelist
+ <typename typelist_element<last_idx - Ints, Typelist>::type...> type;
+};
+
+template<class Typelist, int Int>
+struct invert_typelist_impl< Typelist, index_tuple<Int> >
+{
+ typedef Typelist type;
+};
+
+template<class Typelist>
+struct invert_typelist_impl< Typelist, index_tuple<> >
+{
+ typedef Typelist type;
+};
+
+//invert_typelist
+template<class Typelist>
+struct invert_typelist;
+
+template<class ...Types>
+struct invert_typelist< typelist<Types...> >
+{
+ typedef typelist<Types...> typelist_t;
+ typedef typename build_number_seq<sizeof...(Types)>::type indexes_t;
+ typedef typename invert_typelist_impl<typelist_t, indexes_t>::type type;
+};
+
+//Do pack
+template<class Typelist>
+struct do_pack;
+
+template<>
+struct do_pack<typelist<> >;
+
+template<class Prev>
+struct do_pack<typelist<Prev> >
+{
+ typedef Prev type;
+};
+
+template<class Prev, class Last>
+struct do_pack<typelist<Prev, Last> >
+{
+ typedef typename Prev::template pack<Last> type;
+};
+
+template<class Prev, class ...Others>
+struct do_pack<typelist<Prev, Others...> >
+{
+ typedef typename Prev::template pack
+ <typename do_pack<typelist<Others...>>::type> type;
+};
+
+
+template<class ...Options>
+struct pack_options
+{
+ typedef typelist<Options...> typelist_t;
+ typedef typename invert_typelist<typelist_t>::type inverted_typelist;
+ typedef typename do_pack<inverted_typelist>::type type;
+};
+
+#endif
+
+struct hook_defaults
+ : public pack_options
+ < none
+ , void_pointer<void*>
+ , link_mode<safe_link>
+ , tag<default_tag>
+ , optimize_size<false>
+ , store_hash<false>
+ , linear<false>
+ , optimize_multikey<false>
+ >::type
+{};
+
+/// @endcond
+
+} //namespace intrusive {
+} //namespace boost {
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //#ifndef BOOST_INTRUSIVE_OPTIONS_HPP

Added: sandbox/boost/intrusive/pointer_plus_bits.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/pointer_plus_bits.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,82 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP
+#define BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP
+
+#include <boost/intrusive/detail/mpl.hpp> //ls_zeros
+#include <boost/intrusive/detail/assert.hpp> //BOOST_INTRUSIVE_INVARIANT_ASSERT
+
+namespace boost {
+namespace intrusive {
+
+//!This trait class is used to know if a pointer
+//!can embed extra bits of information if
+//!it's going to be used to point to objects
+//!with an alignment of "Alignment" bytes.
+template<class VoidPointer, std::size_t Alignment>
+struct max_pointer_plus_bits
+{
+ static const std::size_t value = 0;
+};
+
+//!This is a specialization for raw pointers.
+//!Raw pointers can embed extra bits in the lower bits
+//!if the alignment is multiple of 2pow(NumBits).
+template<std::size_t Alignment>
+struct max_pointer_plus_bits<void*, Alignment>
+{
+ static const std::size_t value = detail::ls_zeros<Alignment>::value;
+};
+
+//!This is class that is supposed to have static methods
+//!to embed extra bits of information in a pointer.
+//!This is a declaration and there is no default implementation,
+//!because operations to embed the bits change with every pointer type.
+//!
+//!An implementation that detects that a pointer type whose
+//!has_pointer_plus_bits<>::value is non-zero can make use of these
+//!operations to embed the bits in the pointer.
+template<class Pointer, std::size_t NumBits>
+struct pointer_plus_bits;
+
+//!This is the specialization to embed extra bits of information
+//!in a raw pointer. The extra bits are stored in the lower bit of the pointer.
+template<class T, std::size_t NumBits>
+struct pointer_plus_bits<T*, NumBits>
+{
+ static const std::size_t Mask = ((std::size_t(1u) << NumBits) - 1);
+ typedef T* pointer;
+
+ static pointer get_pointer(pointer n)
+ { return pointer(std::size_t(n) & ~Mask); }
+
+ static void set_pointer(pointer &n, pointer p)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(0 == (std::size_t(p) & Mask));
+ n = pointer(std::size_t(p) | (std::size_t(n) & Mask));
+ }
+
+ static std::size_t get_bits(pointer n)
+ { return (std::size_t(n) & Mask); }
+
+ static void set_bits(pointer &n, std::size_t c)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(c <= Mask);
+ n = pointer(std::size_t(get_pointer(n)) | c);
+ }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#endif //BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP

Added: sandbox/boost/intrusive/priority_compare.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/priority_compare.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,39 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2008
+//
+// 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_PRIORITY_COMPARE_HPP
+#define BOOST_INTRUSIVE_PRIORITY_COMPARE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+
+#include <functional>
+
+namespace boost {
+namespace intrusive {
+
+template <class T>
+struct priority_compare
+ : public std::binary_function<T, T, bool>
+{
+ bool operator()(const T &val, const T &val2) const
+ {
+ return priority_order(val, val2);
+ }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_PRIORITY_COMPARE_HPP

Added: sandbox/boost/intrusive/rbtree.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/rbtree.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1573 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_RBTREE_HPP
+#define BOOST_INTRUSIVE_RBTREE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <algorithm>
+#include <cstddef>
+#include <functional>
+#include <iterator>
+#include <utility>
+
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/set_hook.hpp>
+#include <boost/intrusive/detail/rbtree_node.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/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/rbtree_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize>
+struct setopt
+{
+ typedef ValueTraits value_traits;
+ typedef Compare compare;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+};
+
+template <class T>
+struct set_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_set_hook>
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ , compare<std::less<T> >
+ >::type
+{};
+
+/// @endcond
+
+//! The class template rbtree is an intrusive red-black tree container, that
+//! is used to construct intrusive set and multiset containers. The no-throw
+//! guarantee holds only, if the value_compare object
+//! doesn't throw.
+//!
+//! 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 Config>
+#endif
+class rbtree_impl
+ : private detail::clear_on_destructor_base<rbtree_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef value_type key_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_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<rbtree_impl, false> iterator;
+ typedef tree_iterator<rbtree_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef rbtree_algorithms<node_traits> node_algorithms;
+
+ static const bool constant_time_size = Config::constant_time_size;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<rbtree_impl>::value;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //noncopyable
+ rbtree_impl (const rbtree_impl&);
+ rbtree_impl operator =(const rbtree_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ struct header_plus_size : public size_traits
+ { node header_; };
+
+ struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare>
+ {
+ node_plus_pred_t(const value_compare &comp)
+ : detail::ebo_functor_holder<value_compare>(comp)
+ {}
+ header_plus_size header_plus_size_;
+ };
+
+ struct data_t : public rbtree_impl::value_traits
+ {
+ typedef typename rbtree_impl::value_traits value_traits;
+ data_t(const value_compare & comp, const value_traits &val_traits)
+ : value_traits(val_traits), node_plus_pred_(comp)
+ {}
+ node_plus_pred_t node_plus_pred_;
+ } data_;
+
+ const value_compare &priv_comp() const
+ { return data_.node_plus_pred_.get(); }
+
+ value_compare &priv_comp()
+ { return data_.node_plus_pred_.get(); }
+
+ const node &priv_header() const
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ node &priv_header()
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(detail::get_pointer(ptr)));
+ }
+
+ size_traits &priv_size_traits()
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ typedef typename node_algorithms::insert_commit_data insert_commit_data;
+
+ //! <b>Effects</b>: Constructs an empty tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructorof the value_compare object throws. Basic guarantee.
+ rbtree_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(size_type(0));
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty tree and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is the distance between first and last.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee.
+ template<class Iterator>
+ rbtree_impl( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called), but the nodes according to
+ //! the value_traits template parameter are reinitialized and thus can be reused.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~rbtree_impl()
+ {}
+
+ //! <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(node_ptr(&priv_header())), 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(const_node_ptr(&priv_header())), 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 (node_ptr(&priv_header()), 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(const_node_ptr(&priv_header())), this); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return const_reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return const_reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return reverse_iterator(begin()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return const_reverse_iterator(begin()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return const_reverse_iterator(begin()); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the rbtree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static rbtree_impl &container_from_end_iterator(iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the rbtree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const rbtree_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: it must be a valid iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static rbtree_impl &container_from_iterator(iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <b>Precondition</b>: it must be a valid end const_iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const rbtree_impl &container_from_iterator(const_iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return priv_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return node_algorithms::unique(const_node_ptr(&priv_header())); }
+
+ //! <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(const_node_ptr(&priv_header()));
+ }
+ }
+
+ //! <b>Effects</b>: Swaps the contents of two rbtrees.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the comparison functor's swap call throws.
+ void swap(rbtree_impl& other)
+ {
+ //This can throw
+ using std::swap;
+ swap(priv_comp(), priv_comp());
+ //These can't throw
+ node_algorithms::swap_tree(node_ptr(&priv_header()), node_ptr(&other.priv_header()));
+ if(constant_time_size){
+ size_type backup = this->priv_size_traits().get_size();
+ this->priv_size_traits().set_size(other.priv_size_traits().get_size());
+ other.priv_size_traits().set_size(backup);
+ }
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the tree before the upper bound.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, rbtree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal_upper_bound
+ (node_ptr(&priv_header()), to_insert, key_node_comp), this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator.
+ //!
+ //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to
+ //! where it will be inserted. If "hint" is the upper_bound
+ //! the insertion takes constant time (two comparisons in the worst case)
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(const_iterator hint, reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, rbtree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal
+ (node_ptr(&priv_header()), hint.pointed_node(), to_insert, key_node_comp), this);
+ }
+
+ //! <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.
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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));
+ this->priv_size_traits().increment();
+ node_algorithms::insert_unique_commit
+ (node_ptr(&priv_header()), to_insert, commit_data);
+ return iterator(to_insert, this);
+ }
+
+ //! <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(&priv_header(), 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.
+ 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)
+ 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;
+ 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 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;
+ 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(&priv_header());
+ 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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ node_algorithms::clear_and_dispose(node_ptr(&priv_header())
+ , detail::node_disposer<Disposer, rbtree_impl>(disposer, this));
+ node_algorithms::init_header(&priv_header());
+ 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.
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), 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<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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, rbtree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp));
+ return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this));
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!src.empty()){
+ detail::exception_disposer<rbtree_impl, Disposer>
+ rollback(*this, disposer);
+ node_algorithms::clone
+ (const_node_ptr(&src.priv_header())
+ ,node_ptr(&this->priv_header())
+ ,detail::node_cloner<Cloner, rbtree_impl>(cloner, this)
+ ,detail::node_disposer<Disposer, rbtree_impl>(disposer, this));
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ this->priv_comp() = src.priv_comp();
+ rollback.release();
+ }
+ }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ {
+ node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
+ (node_ptr(&priv_header())));
+ 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)
+ , node_ptr(&priv_header())
+ , get_real_value_traits().to_node_ptr(with_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 iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ return iterator (value_traits::to_node_ptr(value), 0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return iterator (value_traits::to_node_ptr(value), this); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); }
+
+ //! <b>Requires</b>: value shall not be in a tree.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { node_algorithms::init(value_traits::to_node_ptr(value)); }
+
+ //! <b>Effects</b>: removes "value" from the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic time.
+ //!
+ //! <b>Note</b>: This static function is only usable with non-constant
+ //! time size containers that have stateless comparison functors.
+ //!
+ //! If the user calls
+ //! this function with a constant time size container or stateful comparison
+ //! functor a compilation error will be issued.
+ static void remove_node(reference value)
+ {
+ BOOST_STATIC_ASSERT((!constant_time_size));
+ node_ptr to_remove(value_traits::to_node_ptr(value));
+ node_algorithms::unlink(to_remove);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_remove);
+ }
+
+ /// @cond
+ private:
+ template<class Disposer>
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase_and_dispose(b++, disposer);
+ return b.unconst();
+ }
+
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase(b++);
+ return b.unconst();
+ }
+ /// @endcond
+
+ private:
+ static rbtree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ header_plus_size *r = detail::parent_from_member<header_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &header_plus_size::header_);
+ node_plus_pred_t *n = detail::parent_from_member
+ <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_);
+ data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_);
+ rbtree_impl *rb = detail::parent_from_member<rbtree_impl, data_t>(d, &rbtree_impl::data_);
+ return *rb;
+ }
+
+ static rbtree_impl &priv_container_from_iterator(const const_iterator &it)
+ { return priv_container_from_end_iterator(it.end_iterator_from_it()); }
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{
+ typedef rbtree_impl<Config> tree_type;
+ typedef typename tree_type::const_iterator const_iterator;
+
+ if(tree_type::constant_time_size && x.size() != y.size()){
+ return false;
+ }
+ const_iterator end1 = x.end();
+ const_iterator i1 = x.begin();
+ const_iterator i2 = y.begin();
+ if(tree_type::constant_time_size){
+ while (i1 != end1 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1;
+ }
+ else{
+ const_iterator end2 = y.end();
+ while (i1 != end1 && i2 != end2 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1 && i2 == end2;
+ }
+}
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const rbtree_impl<T, Options...> &x, const rbtree_impl<T, Options...> &y)
+#else
+(const rbtree_impl<Config> &x, const rbtree_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(rbtree_impl<T, Options...> &x, rbtree_impl<T, Options...> &y)
+#else
+(rbtree_impl<Config> &x, rbtree_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+/// @cond
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+struct make_rbtree_opt
+{
+ typedef typename pack_options
+ < set_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef setopt
+ < value_traits
+ , typename packed_options::compare
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c rbtree that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_rbtree
+{
+ /// @cond
+ typedef rbtree_impl
+ < typename make_rbtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class rbtree
+ : public make_rbtree<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_rbtree
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ rbtree( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ rbtree( 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)
+ {}
+
+ static rbtree &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<rbtree &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const rbtree &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const rbtree &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static rbtree &container_from_it(iterator it)
+ { return static_cast<rbtree &>(Base::container_from_iterator(it)); }
+
+ static const rbtree &container_from_it(const_iterator it)
+ { return static_cast<const rbtree &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_RBTREE_HPP

Added: sandbox/boost/intrusive/rbtree_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/rbtree_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,850 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008.
+//
+// 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+// The internal implementation of red-black trees is based on that of SGI STL
+// stl_tree.h file:
+//
+// Copyright (c) 1996,1997
+// Silicon Graphics Computer Systems, Inc.
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. Silicon Graphics makes no
+// representations about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied warranty.
+//
+//
+// Copyright (c) 1994
+// Hewlett-Packard Company
+//
+// Permission to use, copy, modify, distribute and sell this software
+// and its documentation for any purpose is hereby granted without fee,
+// provided that the above copyright notice appear in all copies and
+// that both that copyright notice and this permission notice appear
+// in supporting documentation. Hewlett-Packard Company makes no
+// representations about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied warranty.
+//
+// The tree destruction algorithm is based on Julienne Walker and The EC Team code:
+//
+// This code is in the public domain. Anyone may use it or change it in any way that
+// they see fit. The author assumes no responsibility for damages incurred through
+// use of the original code or any variations thereof.
+//
+// It is requested, but not required, that due credit is given to the original author
+// and anyone who has modified the code through a header comment, such as this one.
+
+#ifndef BOOST_INTRUSIVE_RBTREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_RBTREE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.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>
+
+
+namespace boost {
+namespace intrusive {
+
+//! rbtree_algorithms provides basic algorithms to manipulate
+//! nodes forming a red-black tree. The insertion and deletion algorithms are
+//! based on those in Cormen, Leiserson, and Rivest, Introduction to Algorithms
+//! (MIT Press, 1990), except that
+//!
+//! (1) the header node is maintained with links not only to the root
+//! but also to the leftmost node of the tree, to enable constant time
+//! begin(), and to the rightmost node of the tree, to enable linear time
+//! performance when used with the generic set algorithms (set_union,
+//! etc.);
+//!
+//! (2) when a node being deleted has two children its successor node is
+//! relinked into its place, rather than copied, so that the only
+//! pointers invalidated are those referring to the deleted node.
+//!
+//! rbtree_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_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <tt>color</tt>: The type that can store the color of a node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+//!
+//! <tt>static color get_color(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_color(node_ptr n, color c);</tt>
+//!
+//! <tt>static color black();</tt>
+//!
+//! <tt>static color red();</tt>
+template<class NodeTraits>
+class rbtree_algorithms
+{
+ public:
+ typedef NodeTraits node_traits;
+ typedef typename NodeTraits::node node;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+ typedef typename NodeTraits::color color;
+
+ /// @cond
+ private:
+
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+
+ template<class F>
+ struct rbtree_node_cloner
+ : private detail::ebo_functor_holder<F>
+ {
+ typedef detail::ebo_functor_holder<F> base_t;
+
+ rbtree_node_cloner(F f)
+ : base_t(f)
+ {}
+
+ node_ptr operator()(node_ptr p)
+ {
+ node_ptr n = base_t::get()(p);
+ NodeTraits::set_color(n, NodeTraits::get_color(p));
+ return n;
+ }
+ };
+
+ struct rbtree_erase_fixup
+ {
+ void operator()(node_ptr to_erase, node_ptr successor)
+ {
+ //Swap color of y and z
+ color tmp(NodeTraits::get_color(successor));
+ NodeTraits::set_color(successor, NodeTraits::get_color(to_erase));
+ NodeTraits::set_color(to_erase, tmp);
+ }
+ };
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
+
+ static node_ptr end_node(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;
+
+ //! <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(node_ptr header1, node_ptr header2)
+ { return tree_algorithms::swap_tree(header1, header2); }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::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
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ {
+ if(node1 == node2) return;
+
+ tree_algorithms::swap_nodes(node1, header1, node2, header2);
+ //Swap color
+ color c = NodeTraits::get_color(node1);
+ NodeTraits::set_color(node1, NodeTraits::get_color(node2));
+ NodeTraits::set_color(node2, c);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, 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);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ {
+ tree_algorithms::replace_node(node_to_be_replaced, header, new_node);
+ NodeTraits::set_color(new_node, NodeTraits::get_color(node_to_be_replaced));
+ }
+
+ //! <b>Requires</b>: node is a tree node but not the header.
+ //!
+ //! <b>Effects</b>: Unlinks the node and rebalances the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void unlink(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 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(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_node_ptr node)
+ { return tree_algorithms::unique(node); }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ { return tree_algorithms::count(node); }
+
+ //! <b>Requires</b>: header is the header node of the tree.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes above the header.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t size(const_node_ptr header)
+ { return tree_algorithms::size(header); }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ { return tree_algorithms::next_node(p); }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ { return tree_algorithms::prev_node(p); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ { tree_algorithms::init(node); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ {
+ tree_algorithms::init_header(header);
+ NodeTraits::set_color(header, NodeTraits::red());
+ }
+
+ //! <b>Requires</b>: header must be the header of a tree, z a node
+ //! of that tree and z != header.
+ //!
+ //! <b>Effects</b>: Erases node "z" from the tree with header "header".
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr erase(node_ptr header, node_ptr z)
+ {
+ typename tree_algorithms::data_for_rebalance info;
+ tree_algorithms::erase(header, z, rbtree_erase_fixup(), info);
+ node_ptr x = info.x;
+ node_ptr x_parent = info.x_parent;
+
+ //Rebalance rbtree
+ if(NodeTraits::get_color(z) != NodeTraits::red()){
+ rebalance_after_erasure(header, x, x_parent);
+ }
+ 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()(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()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ {
+ rbtree_node_cloner<Cloner> new_cloner(cloner);
+ tree_algorithms::clone(source_header, target_header, new_cloner, disposer);
+ }
+
+ //! <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()(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.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ { tree_algorithms::clear_and_dispose(header, disposer); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::lower_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::upper_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::find(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing
+ //! all elements that are equivalent to "key" according to "comp" or an
+ //! empty range that indicates the position where those elements would be
+ //! if they there are no equivalent elements.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::equal_range(header, key, comp); }
+
+ //! <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
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp)
+ {
+ tree_algorithms::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.
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp)
+ {
+ tree_algorithms::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.
+ template<class NodePtrCompare>
+ static node_ptr insert_equal
+ (node_ptr header, node_ptr hint, node_ptr new_node, NodePtrCompare comp)
+ {
+ tree_algorithms::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.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_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.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, 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.
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_value, const insert_commit_data &commit_data)
+ {
+ tree_algorithms::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(node_ptr n)
+ { return tree_algorithms::get_header(n); }
+
+ /// @cond
+ private:
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is the header of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_header(const_node_ptr p)
+ {
+ return NodeTraits::get_color(p) == NodeTraits::red() &&
+ tree_algorithms::is_header(p);
+ //return NodeTraits::get_color(p) == NodeTraits::red() &&
+ // NodeTraits::get_parent(NodeTraits::get_parent(p)) == p;
+ }
+
+ static void rebalance_after_erasure(node_ptr header, node_ptr x, node_ptr x_parent)
+ {
+ while(x != NodeTraits::get_parent(header) && (x == 0 || NodeTraits::get_color(x) == NodeTraits::black())){
+ if(x == NodeTraits::get_left(x_parent)){
+ node_ptr w = NodeTraits::get_right(x_parent);
+ if(NodeTraits::get_color(w) == NodeTraits::red()){
+ NodeTraits::set_color(w, NodeTraits::black());
+ NodeTraits::set_color(x_parent, NodeTraits::red());
+ tree_algorithms::rotate_left(x_parent, header);
+ w = NodeTraits::get_right(x_parent);
+ }
+ if((NodeTraits::get_left(w) == 0 || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()) &&
+ (NodeTraits::get_right(w) == 0 || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black())){
+ NodeTraits::set_color(w, NodeTraits::red());
+ x = x_parent;
+ x_parent = NodeTraits::get_parent(x_parent);
+ }
+ else {
+ if(NodeTraits::get_right(w) == 0 || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()){
+ NodeTraits::set_color(NodeTraits::get_left(w), NodeTraits::black());
+ NodeTraits::set_color(w, NodeTraits::red());
+ tree_algorithms::rotate_right(w, header);
+ w = NodeTraits::get_right(x_parent);
+ }
+ NodeTraits::set_color(w, NodeTraits::get_color(x_parent));
+ NodeTraits::set_color(x_parent, NodeTraits::black());
+ if(NodeTraits::get_right(w))
+ NodeTraits::set_color(NodeTraits::get_right(w), NodeTraits::black());
+ tree_algorithms::rotate_left(x_parent, header);
+ break;
+ }
+ }
+ else {
+ // same as above, with right_ <-> left_.
+ node_ptr w = NodeTraits::get_left(x_parent);
+ if(NodeTraits::get_color(w) == NodeTraits::red()){
+ NodeTraits::set_color(w, NodeTraits::black());
+ NodeTraits::set_color(x_parent, NodeTraits::red());
+ tree_algorithms::rotate_right(x_parent, header);
+ w = NodeTraits::get_left(x_parent);
+ }
+ if((NodeTraits::get_right(w) == 0 || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()) &&
+ (NodeTraits::get_left(w) == 0 || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black())){
+ NodeTraits::set_color(w, NodeTraits::red());
+ x = x_parent;
+ x_parent = NodeTraits::get_parent(x_parent);
+ }
+ else {
+ if(NodeTraits::get_left(w) == 0 || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()){
+ NodeTraits::set_color(NodeTraits::get_right(w), NodeTraits::black());
+ NodeTraits::set_color(w, NodeTraits::red());
+ tree_algorithms::rotate_left(w, header);
+ w = NodeTraits::get_left(x_parent);
+ }
+ NodeTraits::set_color(w, NodeTraits::get_color(x_parent));
+ NodeTraits::set_color(x_parent, NodeTraits::black());
+ if(NodeTraits::get_left(w))
+ NodeTraits::set_color(NodeTraits::get_left(w), NodeTraits::black());
+ tree_algorithms::rotate_right(x_parent, header);
+ break;
+ }
+ }
+ }
+ if(x)
+ NodeTraits::set_color(x, NodeTraits::black());
+ }
+
+
+ static void rebalance_after_insertion(node_ptr header, node_ptr p)
+ {
+ NodeTraits::set_color(p, NodeTraits::red());
+ while(p != NodeTraits::get_parent(header) && NodeTraits::get_color(NodeTraits::get_parent(p)) == NodeTraits::red()){
+ node_ptr p_parent(NodeTraits::get_parent(p));
+ node_ptr p_parent_parent(NodeTraits::get_parent(p_parent));
+ if(tree_algorithms::is_left_child(p_parent)){
+ node_ptr x = NodeTraits::get_right(p_parent_parent);
+ if(x && NodeTraits::get_color(x) == NodeTraits::red()){
+ NodeTraits::set_color(p_parent, NodeTraits::black());
+ NodeTraits::set_color(p_parent_parent, NodeTraits::red());
+ NodeTraits::set_color(x, NodeTraits::black());
+ p = p_parent_parent;
+ }
+ else {
+ if(!tree_algorithms::is_left_child(p)){
+ p = p_parent;
+ tree_algorithms::rotate_left(p, header);
+ }
+ node_ptr new_p_parent(NodeTraits::get_parent(p));
+ node_ptr new_p_parent_parent(NodeTraits::get_parent(new_p_parent));
+ NodeTraits::set_color(new_p_parent, NodeTraits::black());
+ NodeTraits::set_color(new_p_parent_parent, NodeTraits::red());
+ tree_algorithms::rotate_right(new_p_parent_parent, header);
+ }
+ }
+ else{
+ node_ptr x = NodeTraits::get_left(p_parent_parent);
+ if(x && NodeTraits::get_color(x) == NodeTraits::red()){
+ NodeTraits::set_color(p_parent, NodeTraits::black());
+ NodeTraits::set_color(p_parent_parent, NodeTraits::red());
+ NodeTraits::set_color(x, NodeTraits::black());
+ p = p_parent_parent;
+ }
+ else{
+ if(tree_algorithms::is_left_child(p)){
+ p = p_parent;
+ tree_algorithms::rotate_right(p, header);
+ }
+ node_ptr new_p_parent(NodeTraits::get_parent(p));
+ node_ptr new_p_parent_parent(NodeTraits::get_parent(new_p_parent));
+ NodeTraits::set_color(new_p_parent, NodeTraits::black());
+ NodeTraits::set_color(new_p_parent_parent, NodeTraits::red());
+ tree_algorithms::rotate_left(new_p_parent_parent, header);
+ }
+ }
+ }
+ NodeTraits::set_color(NodeTraits::get_parent(header), NodeTraits::black());
+ }
+ /// @endcond
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_RBTREE_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/set.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/set.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,2228 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_SET_HPP
+#define BOOST_INTRUSIVE_SET_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/rbtree.hpp>
+#include <iterator>
+
+namespace boost {
+namespace intrusive {
+
+//! The class template 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 Config>
+#endif
+class set_impl
+{
+ /// @cond
+ typedef rbtree_impl<Config> tree_type;
+ //! This class is
+ //! non-copyable
+ set_impl (const set_impl&);
+
+ //! This class is
+ //! non-assignable
+ set_impl &operator =(const 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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor of the value_compare object throws.
+ set_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty set and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is std::distance(last, first).
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ set_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(true, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~set_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of set.
+ //!
+ //! <b>Effects</b>: Returns a reference to the set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static set_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const set_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static set_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const set_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &set_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the set.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two sets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(set_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const set_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to inserts value into the set.
+ //!
+ //! <b>Returns</b>: If the value
+ //! is not already present inserts it and returns a pair containing the
+ //! iterator to the new value and true. If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert(reference value)
+ { return tree_.insert_unique(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to to insert x into the set, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the
+ //! new element was inserted into the set.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(const_iterator hint, reference value)
+ { return tree_.insert_unique(hint, value); }
+
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces
+ //! the same strict weak ordering as value_compare. The difference is that
+ //! key_value_comp compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the set, using
+ //! a user provided key instead of the value itself.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that
+ //! part to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the set.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ { return tree_.insert_unique_check(key, key_value_comp, commit_data); }
+
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces
+ //! the same strict weak ordering as value_compare. The difference is that
+ //! key_value_comp compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the set, using
+ //! a user provided key instead of the value itself, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! constructing that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that key
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This can give a total
+ //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the set.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }
+
+ //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
+ //! must have been obtained from a previous call to "insert_check".
+ //! No objects should have been inserted or erased from the set between
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
+ //!
+ //! <b>Effects</b>: Inserts the value in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Returns</b>: An iterator to the newly inserted object.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ iterator insert_commit(reference value, const insert_commit_data &commit_data)
+ { return tree_.insert_unique_commit(value, commit_data); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the set.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_unique(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is 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.
+ 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); }
+
+ #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 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.
+ 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.
+ 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.
+ 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.
+ 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_.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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a set/multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ /// @cond
+ friend bool operator==(const set_impl &x, const set_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const set_impl &x, const set_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
+#else
+(const set_impl<Config> &x, const set_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
+#else
+(const set_impl<Config> &x, const set_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
+#else
+(const set_impl<Config> &x, const set_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const set_impl<T, Options...> &x, const set_impl<T, Options...> &y)
+#else
+(const set_impl<Config> &x, const set_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(set_impl<T, Options...> &x, set_impl<T, Options...> &y)
+#else
+(set_impl<Config> &x, set_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! 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>
+#endif
+struct make_set
+{
+ /// @cond
+ typedef set_impl
+ < typename make_rbtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::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>
+#else
+template<class T, class ...Options>
+#endif
+class set
+ : public make_set<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_set
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ set( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ set( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static set &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const set &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static set &container_from_iterator(iterator it)
+ { return static_cast<set &>(Base::container_from_iterator(it)); }
+
+ static const set &container_from_iterator(const_iterator it)
+ { return static_cast<const set &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+//! The class template 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 Config>
+#endif
+class multiset_impl
+{
+ /// @cond
+ typedef rbtree_impl<Config> tree_type;
+
+ //Non-copyable and non-assignable
+ multiset_impl (const multiset_impl&);
+ multiset_impl &operator =(const 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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ multiset_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty multiset and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is the distance between first and last
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ multiset_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(false, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~multiset_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static multiset_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const multiset_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static multiset_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const multiset_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &multiset_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the multiset.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two multisets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(multiset_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const multiset_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(reference value)
+ { return tree_.insert_equal(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts x into the multiset, using pos as a hint to
+ //! where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(const_iterator hint, reference value)
+ { return tree_.insert_equal(hint, value); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_equal(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is at most
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator b, iterator e)
+ { return tree_.erase(b, e); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + this->count(value)).
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ size_type erase(const_reference value)
+ { return tree_.erase(value); }
+
+ //! <b>Effects</b>: Erases all the elements that compare equal with
+ //! the given key and the given comparison functor.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + this->count(key, comp)).
+ //!
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ 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); }
+
+ #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>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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a set/multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Effects</b>: removes "value" from the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic time.
+ //!
+ //! <b>Note</b>: This static function is only usable with non-constant
+ //! time size containers that have stateless comparison functors.
+ //!
+ //! If the user calls
+ //! this function with a constant time size container or stateful comparison
+ //! functor a compilation error will be issued.
+ static void remove_node(reference value)
+ { tree_type::remove_node(value); }
+
+ /// @cond
+ friend bool operator==(const multiset_impl &x, const multiset_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const multiset_impl &x, const multiset_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
+#else
+(const multiset_impl<Config> &x, const multiset_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
+#else
+(const multiset_impl<Config> &x, const multiset_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
+#else
+(const multiset_impl<Config> &x, const multiset_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const multiset_impl<T, Options...> &x, const multiset_impl<T, Options...> &y)
+#else
+(const multiset_impl<Config> &x, const multiset_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(multiset_impl<T, Options...> &x, multiset_impl<T, Options...> &y)
+#else
+(multiset_impl<Config> &x, multiset_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c multiset that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_multiset
+{
+ /// @cond
+ typedef multiset_impl
+ < typename make_rbtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::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>
+#else
+template<class T, class ...Options>
+#endif
+class multiset
+ : public make_multiset<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_multiset<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ multiset( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ multiset( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static multiset &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const multiset &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static multiset &container_from_iterator(iterator it)
+ { return static_cast<multiset &>(Base::container_from_iterator(it)); }
+
+ static const multiset &container_from_iterator(const_iterator it)
+ { return static_cast<const multiset &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SET_HPP

Added: sandbox/boost/intrusive/set_hook.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/set_hook.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,298 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_SET_HOOK_HPP
+#define BOOST_INTRUSIVE_SET_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/rbtree_node.hpp>
+#include <boost/intrusive/rbtree_algorithms.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/generic_hook.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+template<class VoidPointer, bool OptimizeSize = false>
+struct get_set_node_algo
+{
+ typedef rbtree_algorithms<rbtree_node_traits<VoidPointer, OptimizeSize> > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c set_base_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none, class O4 = none>
+#endif
+struct make_set_base_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_set_node_algo<typename packed_options::void_pointer
+ ,packed_options::optimize_size>
+ , typename packed_options::tag
+ , packed_options::link_mode
+ , detail::SetBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Derive a class from set_base_hook in order to store objects in
+//! in a set/multiset. set_base_hook holds the data necessary to maintain
+//! the set/multiset and provides an appropriate value_traits class for set/multiset.
+//!
+//! The hook admits the following options: \c tag<>, \c void_pointer<>,
+//! \c link_mode<> and \c optimize_size<>.
+//!
+//! \c tag<> defines a tag to identify the node.
+//! The same tag value can be used in different classes, but if a class is
+//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
+//! unique tag.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c optimize_size<> will tell the hook to optimize the hook for size instead
+//! of speed.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3, class O4>
+#endif
+class set_base_hook
+ : public make_set_base_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ set_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ set_base_hook(const set_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ set_base_hook& operator=(const set_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in a set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~set_base_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(set_base_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+//! Helper metafunction to define a \c set_member_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none, class O4 = none>
+#endif
+struct make_set_member_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_set_node_algo<typename packed_options::void_pointer
+ ,packed_options::optimize_size>
+ , member_tag
+ , packed_options::link_mode
+ , detail::NoBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Put a public data member set_member_hook in order to store objects of this class in
+//! a set/multiset. set_member_hook holds the data necessary for maintaining the
+//! set/multiset and provides an appropriate value_traits class for set/multiset.
+//!
+//! The hook admits the following options: \c void_pointer<>,
+//! \c link_mode<> and \c optimize_size<>.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c optimize_size<> will tell the hook to optimize the hook for size instead
+//! of speed.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3, class O4>
+#endif
+class set_member_hook
+ : public make_set_member_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ set_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ set_member_hook(const set_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ set_member_hook& operator=(const set_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in a set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~set_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(set_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SET_HOOK_HPP

Added: sandbox/boost/intrusive/sg_set.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/sg_set.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,2292 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_SG_SET_HPP
+#define BOOST_INTRUSIVE_SG_SET_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/sgtree.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <iterator>
+
+namespace boost {
+namespace intrusive {
+
+//! The class template sg_set is an intrusive container, that mimics most of
+//! the interface of std::set as described in the C++ standard.
+//!
+//! The 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 Config>
+#endif
+class sg_set_impl
+{
+ /// @cond
+ typedef sgtree_impl<Config> tree_type;
+ //! This class is
+ //! non-copyable
+ sg_set_impl (const sg_set_impl&);
+
+ //! This class is
+ //! non-assignable
+ sg_set_impl &operator =(const sg_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor of the value_compare object throws.
+ sg_set_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty sg_set and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is std::distance(last, first).
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ sg_set_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(true, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~sg_set_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of sg_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static sg_set_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<sg_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &sg_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of sg_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sg_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const sg_set_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<sg_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &sg_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static sg_set_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<sg_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &sg_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const sg_set_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<sg_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &sg_set_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the sg_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the sg_set.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two sets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(sg_set_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const sg_set_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to inserts value into the sg_set.
+ //!
+ //! <b>Returns</b>: If the value
+ //! is not already present inserts it and returns a pair containing the
+ //! iterator to the new value and true. If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert(reference value)
+ { return tree_.insert_unique(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to to insert x into the sg_set, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the
+ //! new element was inserted into the sg_set.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ 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 ascapegoatitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using
+ //! a user provided key instead of the value itself.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that
+ //! part to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the sg_set.
+ 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 ascapegoatitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the sg_set, using
+ //! a user provided key instead of the value itself, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! constructing that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that key
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This can give a total
+ //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the sg_set.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }
+
+ //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
+ //! must have been obtained from a previous call to "insert_check".
+ //! No objects should have been inserted or erased from the sg_set between
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
+ //!
+ //! <b>Effects</b>: Inserts the value in the sg_set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Returns</b>: An iterator to the newly inserted object.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ iterator insert_commit(reference value, const insert_commit_data &commit_data)
+ { return tree_.insert_unique_commit(value, commit_data); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the sg_set.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_unique(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is 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.
+ 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); }
+
+ #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 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.
+ 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.
+ 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.
+ 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.
+ 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_.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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a sg_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! sg_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! sg_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a sg_set/sg_multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ //! <b>Returns</b>: The balance factor (alpha) used in this tree
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ float balance_factor() const
+ { return tree_.balance_factor(); }
+
+ //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
+ //!
+ //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
+ //! the tree if the new balance factor is stricter (less) than the old factor.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ void balance_factor(float new_alpha)
+ { tree_.balance_factor(new_alpha); }
+
+ /// @cond
+ friend bool operator==(const sg_set_impl &x, const sg_set_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const sg_set_impl &x, const sg_set_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
+#else
+(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
+#else
+(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
+#else
+(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_set_impl<T, Options...> &x, const sg_set_impl<T, Options...> &y)
+#else
+(const sg_set_impl<Config> &x, const sg_set_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(sg_set_impl<T, Options...> &x, sg_set_impl<T, Options...> &y)
+#else
+(sg_set_impl<Config> &x, sg_set_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c sg_set that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_sg_set
+{
+ /// @cond
+ typedef sg_set_impl
+ < typename make_sgtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::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>
+#else
+template<class T, class ...Options>
+#endif
+class sg_set
+ : public make_sg_set<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_sg_set
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ sg_set( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ sg_set( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static sg_set &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<sg_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const sg_set &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const sg_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static sg_set &container_from_iterator(iterator it)
+ { return static_cast<sg_set &>(Base::container_from_iterator(it)); }
+
+ static const sg_set &container_from_iterator(const_iterator it)
+ { return static_cast<const sg_set &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+//! The class template sg_multiset is an intrusive container, that mimics most of
+//! the interface of std::sg_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 Config>
+#endif
+class sg_multiset_impl
+{
+ /// @cond
+ typedef sgtree_impl<Config> tree_type;
+
+ //Non-copyable and non-assignable
+ sg_multiset_impl (const sg_multiset_impl&);
+ sg_multiset_impl &operator =(const sg_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ sg_multiset_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty sg_multiset and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is the distance between first and last
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ sg_multiset_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(false, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the sg_multiset
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~sg_multiset_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of sg_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static sg_multiset_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<sg_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &sg_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of sg_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sg_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const sg_multiset_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<sg_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &sg_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static sg_multiset_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<sg_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &sg_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const sg_multiset_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<sg_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &sg_multiset_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the sg_multiset.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two sg_multisets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(sg_multiset_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const sg_multiset_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the sg_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(reference value)
+ { return tree_.insert_equal(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts x into the sg_multiset, using pos as a hint to
+ //! where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(const_iterator hint, reference value)
+ { return tree_.insert_equal(hint, value); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the sg_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_equal(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is 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.
+ 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); }
+
+ #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>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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a sg_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! sg_multiset that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the sg_multiset
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a sg_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! sg_multiset that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a sg_multiset/sg_multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ //! <b>Returns</b>: The balance factor (alpha) used in this tree
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ float balance_factor() const
+ { return tree_.balance_factor(); }
+
+ //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
+ //!
+ //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
+ //! the tree if the new balance factor is stricter (less) than the old factor.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ void balance_factor(float new_alpha)
+ { tree_.balance_factor(new_alpha); }
+
+ /// @cond
+ friend bool operator==(const sg_multiset_impl &x, const sg_multiset_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const sg_multiset_impl &x, const sg_multiset_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
+#else
+(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
+#else
+(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
+#else
+(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sg_multiset_impl<T, Options...> &x, const sg_multiset_impl<T, Options...> &y)
+#else
+(const sg_multiset_impl<Config> &x, const sg_multiset_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(sg_multiset_impl<T, Options...> &x, sg_multiset_impl<T, Options...> &y)
+#else
+(sg_multiset_impl<Config> &x, sg_multiset_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c sg_multiset that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_sg_multiset
+{
+ /// @cond
+ typedef sg_multiset_impl
+ < typename make_sgtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class sg_multiset
+ : public make_sg_multiset<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_sg_multiset
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ sg_multiset( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ sg_multiset( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static sg_multiset &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const sg_multiset &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const sg_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static sg_multiset &container_from_iterator(iterator it)
+ { return static_cast<sg_multiset &>(Base::container_from_iterator(it)); }
+
+ static const sg_multiset &container_from_iterator(const_iterator it)
+ { return static_cast<const sg_multiset &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SG_SET_HPP

Added: sandbox/boost/intrusive/sgtree.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/sgtree.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1795 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// The option that yields to non-floating point 1/sqrt(2) alpha is taken
+// from the scapegoat tree implementation of the PSPP library.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_SGTREE_HPP
+#define BOOST_INTRUSIVE_SGTREE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <algorithm>
+#include <cstddef>
+#include <functional>
+#include <iterator>
+#include <utility>
+#include <cmath>
+#include <cstddef>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/bs_set_hook.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/sgtree_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+namespace detail{
+
+//! Returns floor(log(n)/log(sqrt(2))) -> floor(2*log2(n))
+//! Undefined if N is 0.
+//!
+//! This function does not use float point operations.
+inline std::size_t calculate_h_sqrt2 (std::size_t n)
+{
+ std::size_t f_log2 = detail::floor_log2(n);
+ return (2*f_log2) + (n >= detail::sqrt2_pow_2xplus1 (f_log2));
+}
+
+struct h_alpha_sqrt2_t
+{
+ h_alpha_sqrt2_t(void){}
+ std::size_t operator()(std::size_t n) const
+ { return calculate_h_sqrt2(n); }
+};
+
+struct alpha_0_75_by_max_size_t
+{
+ alpha_0_75_by_max_size_t(void){}
+ std::size_t operator()(std::size_t max_tree_size) const
+ {
+ const std::size_t max_tree_size_limit = ((~std::size_t(0))/std::size_t(3));
+ return max_tree_size > max_tree_size_limit ? max_tree_size/4*3 : max_tree_size*3/4;
+ }
+};
+
+struct h_alpha_t
+{
+ h_alpha_t(float inv_minus_logalpha)
+ : inv_minus_logalpha_(inv_minus_logalpha)
+ {}
+
+ std::size_t operator()(std::size_t n) const
+ {
+ //Returns floor(log1/alpha(n)) ->
+ // floor(log(n)/log(1/alpha)) ->
+ // floor(log(n)/(-log(alpha)))
+ //return static_cast<std::size_t>(std::log(float(n))*inv_minus_logalpha_);
+ return static_cast<std::size_t>(detail::fast_log2(float(n))*inv_minus_logalpha_);
+ }
+
+ private:
+ //Since the function will be repeatedly called
+ //precalculate constant data to avoid repeated
+ //calls to log and division.
+ //This will store 1/(-std::log(alpha_))
+ float inv_minus_logalpha_;
+};
+
+struct alpha_by_max_size_t
+{
+ alpha_by_max_size_t(float alpha)
+ : alpha_(alpha)
+ {}
+
+ float operator()(std::size_t max_tree_size) const
+ { return float(max_tree_size)*alpha_; }
+
+ private:
+ float alpha_;
+ float inv_minus_logalpha_;
+};
+
+template<bool Activate>
+struct alpha_holder
+{
+ typedef boost::intrusive::detail::h_alpha_t h_alpha_t;
+ typedef boost::intrusive::detail::alpha_by_max_size_t multiply_by_alpha_t;
+
+ alpha_holder()
+ { set_alpha(0.7f); }
+
+ float get_alpha() const
+ { return alpha_; }
+
+ void set_alpha(float alpha)
+ {
+ alpha_ = alpha;
+ inv_minus_logalpha_ = 1/(-detail::fast_log2(alpha));
+ }
+
+ h_alpha_t get_h_alpha_t() const
+ { return h_alpha_t(inv_minus_logalpha_); }
+
+ multiply_by_alpha_t get_multiply_by_alpha_t() const
+ { return multiply_by_alpha_t(alpha_); }
+
+ private:
+ float alpha_;
+ float inv_minus_logalpha_;
+};
+
+template<>
+struct alpha_holder<false>
+{
+ //This specialization uses alpha = 1/sqrt(2)
+ //without using floating point operations
+ //Downside: alpha CAN't be changed.
+ typedef boost::intrusive::detail::h_alpha_sqrt2_t h_alpha_t;
+ typedef boost::intrusive::detail::alpha_0_75_by_max_size_t multiply_by_alpha_t;
+
+ float get_alpha() const
+ { return 0.70710677f; }
+
+ void set_alpha(float)
+ { //alpha CAN't be changed.
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(0);
+ }
+
+ h_alpha_t get_h_alpha_t() const
+ { return h_alpha_t(); }
+
+ multiply_by_alpha_t get_multiply_by_alpha_t() const
+ { return multiply_by_alpha_t(); }
+};
+
+} //namespace detail{
+
+template <class ValueTraits, class Compare, class SizeType, bool FloatingPoint>
+struct sg_setopt
+{
+ typedef ValueTraits value_traits;
+ typedef Compare compare;
+ typedef SizeType size_type;
+ static const bool floating_point = FloatingPoint;
+};
+
+template <class T>
+struct sg_set_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_bs_set_hook>
+ , floating_point<true>
+ , size_type<std::size_t>
+ , compare<std::less<T> >
+ >::type
+{};
+
+/// @endcond
+
+//! The class template sgtree is an intrusive scapegoat tree container, that
+//! is used to construct intrusive sg_set and sg_multiset containers.
+//! The no-throw guarantee holds only, if the value_compare object
+//! doesn't throw.
+//!
+//! 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 floating_point<>, \c size_type<> and
+//! \c compare<>.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class sgtree_impl
+ : private detail::clear_on_destructor_base<sgtree_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef value_type key_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_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<sgtree_impl, false> iterator;
+ typedef tree_iterator<sgtree_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef sgtree_algorithms<node_traits> node_algorithms;
+
+ static const bool floating_point = Config::floating_point;
+ static const bool constant_time_size = true;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<sgtree_impl>::value;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<true, size_type> size_traits;
+ typedef detail::alpha_holder<floating_point> alpha_traits;
+ typedef typename alpha_traits::h_alpha_t h_alpha_t;
+ typedef typename alpha_traits::multiply_by_alpha_t multiply_by_alpha_t;
+
+ //noncopyable
+ sgtree_impl (const sgtree_impl&);
+ sgtree_impl operator =(const sgtree_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ BOOST_STATIC_ASSERT(((int)real_value_traits::link_mode != (int)auto_unlink));
+
+ //BOOST_STATIC_ASSERT((
+ // (int)real_value_traits::link_mode != (int)auto_unlink ||
+ // !floating_point
+ // ));
+
+ struct header_plus_alpha : public alpha_traits
+ { node header_; };
+
+ struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare>
+ {
+ node_plus_pred_t(const value_compare &comp)
+ : detail::ebo_functor_holder<value_compare>(comp)
+ {}
+ header_plus_alpha header_plus_alpha_;
+ size_traits size_traits_;
+ };
+
+ struct data_t : public sgtree_impl::value_traits
+ {
+ typedef typename sgtree_impl::value_traits value_traits;
+ data_t(const value_compare & comp, const value_traits &val_traits)
+ : value_traits(val_traits), node_plus_pred_(comp)
+ , max_tree_size_(0)
+ {}
+ node_plus_pred_t node_plus_pred_;
+ size_type max_tree_size_;
+ } data_;
+
+ float priv_alpha() const
+ { return this->priv_alpha_traits().get_alpha(); }
+
+ void priv_alpha(float alpha)
+ { return this->priv_alpha_traits().set_alpha(alpha); }
+
+ const value_compare &priv_comp() const
+ { return data_.node_plus_pred_.get(); }
+
+ value_compare &priv_comp()
+ { return data_.node_plus_pred_.get(); }
+
+ const node &priv_header() const
+ { return data_.node_plus_pred_.header_plus_alpha_.header_; }
+
+ node &priv_header()
+ { return data_.node_plus_pred_.header_plus_alpha_.header_; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ { return node_ptr(const_cast<node*>(detail::get_pointer(ptr))); }
+
+ size_traits &priv_size_traits()
+ { return data_.node_plus_pred_.size_traits_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.node_plus_pred_.size_traits_; }
+
+ alpha_traits &priv_alpha_traits()
+ { return data_.node_plus_pred_.header_plus_alpha_; }
+
+ const alpha_traits &priv_alpha_traits() const
+ { return data_.node_plus_pred_.header_plus_alpha_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ h_alpha_t get_h_alpha_func() const
+ { return priv_alpha_traits().get_h_alpha_t(); }
+
+ multiply_by_alpha_t get_alpha_by_max_size_func() const
+ { return priv_alpha_traits().get_multiply_by_alpha_t(); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ typedef typename node_algorithms::insert_commit_data insert_commit_data;
+
+ //! <b>Effects</b>: Constructs an empty tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructorof the value_compare object throws. Basic guarantee.
+ sgtree_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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>
+ sgtree_impl( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called), but the nodes according to
+ //! the value_traits template parameter are reinitialized and thus can be reused.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~sgtree_impl()
+ {}
+
+ //! <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(node_ptr(&priv_header())), 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(const_node_ptr(&priv_header())), 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 (node_ptr(&priv_header()), 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(const_node_ptr(&priv_header())), 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 sgtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sgtree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static sgtree_impl &container_from_end_iterator(iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of sgtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the sgtree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const sgtree_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: it must be a valid iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static sgtree_impl &container_from_iterator(iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <b>Precondition</b>: it must be a valid end const_iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const sgtree_impl &container_from_iterator(const_iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <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(const_node_ptr(&priv_header())); }
+
+ //! <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(const_node_ptr(&priv_header()));
+ }
+ }
+
+ //! <b>Effects</b>: Swaps the contents of two sgtrees.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the comparison functor's swap call throws.
+ void swap(sgtree_impl& other)
+ {
+ //This can throw
+ using std::swap;
+ swap(priv_comp(), priv_comp());
+ swap(priv_alpha_traits(), priv_alpha_traits());
+ swap(data_.max_tree_size_, other.data_.max_tree_size_);
+ //These can't throw
+ node_algorithms::swap_tree(node_ptr(&priv_header()), node_ptr(&other.priv_header()));
+ 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, sgtree_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));
+ this->priv_size_traits().increment();
+ std::size_t max_tree_size = (std::size_t)data_.max_tree_size_;
+ node_ptr p = node_algorithms::insert_equal_upper_bound
+ (node_ptr(&priv_header()), to_insert, key_node_comp
+ , (size_type)this->size(), this->get_h_alpha_func(), max_tree_size);
+ data_.max_tree_size_ = (size_type)max_tree_size;
+ return iterator(p, this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator.
+ //!
+ //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to
+ //! where it will be inserted. If "hint" is the upper_bound
+ //! the insertion takes constant time (two comparisons in the worst case)
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(const_iterator hint, reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, sgtree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ std::size_t max_tree_size = (std::size_t)data_.max_tree_size_;
+ node_ptr p = node_algorithms::insert_equal
+ (node_ptr(&priv_header()), hint.pointed_node(), to_insert, key_node_comp
+ , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
+ data_.max_tree_size_ = (size_type)max_tree_size;
+ return iterator(p, this);
+ }
+
+ //! <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.
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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));
+ this->priv_size_traits().increment();
+ std::size_t max_tree_size = (std::size_t)data_.max_tree_size_;
+ node_algorithms::insert_unique_commit
+ ( node_ptr(&priv_header()), to_insert, commit_data
+ , (std::size_t)this->size(), this->get_h_alpha_func(), max_tree_size);
+ data_.max_tree_size_ = (size_type)max_tree_size;
+ return iterator(to_insert, this);
+ }
+
+ //! <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));
+ std::size_t max_tree_size = data_.max_tree_size_;
+ node_algorithms::erase
+ ( &priv_header(), to_erase, (std::size_t)this->size()
+ , max_tree_size, this->get_alpha_by_max_size_func());
+ data_.max_tree_size_ = (size_type)max_tree_size;
+ this->priv_size_traits().decrement();
+ 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.
+ 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)
+ 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.
+ 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.
+ 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.
+ 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(&priv_header());
+ 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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ node_algorithms::clear_and_dispose(node_ptr(&priv_header())
+ , detail::node_disposer<Disposer, sgtree_impl>(disposer, this));
+ node_algorithms::init_header(&priv_header());
+ 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.
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ return const_iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), 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<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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, sgtree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp));
+ 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 sgtree_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!src.empty()){
+ detail::exception_disposer<sgtree_impl, Disposer>
+ rollback(*this, disposer);
+ node_algorithms::clone
+ (const_node_ptr(&src.priv_header())
+ ,node_ptr(&this->priv_header())
+ ,detail::node_cloner<Cloner, sgtree_impl>(cloner, this)
+ ,detail::node_disposer<Disposer, sgtree_impl>(disposer, this));
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ this->priv_comp() = src.priv_comp();
+ rollback.release();
+ }
+ }
+
+ //! <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
+ (node_ptr(&priv_header())));
+ 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)
+ , node_ptr(&priv_header())
+ , get_real_value_traits().to_node_ptr(with_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 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>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { node_algorithms::rebalance(node_ptr(&priv_header())); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this); }
+
+ //! <b>Returns</b>: The balance factor (alpha) used in this tree
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ float balance_factor() const
+ { return this->priv_alpha(); }
+
+ //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
+ //!
+ //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
+ //! the tree if the new balance factor is stricter (less) than the old factor.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ void balance_factor(float new_alpha)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT((new_alpha > 0.5f && new_alpha < 1.0f));
+ if(new_alpha < 0.5f && new_alpha >= 1.0f) return;
+
+ //The alpha factor CAN't be changed if the fixed, floating operation-less
+ //1/sqrt(2) alpha factor option is activated
+ BOOST_STATIC_ASSERT((floating_point));
+ float old_alpha = this->priv_alpha();
+ this->priv_alpha(new_alpha);
+
+ if(new_alpha < old_alpha){
+ data_.max_tree_size_ = this->size();
+ this->rebalance();
+ }
+ }
+/*
+ //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect,
+ //! if x is not in such a tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This static function is only usable with the "safe mode"
+ //! hook and non-constant time size lists. Otherwise, the user must use
+ //! the non-static "erase(reference )" member. If the user calls
+ //! this function with a non "safe mode" or constant time size list
+ //! a compilation error will be issued.
+ template<class T>
+ static void remove_node(T& value)
+ {
+ //This function is only usable for safe mode hooks and non-constant
+ //time lists.
+ //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size)));
+ BOOST_STATIC_ASSERT((!constant_time_size));
+ BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value));
+ node_ptr to_remove(value_traits::to_node_ptr(value));
+ node_algorithms::unlink_and_rebalance(to_remove);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_remove);
+ }
+*/
+
+ /// @cond
+ private:
+ template<class Disposer>
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase_and_dispose(b++, disposer);
+ return b.unconst();
+ }
+
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase(b++);
+ return b.unconst();
+ }
+ /// @endcond
+
+ private:
+ static sgtree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ header_plus_alpha *r = detail::parent_from_member<header_plus_alpha, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &header_plus_alpha::header_);
+ node_plus_pred_t *n = detail::parent_from_member
+ <node_plus_pred_t, header_plus_alpha>(r, &node_plus_pred_t::header_plus_alpha_);
+ data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_);
+ sgtree_impl *scapegoat = detail::parent_from_member<sgtree_impl, data_t>(d, &sgtree_impl::data_);
+ return *scapegoat;
+ }
+
+ static sgtree_impl &priv_container_from_iterator(const const_iterator &it)
+ { return priv_container_from_end_iterator(it.end_iterator_from_it()); }
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{
+ typedef sgtree_impl<Config> tree_type;
+ typedef typename tree_type::const_iterator const_iterator;
+
+ 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 Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const sgtree_impl<T, Options...> &x, const sgtree_impl<T, Options...> &y)
+#else
+(const sgtree_impl<Config> &x, const sgtree_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(sgtree_impl<T, Options...> &x, sgtree_impl<T, Options...> &y)
+#else
+(sgtree_impl<Config> &x, sgtree_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+/// @cond
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#else
+template<class T, class ...Options>
+#endif
+struct make_sgtree_opt
+{
+ typedef typename pack_options
+ < sg_set_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef sg_setopt
+ < value_traits
+ , typename packed_options::compare
+ , typename packed_options::size_type
+ , packed_options::floating_point
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c sgtree that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_sgtree
+{
+ /// @cond
+ typedef sgtree_impl
+ < typename make_sgtree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class sgtree
+ : public make_sgtree<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_sgtree
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ sgtree( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ sgtree( 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)
+ {}
+
+ static sgtree &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<sgtree &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const sgtree &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const sgtree &>(Base::container_from_end_iterator(end_iterator)); }
+};
+
+#endif
+
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SGTREE_HPP

Added: sandbox/boost/intrusive/sgtree_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/sgtree_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,713 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+//
+// Scapegoat tree algorithms are taken from the paper titled:
+// "Scapegoat Trees" by Igal Galperin Ronald L. Rivest.
+//
+/////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_INTRUSIVE_SGTREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_SGTREE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.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>
+
+
+namespace boost {
+namespace intrusive {
+
+//! sgtree_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_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class sgtree_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;
+
+ /// @cond
+ private:
+
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return tree_algorithms::end_node(header); }
+
+ //! This type is the information that will be
+ //! filled by insert_unique_check
+ struct insert_commit_data
+ : tree_algorithms::insert_commit_data
+ {
+ std::size_t depth;
+ };
+
+ //! <b>Requires</b>: header1 and header2 must be the header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two trees. After the function header1 will contain
+ //! links to the second tree and header2 will have links to the first tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_tree(node_ptr header1, node_ptr header2)
+ { return tree_algorithms::swap_tree(header1, header2); }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::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
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ { tree_algorithms::swap_nodes(node1, header1, node2, header2); }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, 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);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); }
+
+ //! <b>Requires</b>: node is a tree node but not the header.
+ //!
+ //! <b>Effects</b>: Unlinks the node and rebalances the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void unlink(node_ptr node)
+ {
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x))
+ x = NodeTraits::get_parent(x);
+ tree_algorithms::erase(x, node);
+ }
+ }
+
+ //! <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(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_node_ptr node)
+ { return tree_algorithms::unique(node); }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ { return tree_algorithms::count(node); }
+
+ //! <b>Requires</b>: header is the header node of the tree.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes above the header.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t size(const_node_ptr header)
+ { return tree_algorithms::size(header); }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ { return tree_algorithms::next_node(p); }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ { return tree_algorithms::prev_node(p); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ { tree_algorithms::init(node); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ { tree_algorithms::init_header(header); }
+
+ //! <b>Requires</b>: header must be the header of a tree, z a node
+ //! of that tree and z != header.
+ //!
+ //! <b>Effects</b>: Erases node "z" from the tree with header "header".
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class AlphaByMaxSize>
+ static node_ptr erase(node_ptr header, node_ptr z, std::size_t tree_size, std::size_t &max_tree_size, AlphaByMaxSize alpha_by_maxsize)
+ {
+ //typename tree_algorithms::data_for_rebalance info;
+ tree_algorithms::erase(header, z);
+ --tree_size;
+ if (tree_size > 0 &&
+ tree_size < alpha_by_maxsize(max_tree_size)){
+ tree_algorithms::rebalance(header);
+ max_tree_size = tree_size;
+ }
+ return z;
+ }
+
+ //! <b>Requires</b>: "cloner" must be a function
+ //! object taking a node_ptr and returning a new cloned node of it. "disposer" must
+ //! take a node_ptr and shouldn't throw.
+ //!
+ //! <b>Effects</b>: First empties target tree calling
+ //! <tt>void disposer::operator()(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()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ {
+ tree_algorithms::clone(source_header, target_header, 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()(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.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ { tree_algorithms::clear_and_dispose(header, disposer); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::lower_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::upper_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::find(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing
+ //! all elements that are equivalent to "key" according to "comp" or an
+ //! empty range that indicates the position where those elements would be
+ //! if they there are no equivalent elements.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::equal_range(header, key, comp); }
+
+ //! <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, class H_Alpha>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp
+ ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
+ {
+ std::size_t depth;
+ tree_algorithms::insert_equal_upper_bound(h, new_node, comp, &depth);
+ rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: "h" must be the header node of a tree.
+ //! NodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares two node_ptrs.
+ //!
+ //! <b>Effects</b>: Inserts new_node into the tree before the lower bound
+ //! according to "comp".
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class NodePtrCompare, class H_Alpha>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp
+ ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
+ {
+ std::size_t depth;
+ tree_algorithms::insert_equal_lower_bound(h, new_node, comp, &depth);
+ rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! NodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares two node_ptrs. "hint" is node from
+ //! the "header"'s tree.
+ //!
+ //! <b>Effects</b>: Inserts new_node into the tree, using "hint" as a hint to
+ //! where it will be inserted. If "hint" is the upper_bound
+ //! the insertion takes constant time (two comparisons in the worst case).
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if new_node is inserted immediately before "hint".
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class NodePtrCompare, class H_Alpha>
+ static node_ptr insert_equal
+ (node_ptr header, node_ptr hint, node_ptr new_node, NodePtrCompare comp
+ ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
+ {
+ std::size_t depth;
+ tree_algorithms::insert_equal(header, hint, new_node, comp, &depth);
+ rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ std::size_t depth;
+ std::pair<node_ptr, bool> ret =
+ tree_algorithms::insert_unique_check(header, key, comp, commit_data, &depth);
+ commit_data.depth = depth;
+ return ret;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! 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_node_ptr header, node_ptr hint, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ std::size_t depth;
+ std::pair<node_ptr, bool> ret =
+ tree_algorithms::insert_unique_check
+ (header, hint, key, comp, commit_data, &depth);
+ commit_data.depth = depth;
+ return ret;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ template<class H_Alpha>
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_value, const insert_commit_data &commit_data
+ ,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
+ {
+ tree_algorithms::insert_unique_commit(header, new_value, commit_data);
+ rebalance_after_insertion(new_value, commit_data.depth, tree_size+1, h_alpha, max_tree_size);
+ }
+
+ //! <b>Requires</b>: header must be the header of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ static void rebalance(node_ptr header)
+ { tree_algorithms::rebalance(header); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ static node_ptr rebalance_subtree(node_ptr old_root)
+ { return tree_algorithms::rebalance_subtree(old_root); }
+
+ //! <b>Requires</b>: "n" must be a node inserted in a tree.
+ //!
+ //! <b>Effects</b>: Returns a pointer to the header node of the tree.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr get_header(node_ptr n)
+ { return tree_algorithms::get_header(n); }
+
+ /// @cond
+ private:
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is the header of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_header(const_node_ptr p)
+ { return tree_algorithms::is_header(p); }
+
+ template<class H_Alpha>
+ static void rebalance_after_insertion
+ ( node_ptr x, std::size_t depth
+ , std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
+ {
+ if(tree_size > max_tree_size)
+ max_tree_size = tree_size;
+
+ if(tree_size != 1 && depth > h_alpha(tree_size)){
+ //Find the first non height-balanced node
+ //as described in the section 4.2 of the paper.
+ //This method is the alternative method described
+ //in the paper. Authors claim that this method
+ //may tend to yield more balanced trees on the average
+ //than the weight balanced method.
+ node_ptr s = x;
+ std::size_t size = 1;
+
+ for(std::size_t i = 1; true; ++i){
+ bool rebalance = false;
+ if(i == depth){
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(tree_size == count(s));
+ rebalance = true;
+ }
+ else if(i > h_alpha(size)){
+ node_ptr s_parent = NodeTraits::get_parent(s);
+ node_ptr s_parent_left = NodeTraits::get_left(s_parent);
+ size += 1 + tree_algorithms::count
+ ( s_parent_left == s ? NodeTraits::get_right(s_parent) : s_parent_left );
+ s = s_parent;
+ rebalance = true;
+ }
+ if(rebalance){
+ rebalance_subtree(s);
+ break;
+ }
+ }
+ }
+ }
+
+ /// @endcond
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SGTREE_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/slist.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/slist.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1962 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_SLIST_HPP
+#define BOOST_INTRUSIVE_SLIST_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/slist_hook.hpp>
+#include <boost/intrusive/circular_slist_algorithms.hpp>
+#include <boost/intrusive/linear_slist_algorithms.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <iterator>
+#include <functional>
+#include <algorithm>
+#include <cstddef> //std::size_t
+#include <utility> //std::pair
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class ValueTraits, class SizeType, bool ConstantTimeSize, bool Linear, bool CacheLast>
+struct slistopt
+{
+ typedef ValueTraits value_traits;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+ static const bool linear = Linear;
+ static const bool cache_last = CacheLast;
+};
+
+template<class Node, class NodePtr, bool>
+struct root_plus_last
+{
+ Node root_;
+ NodePtr last_;
+};
+
+template<class Node, class NodePtr>
+struct root_plus_last<Node, NodePtr, false>
+{
+ Node root_;
+};
+
+template <class T>
+struct slist_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_slist_hook>
+ , constant_time_size<true>
+ , linear<false>
+ , size_type<std::size_t>
+ , cache_last<false>
+ >::type
+{};
+
+/// @endcond
+
+//! The class template slist is an intrusive container, that encapsulates
+//! a singly-linked list. You can use such a list to squeeze the last bit
+//! of performance from your application. Unfortunately, the little gains
+//! come with some huge drawbacks. A lot of member functions can't be
+//! implemented as efficiently as for standard containers. To overcome
+//! this limitation some other member functions with rather unusual semantics
+//! have to be introduced.
+//!
+//! 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<>,
+//! \c linear<> and \c cache_last<>.
+//!
+//! The iterators of slist are forward iterators. slist provides a static
+//! function called "previous" to compute the previous iterator of a given iterator.
+//! This function has linear complexity. To improve the usability esp. with
+//! the '*_after' functions, ++end() == begin() and previous(begin()) == end()
+//! are defined. An new special function "before_begin()" is defined, which returns
+//! an iterator that points one less the beginning of the list: ++before_begin() == begin()
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class slist_impl
+ : private detail::clear_on_destructor_base<slist_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ //Public typedefs
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+ typedef typename Config::size_type size_type;
+ typedef slist_iterator<slist_impl, false> iterator;
+ typedef slist_iterator<slist_impl, true> const_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <pointer, const node>::type const_node_ptr;
+ typedef typename detail::if_c
+ < Config::linear
+ , linear_slist_algorithms<node_traits>
+ , circular_slist_algorithms<node_traits>
+ >::type node_algorithms;
+
+ static const bool constant_time_size = Config::constant_time_size;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<slist_impl>::value;
+ static const bool linear = Config::linear;
+ static const bool cache_last = Config::cache_last;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //! This class is
+ //! non-copyable
+ slist_impl (const slist_impl&);
+
+ //! This class is
+ //! non-asignable
+ slist_impl &operator =(const slist_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+ //Linear singly linked lists are incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(linear && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+ //A list with cached last node is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(cache_last && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ node_ptr get_end_node()
+ { return node_ptr(linear ? node_ptr(0) : this->get_root_node()); }
+
+ const_node_ptr get_end_node() const
+ {
+ return const_node_ptr
+ (linear ? const_node_ptr(0) : this->get_root_node()); }
+
+ node_ptr get_root_node()
+ { return node_ptr(&data_.root_plus_size_.root_); }
+
+ const_node_ptr get_root_node() const
+ { return const_node_ptr(&data_.root_plus_size_.root_); }
+
+ node_ptr get_last_node()
+ { return this->get_last_node(detail::bool_<cache_last>()); }
+
+ const_node_ptr get_last_node() const
+ { return this->get_last_node(detail::bool_<cache_last>()); }
+
+ void set_last_node(node_ptr n)
+ { return this->set_last_node(n, detail::bool_<cache_last>()); }
+
+ static node_ptr get_last_node(detail::bool_<false>)
+ { return node_ptr(0); }
+
+ static void set_last_node(node_ptr, detail::bool_<false>)
+ {}
+
+ node_ptr get_last_node(detail::bool_<true>)
+ { return node_ptr(data_.root_plus_size_.last_); }
+
+ const_node_ptr get_last_node(detail::bool_<true>) const
+ { return const_node_ptr(data_.root_plus_size_.last_); }
+
+ void set_last_node(node_ptr n, detail::bool_<true>)
+ { data_.root_plus_size_.last_ = n; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ { return node_ptr(const_cast<node*>(detail::get_pointer(ptr))); }
+
+ void set_default_constructed_state()
+ {
+ node_algorithms::init_header(this->get_root_node());
+ this->priv_size_traits().set_size(size_type(0));
+ if(cache_last){
+ this->set_last_node(this->get_root_node());
+ }
+ }
+
+ struct root_plus_size
+ : public size_traits
+ , public root_plus_last<node, node_ptr, cache_last>
+ {};
+
+ struct data_t
+ : public slist_impl::value_traits
+ {
+ typedef typename slist_impl::value_traits value_traits;
+ data_t(const value_traits &val_traits)
+ : value_traits(val_traits)
+ {}
+
+ root_plus_size root_plus_size_;
+ } data_;
+
+ size_traits &priv_size_traits()
+ { return data_.root_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.root_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ public:
+ //! <b>Effects</b>: constructs an empty list.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
+ slist_impl(const value_traits &v_traits = value_traits())
+ : data_(v_traits)
+ { this->set_default_constructed_state(); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Constructs a list equal to [first,last).
+ //!
+ //! <b>Complexity</b>: Linear in std::distance(b, e). No copy constructors are called.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks).
+ template<class Iterator>
+ slist_impl(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
+ : data_(v_traits)
+ {
+ this->set_default_constructed_state();
+ this->insert_after(this->cbefore_begin(), b, e);
+ }
+
+ //! <b>Effects</b>: If it's a safe-mode
+ //! or auto-unlink value, the destructor does nothing
+ //! (ie. no code is generated). Otherwise it detaches all elements from this.
+ //! In this case the objects in the list are not deleted (i.e. no destructors
+ //! are called), but the hooks according to the value_traits template parameter
+ //! are set to their default value.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements in the list, if
+ //! it's a safe-mode or auto-unlink value. Otherwise constant.
+ ~slist_impl()
+ {}
+
+ //! <b>Effects</b>: Erases all the elements of the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements of the list.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased elements.
+ void clear()
+ {
+ if(safemode_or_autounlink){
+ this->clear_and_dispose(detail::null_disposer());
+ }
+ else{
+ this->set_default_constructed_state();
+ }
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements of the container
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements of the list.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased elements.
+ template <class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ const_iterator it(this->begin()), itend(this->end());
+ while(it != itend){
+ node_ptr to_erase(it.pointed_node());
+ ++it;
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ }
+ this->set_default_constructed_state();
+ }
+
+ //! <b>Requires</b>: value must be an lvalue.
+ //!
+ //! <b>Effects</b>: Inserts the value in the front of the list.
+ //! No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void push_front(reference value)
+ {
+ node_ptr to_insert = get_real_value_traits().to_node_ptr(value);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(to_insert));
+ if(cache_last){
+ if(this->empty()){
+ this->set_last_node(to_insert);
+ }
+ }
+ node_algorithms::link_after(this->get_root_node(), to_insert);
+ this->priv_size_traits().increment();
+ }
+
+ //! <b>Requires</b>: value must be an lvalue.
+ //!
+ //! <b>Effects</b>: Inserts the value in the back of the list.
+ //! No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! This function is only available is cache_last<> is true.
+ void push_back(reference value)
+ {
+ BOOST_STATIC_ASSERT((cache_last != 0));
+ this->insert_after(const_iterator(this->get_last_node(), this), value);
+ }
+
+ //! <b>Effects</b>: Erases the first element of the list.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the erased element.
+ void pop_front()
+ { return this->pop_front_and_dispose(detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the first element of the list.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template<class Disposer>
+ void pop_front_and_dispose(Disposer disposer)
+ {
+ node_ptr to_erase = node_traits::get_next(this->get_root_node());
+ node_algorithms::unlink_after(this->get_root_node());
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ if(cache_last){
+ if(this->empty()){
+ this->set_last_node(this->get_root_node());
+ }
+ }
+ }
+
+ //! <b>Effects</b>: Returns a reference to the first element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ reference front()
+ { return *this->get_real_value_traits().to_value_ptr(node_traits::get_next(this->get_root_node())); }
+
+ //! <b>Effects</b>: Returns a const_reference to the first element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_reference front() const
+ { return *this->get_real_value_traits().to_value_ptr(uncast(node_traits::get_next(this->get_root_node()))); }
+
+ //! <b>Effects</b>: Returns a reference to the last element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! This function is only available is cache_last<> is true.
+ reference back()
+ {
+ BOOST_STATIC_ASSERT((cache_last != 0));
+ return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
+ }
+
+ //! <b>Effects</b>: Returns a const_reference to the last element of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! This function is only available is cache_last<> is true.
+ const_reference back() const
+ {
+ BOOST_STATIC_ASSERT((cache_last != 0));
+ return *this->get_real_value_traits().to_value_ptr(this->get_last_node());
+ }
+
+ //! <b>Effects</b>: Returns an iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator begin()
+ { return iterator (node_traits::get_next(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator begin() const
+ { return const_iterator (node_traits::get_next(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the first element contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cbegin() const
+ { return const_iterator(node_traits::get_next(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns an iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator end()
+ { return iterator(this->get_end_node(), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator end() const
+ { return const_iterator(uncast(this->get_end_node()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator to the end of the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cend() const
+ { return this->end(); }
+
+ //! <b>Effects</b>: Returns an iterator that points to a position
+ //! before the first element. Equivalent to "end()"
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ iterator before_begin()
+ { return iterator(this->get_root_node(), this); }
+
+ //! <b>Effects</b>: Returns an iterator that points to a position
+ //! before the first element. Equivalent to "end()"
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator before_begin() const
+ { return const_iterator(uncast(this->get_root_node()), this); }
+
+ //! <b>Effects</b>: Returns an iterator that points to a position
+ //! before the first element. Equivalent to "end()"
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ const_iterator cbefore_begin() const
+ { return this->before_begin(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of slist.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static slist_impl &container_from_end_iterator(iterator end_iterator)
+ { return slist_impl::priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of slist.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the slist associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const slist_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return slist_impl::priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Effects</b>: Returns the number of the elements contained in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements contained in the list.
+ //! if constant_time_size is false. Constant time otherwise.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ size_type size() const
+ {
+ if(constant_time_size)
+ return this->priv_size_traits().get_size();
+ else
+ return node_algorithms::count(this->get_root_node()) - 1;
+ }
+
+ //! <b>Effects</b>: Returns true if the list contains no elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ bool empty() const
+ { return node_algorithms::unique(this->get_root_node()); }
+
+ //! <b>Effects</b>: Swaps the elements of x and *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements of both lists.
+ //! Constant-time if linear<> and/or cache_last<> options are used.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void swap(slist_impl& other)
+ {
+ if(cache_last){
+ this->priv_swap_cache_last(other);
+ }
+ else{
+ this->priv_swap_lists(this->get_root_node(), other.get_root_node(), detail::bool_<linear>());
+ }
+ 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>Effects</b>: Moves backwards all the elements, so that the first
+ //! element becomes the second, the second becomes the third...
+ //! the last element becomes the first one.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
+ //!
+ //! <b>Note</b>: Iterators Does not affect the validity of iterators and references.
+ void shift_backwards(size_type n = 1)
+ { this->priv_shift_backwards(n, detail::bool_<linear>()); }
+
+ //! <b>Effects</b>: Moves forward all the elements, so that the second
+ //! element becomes the first, the third becomes the second...
+ //! the first element becomes the last one.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements plus the number shifts.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ void shift_forward(size_type n = 1)
+ { this->priv_shift_forward(n, detail::bool_<linear>()); }
+
+ //! <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.
+ //!
+ //! 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.
+ template <class Cloner, class Disposer>
+ void clone_from(const slist_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ detail::exception_disposer<slist_impl, Disposer>
+ rollback(*this, disposer);
+ const_iterator prev(this->cbefore_begin());
+ const_iterator b(src.begin()), e(src.end());
+ for(; b != e; ++b){
+ prev = this->insert_after(prev, *cloner(*b));
+ }
+ rollback.release();
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and prev_p must point to an element
+ //! contained by the list or to end().
+ //!
+ //! <b>Effects</b>: Inserts the value after the position pointed by prev_p.
+ //! No copy constructor is called.
+ //!
+ //! <b>Returns</b>: An iterator to the inserted element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ iterator insert_after(const_iterator prev_p, reference value)
+ {
+ node_ptr n = get_real_value_traits().to_node_ptr(value);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
+ node_ptr prev_n(prev_p.pointed_node());
+ node_algorithms::link_after(prev_n, n);
+ if(cache_last && (this->get_last_node() == prev_n)){
+ this->set_last_node(n);
+ }
+ this->priv_size_traits().increment();
+ return iterator (n, this);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type and prev_p must point to an element
+ //! contained by the list or to the end node.
+ //!
+ //! <b>Effects</b>: Inserts the [first, last)
+ //! after the position prev_p.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ template<class Iterator>
+ void insert_after(const_iterator prev_p, Iterator first, Iterator last)
+ {
+ for (; first != last; ++first)
+ prev_p = this->insert_after(prev_p, *first);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and p must point to an element
+ //! contained by the list or to end().
+ //!
+ //! <b>Effects</b>: Inserts the value before the position pointed by p.
+ //! No copy constructor is called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements before p.
+ //! Constant-time if cache_last<> is true and p == end().
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ iterator insert(const_iterator p, reference value)
+ { return this->insert_after(this->previous(p), value); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type and p must point to an element
+ //! contained by the list or to the end node.
+ //!
+ //! <b>Effects</b>: Inserts the pointed by b and e
+ //! before the position p. No copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted plus linear
+ //! to the elements before b.
+ //! Linear to the number of elements to insert if cache_last<> option is true and p == end().
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ template<class Iterator>
+ void insert(const_iterator p, Iterator b, Iterator e)
+ { return this->insert_after(this->previous(p), b, e); }
+
+ //! <b>Effects</b>: Erases the element after the element pointed by prev of
+ //! the list. No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase_after(const_iterator prev)
+ { return this->erase_after_and_dispose(prev, detail::null_disposer()); }
+
+ //! <b>Effects</b>: Erases the range (before_first, last) from
+ //! the list. No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of erased elements if it's a safe-mode
+ //! , auto-unlink value or constant-time size is activated. Constant time otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase_after(const_iterator before_first, const_iterator last)
+ {
+ if(safemode_or_autounlink || constant_time_size){
+ return this->erase_after_and_dispose(before_first, last, detail::null_disposer());
+ }
+ else{
+ node_ptr bfp = before_first.pointed_node();
+ node_ptr lp = last.pointed_node();
+ if(cache_last){
+ if((lp == this->get_end_node())){
+ this->set_last_node(bfp);
+ }
+ }
+ node_algorithms::unlink_after(bfp, lp);
+ return last.unconst();
+ }
+ }
+
+ //! <b>Effects</b>: Erases the range (before_first, last) from
+ //! the list. n must be std::distance(before_first, last) - 1.
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: constant-time if link_mode is normal_link.
+ //! Linear to the elements (last - before_first) otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase_after(const_iterator before_first, const_iterator last, difference_type n)
+ {
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(++const_iterator(before_first), last) == difference_type(n));
+ if(safemode_or_autounlink){
+ return this->erase_after(before_first, last);
+ }
+ else{
+ node_ptr bfp = before_first.pointed_node();
+ node_ptr lp = last.pointed_node();
+ if(cache_last){
+ if((lp == this->get_end_node())){
+ this->set_last_node(bfp);
+ }
+ }
+ node_algorithms::unlink_after(bfp, lp);
+ if(constant_time_size){
+ this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
+ }
+ return last.unconst();
+ }
+ }
+
+ //! <b>Effects</b>: Erases the element pointed by i of the list.
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed element,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements before i.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase(const_iterator i)
+ { return this->erase_after(this->previous(i)); }
+
+ //! <b>Requires</b>: first and last must be valid iterator to elements in *this.
+ //!
+ //! <b>Effects</b>: Erases the range pointed by b and e.
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements before last.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased elements.
+ iterator erase(const_iterator first, const_iterator last)
+ { return this->erase_after(this->previous(first), last); }
+
+ //! <b>Effects</b>: Erases the range [first, last) from
+ //! the list. n must be std::distance(first, last).
+ //! No destructors are called.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: linear to the elements before first if link_mode is normal_link
+ //! and constant_time_size is activated. Linear to the elements before last otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ iterator erase(const_iterator first, const_iterator last, difference_type n)
+ { return this->erase_after(this->previous(first), last, n); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the element after the element pointed by prev of
+ //! the list.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template<class Disposer>
+ iterator erase_after_and_dispose(const_iterator prev, Disposer disposer)
+ {
+ const_iterator it(prev);
+ ++it;
+ node_ptr to_erase(it.pointed_node());
+ ++it;
+ node_ptr prev_n(prev.pointed_node());
+ node_algorithms::unlink_after(prev_n);
+ if(cache_last && (to_erase == this->get_last_node())){
+ this->set_last_node(prev_n);
+ }
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ this->priv_size_traits().decrement();
+ return it.unconst();
+ }
+
+ /// @cond
+
+ template<class Disposer>
+ static iterator s_erase_after_and_dispose(const_iterator prev, Disposer disposer)
+ {
+ BOOST_STATIC_ASSERT(((!cache_last)&&(!constant_time_size)&&(!stateful_value_traits)));
+ const_iterator it(prev);
+ ++it;
+ node_ptr to_erase(it.pointed_node());
+ ++it;
+ node_ptr prev_n(prev.pointed_node());
+ node_algorithms::unlink_after(prev_n);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(real_value_traits::to_value_ptr(to_erase));
+ return it.unconst();
+ }
+
+ static iterator s_erase_after(const_iterator prev)
+ { return s_erase_after_and_dispose(prev, detail::null_disposer()); }
+
+ /// @endcond
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the range (before_first, last) from
+ //! the list.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Lineal to the elements (last - before_first + 1).
+ //!
+ //! <b>Note</b>: Invalidates the iterators to the erased element.
+ template<class Disposer>
+ iterator erase_after_and_dispose(const_iterator before_first, const_iterator last, Disposer disposer)
+ {
+ node_ptr bfp(before_first.pointed_node()), lp(last.pointed_node());
+ node_ptr fp(node_traits::get_next(bfp));
+ node_algorithms::unlink_after(bfp, lp);
+ while(fp != lp){
+ node_ptr to_erase(fp);
+ fp = node_traits::get_next(fp);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ this->priv_size_traits().decrement();
+ }
+ if(cache_last && (node_traits::get_next(bfp) == this->get_end_node())){
+ this->set_last_node(bfp);
+ }
+ return last.unconst();
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the element pointed by i of the list.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed element,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements before i.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased element.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator i, Disposer disposer)
+ { return this->erase_after_and_dispose(this->previous(i), disposer); }
+
+ #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>: first and last must be valid iterator to elements in *this.
+ //! Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the range pointed by b and e.
+ //! No destructors are called.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: the first element remaining beyond the removed elements,
+ //! or end() if no such element exists.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of erased elements plus linear
+ //! to the elements before first.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references) to the
+ //! erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator first, const_iterator last, Disposer disposer)
+ { return this->erase_after_and_dispose(this->previous(first), last, disposer); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
+ //! No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted plus
+ //! linear to the elements contained in the list if it's a safe-mode
+ //! or auto-unlink value.
+ //! Linear to the number of elements inserted in the list otherwise.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements.
+ template<class Iterator>
+ void assign(Iterator b, Iterator e)
+ {
+ this->clear();
+ this->insert_after(this->cbefore_begin(), b, e);
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Requires</b>: Dereferencing iterator must yield
+ //! an lvalue of type value_type.
+ //!
+ //! <b>Effects</b>: Clears the list and inserts the range pointed by b and e.
+ //! No destructors or copy constructors are called.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements inserted plus
+ //! linear to the elements contained in the list.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements.
+ template<class Iterator, class Disposer>
+ void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
+ {
+ this->clear_and_dispose(disposer);
+ this->insert_after(this->cbefore_begin(), b, e, disposer);
+ }
+
+ //! <b>Requires</b>: prev is an iterator to an element or x.end()/x.before_begin() in x.
+ //!
+ //! <b>Effects</b>: Transfers all the elements of list x to this list, after the
+ //! the element pointed by prev. No destructors or copy constructors are called.
+ //!
+ //! <b>Returns</b>: The last element inserted of x or prev if x is empty.
+ //! This iterator can be used as new "prev" iterator for a new splice_after call.
+ //! that will splice new values after the previously spliced values.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements contained in x.
+ //! Constant-time if cache_last<> option is true.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ iterator splice_after(const_iterator prev, slist_impl &x)
+ {
+ if (!x.empty()){
+ const_iterator last_x(x.previous(x.end())); //<- constant time if cache_last is active
+ node_ptr prev_n(prev.pointed_node());
+ node_ptr last_x_n(last_x.pointed_node());
+ if(cache_last){
+ x.set_last_node(x.get_root_node());
+ if(node_traits::get_next(prev_n) == this->get_end_node()){
+ this->set_last_node(last_x_n);
+ }
+ }
+ node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
+ this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size());
+ x.priv_size_traits().set_size(size_type(0));
+ return last_x.unconst();
+ }
+ else{
+ return prev.unconst();
+ }
+ }
+
+ //! <b>Requires</b>: prev must point to an element contained by this list or
+ //! to the before_begin() element. prev_ele must point to an element contained in list
+ //! x or must be x.before_begin().
+ //!
+ //! <b>Effects</b>: Transfers the element after prev_ele, from list x to this list,
+ //! after the element pointed by prev. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator prev_ele)
+ {
+ const_iterator elem = prev_ele;
+ this->splice_after(prev_pos, x, prev_ele, ++elem, 1);
+ }
+
+ //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
+ //! before_begin(), and before_first and before_last belong to x and
+ //! ++before_first != x.end() && before_last != x.end().
+ //!
+ //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this
+ //! list, after the element pointed by prev_pos.
+ //! No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements transferred
+ //! if constant_time_size is true. Constant-time otherwise.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last)
+ {
+ if(constant_time_size)
+ this->splice_after(prev_pos, x, before_first, before_last, std::distance(before_first, before_last));
+ else
+ this->priv_splice_after
+ (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node());
+ }
+
+ //! <b>Requires</b>: prev_pos must be a dereferenceable iterator in *this or be
+ //! before_begin(), and before_first and before_last belong to x and
+ //! ++before_first != x.end() && before_last != x.end() and
+ //! n == std::distance(before_first, before_last).
+ //!
+ //! <b>Effects</b>: Transfers the range (before_first, before_last] from list x to this
+ //! list, after the element pointed by p. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice_after(const_iterator prev_pos, slist_impl &x, const_iterator before_first, const_iterator before_last, difference_type n)
+ {
+ if(n){
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(std::distance(before_first, before_last) == n);
+ this->priv_splice_after
+ (prev_pos.pointed_node(), x, before_first.pointed_node(), before_last.pointed_node());
+ if(constant_time_size){
+ this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
+ x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: it is an iterator to an element in x.
+ //!
+ //! <b>Effects</b>: Transfers all the elements of list x to this list, before the
+ //! the element pointed by it. No destructors or copy constructors are called.
+ //!
+ //! <b>Returns</b>: The last element inserted of x or the previous element
+ //! of it if x is empty.
+ //! This iterator can be used as new "prev" iterator for a new splice call.
+ //! that will splice new values after the previously spliced values.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements contained in x plus linear to
+ //! the elements before it.
+ //! Linear to the elements before it if cache_last<> option is true.
+ //! Constant-time if cache_last<> option is true and it == end().
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ iterator splice(const_iterator it, slist_impl &x)
+ { return this->splice_after(this->previous(it), x); }
+
+ //! <b>Requires</b>: it p must be a valid iterator of *this.
+ //! elem must point to an element contained in list
+ //! x.
+ //!
+ //! <b>Effects</b>: Transfers the element elem, from list x to this list,
+ //! before the element pointed by pos. No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements before pos and before elem.
+ //! Linear to the elements before elem if cache_last<> option is true and pos == end().
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator pos, slist_impl &x, const_iterator elem)
+ { return this->splice_after(this->previous(pos), x, x.previous(elem)); }
+
+ //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
+ //! and first and last belong to x and first and last a valid range on x.
+ //!
+ //! <b>Effects</b>: Transfers the range [first, last) from list x to this
+ //! list, before the element pointed by pos.
+ //! No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last
+ //! plus linear to the number of elements transferred if constant_time_size is true.
+ //! Linear to the sum of elements before first, and last
+ //! plus linear to the number of elements transferred if constant_time_size is true
+ //! if cache_last<> is true and pos == end()
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last)
+ { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last)); }
+
+ //! <b>Requires</b>: pos must be a dereferenceable iterator in *this
+ //! and first and last belong to x and first and last a valid range on x.
+ //! n == std::distance(first, last).
+ //!
+ //! <b>Effects</b>: Transfers the range [first, last) from list x to this
+ //! list, before the element pointed by pos.
+ //! No destructors or copy constructors are called.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the sum of elements before pos, first, and last.
+ //! Linear to the sum of elements before first and last
+ //! if cache_last<> is true and pos == end().
+ //!
+ //! <b>Note</b>: Iterators of values obtained from list x now point to elements of this
+ //! list. Iterators of this list and all the references are not invalidated.
+ void splice(const_iterator pos, slist_impl &x, const_iterator first, const_iterator last, difference_type n)
+ { return this->splice_after(this->previous(pos), x, x.previous(first), x.previous(last), n); }
+
+ //! <b>Effects</b>: This function sorts the list *this according to std::less<value_type>.
+ //! The sort is stable, that is, the relative order of equivalent elements is preserved.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the predicate throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: The number of comparisons is approximately N log N, where N
+ //! is the list's size.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated
+ template<class Predicate>
+ void sort(Predicate p)
+ {
+ if (node_traits::get_next(node_traits::get_next(this->get_root_node()))
+ != this->get_root_node()) {
+ slist_impl carry;
+ slist_impl counter[64];
+ int fill = 0;
+ const_iterator last_inserted;
+ while(!this->empty()){
+ last_inserted = this->cbegin();
+ carry.splice_after(carry.cbefore_begin(), *this, this->cbefore_begin());
+ int i = 0;
+ while(i < fill && !counter[i].empty()) {
+ last_inserted = carry.merge(counter[i++], p);
+ }
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(counter[i].empty());
+
+ node_ptr p = node_algorithms::get_previous_node
+ (last_inserted.pointed_node(), carry.cend().pointed_node());
+ const_iterator last_element(p, this);
+ if(constant_time_size){
+ counter[i].splice_after( counter[i].cbefore_begin(), carry
+ , carry.cbefore_begin(), last_element
+ , carry.size());
+ }
+ else{
+ counter[i].splice_after( counter[i].cbefore_begin(), carry
+ , carry.cbefore_begin(), last_element);
+ }
+ if(i == fill)
+ ++fill;
+ }
+
+ for (int i = 1; i < fill; ++i)
+ last_inserted = counter[i].merge(counter[i-1], p);
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(this->empty());
+
+ node_ptr p = node_algorithms::get_previous_node
+ (last_inserted.pointed_node(), counter[--fill].end().pointed_node());
+ const_iterator last_element(p, this);
+ if(constant_time_size){
+ this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
+ , last_element, counter[fill].size());
+ }
+ else{
+ this->splice_after( cbefore_begin(), counter[fill], counter[fill].cbefore_begin()
+ , last_element);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: p must be a comparison function that induces a strict weak
+ //! ordering and both *this and x must be sorted according to that ordering
+ //! The lists x and *this must be distinct.
+ //!
+ //! <b>Effects</b>: This function removes all of x's elements and inserts them
+ //! in order into *this. The merge is stable; that is, if an element from *this is
+ //! equivalent to one from x, then the element from *this will precede the one from x.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or std::less<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: This function is linear time: it performs at most
+ //! size() + x.size() - 1 comparisons.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ void sort()
+ { this->sort(std::less<value_type>()); }
+
+ //! <b>Requires</b>: p must be a comparison function that induces a strict weak
+ //! ordering and both *this and x must be sorted according to that ordering
+ //! The lists x and *this must be distinct.
+ //!
+ //! <b>Effects</b>: This function removes all of x's elements and inserts them
+ //! in order into *this. The merge is stable; that is, if an element from *this is
+ //! equivalent to one from x, then the element from *this will precede the one from x.
+ //!
+ //! <b>Returns</b>: An iterator to the last transferred value, end() is x is empty.
+ //!
+ //! <b>Throws</b>: If the predicate throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: This function is linear time: it performs at most
+ //! size() + x.size() - 1 comparisons.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ template<class Predicate>
+ iterator merge(slist_impl& x, Predicate p)
+ {
+ const_iterator a(cbefore_begin()), e(cend()), ax(x.cbefore_begin()), ex(x.cend());
+ const_iterator last_inserted(e);
+ const_iterator a_next;
+ while(++(a_next = a) != e && !x.empty()) {
+ const_iterator ix(ax);
+ const_iterator cx;
+ size_type n(0);
+ while(++(cx = ix) != ex && p(*cx, *a_next)){
+ ++ix; ++n;
+ }
+ if(ax != ix){
+ this->splice_after(a, x, ax, ix, n);
+ last_inserted = ix;
+ }
+ a = a_next;
+ }
+ if (!x.empty()){
+ last_inserted = this->splice_after(a, x);
+ }
+ return last_inserted.unconst();
+ }
+
+ //! <b>Effects</b>: This function removes all of x's elements and inserts them
+ //! in order into *this according to std::less<value_type>. The merge is stable;
+ //! that is, if an element from *this is equivalent to one from x, then the element
+ //! from *this will precede the one from x.
+ //!
+ //! <b>Throws</b>: if std::less<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: This function is linear time: it performs at most
+ //! size() + x.size() - 1 comparisons.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated
+ void merge(slist_impl& x)
+ { this->merge(x, std::less<value_type>()); }
+
+ //! <b>Effects</b>: Reverses the order of elements in the list.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: This function is linear to the contained elements.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated
+ void reverse()
+ {
+ if(cache_last && !this->empty()){
+ this->set_last_node(node_traits::get_next(this->get_root_node()));
+ }
+ this->priv_reverse(detail::bool_<linear>());
+ }
+
+ //! <b>Effects</b>: Removes all the elements that compare equal to value.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid. This function is
+ //! linear time: it performs exactly size() comparisons for equality.
+ void remove(const_reference value)
+ { this->remove_if(detail::equal_to_value<const_reference>(value)); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes all the elements that compare equal to value.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Disposer>
+ void remove_and_dispose(const_reference value, Disposer disposer)
+ { this->remove_and_dispose_if(detail::equal_to_value<const_reference>(value), disposer); }
+
+ //! <b>Effects</b>: Removes all the elements for which a specified
+ //! predicate is satisfied. No destructors are called.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Pred>
+ void remove_if(Pred pred)
+ { this->remove_and_dispose_if(pred, detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes all the elements for which a specified
+ //! predicate is satisfied.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If pred throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Pred, class Disposer>
+ void remove_and_dispose_if(Pred pred, Disposer disposer)
+ {
+ const_iterator bcur(this->before_begin()), cur(this->begin()), e(this->end());
+
+ while(cur != e){
+ if (pred(*cur)){
+ cur = this->erase_after_and_dispose(bcur, disposer);
+ }
+ else{
+ bcur = cur;
+ ++cur;
+ }
+ }
+ if(cache_last){
+ this->set_last_node(bcur.pointed_node());
+ }
+ }
+
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that are equal from the list. No destructors are called.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons calls to pred()).
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ void unique()
+ { this->unique_and_dispose(std::equal_to<value_type>(), detail::null_disposer()); }
+
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that satisfy some binary predicate from the list.
+ //! No destructors are called.
+ //!
+ //! <b>Throws</b>: If the predicate throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class BinaryPredicate>
+ void unique(BinaryPredicate pred)
+ { this->unique_and_dispose(pred, detail::null_disposer()); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that satisfy some binary predicate from the list.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If std::equal_to<value_type> throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class Disposer>
+ void unique_and_dispose(Disposer disposer)
+ { this->unique(std::equal_to<value_type>(), disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
+ //! elements that satisfy some binary predicate from the list.
+ //! Disposer::operator()(pointer) is called for every removed element.
+ //!
+ //! <b>Throws</b>: If the predicate throws. Basic guarantee.
+ //!
+ //! <b>Complexity</b>: Linear time (size()-1) comparisons equality comparisons.
+ //!
+ //! <b>Note</b>: The relative order of elements that are not removed is unchanged,
+ //! and iterators to elements that are not removed remain valid.
+ template<class BinaryPredicate, class Disposer>
+ void unique_and_dispose(BinaryPredicate pred, Disposer disposer)
+ {
+ const_iterator end_n(this->cend());
+ const_iterator bcur(this->cbegin());
+ if(bcur != end_n){
+ const_iterator cur(bcur);
+ ++cur;
+ while(cur != end_n) {
+ if (pred(*bcur, *cur)){
+ cur = this->erase_after_and_dispose(bcur, disposer);
+ }
+ else{
+ bcur = cur;
+ ++cur;
+ }
+ }
+ if(cache_last){
+ this->set_last_node(bcur.pointed_node());
+ }
+ }
+ }
+
+ //! <b>Requires</b>: value must be a reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns a const_iterator pointing to the element
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ //! 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));
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
+ return iterator (value_traits::to_node_ptr(value), 0);
+ }
+
+ //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns an iterator pointing to the element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ //! 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));
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
+ return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0);
+ }
+
+ //! <b>Requires</b>: value must be a reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns a const_iterator pointing to the element
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ iterator iterator_to(reference value)
+ {
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(value)));
+ return iterator (value_traits::to_node_ptr(value), this);
+ }
+
+ //! <b>Requires</b>: value must be a const reference to a value inserted in a list.
+ //!
+ //! <b>Effects</b>: This function returns an iterator pointing to the element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: Iterators and references are not invalidated.
+ const_iterator iterator_to(const_reference value) const
+ {
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT (!node_algorithms::inited(value_traits::to_node_ptr(const_cast<reference> (value))));
+ return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this);
+ }
+
+ //! <b>Returns</b>: The iterator to the element before i in the list.
+ //! Returns the end-iterator, if either i is the begin-iterator or the
+ //! list is empty.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements before i.
+ //! Constant if cache_last<> is true and i == end().
+ iterator previous(iterator i)
+ {
+ if(cache_last && (i.pointed_node() == this->get_end_node())){
+ return iterator(this->get_last_node(), this);
+ }
+ return iterator
+ (node_algorithms::get_previous_node
+ (this->before_begin().pointed_node(), i.pointed_node()), this);
+ }
+
+ //! <b>Returns</b>: The const_iterator to the element before i in the list.
+ //! Returns the end-const_iterator, if either i is the begin-const_iterator or
+ //! the list is empty.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements before i.
+ //! Constant if cache_last<> is true and i == end().
+ const_iterator previous(const_iterator i) const
+ {
+ if(cache_last && (i.pointed_node() == this->get_end_node())){
+ return const_iterator(uncast(this->get_last_node()), this);
+ }
+ return const_iterator
+ (node_algorithms::get_previous_node
+ (this->before_begin().pointed_node(), i.pointed_node()), this);
+ }
+
+ private:
+ void priv_splice_after(node_ptr prev_pos_n, slist_impl &x, node_ptr before_first_n, node_ptr before_last_n)
+ {
+ if (before_first_n != before_last_n && prev_pos_n != before_first_n && prev_pos_n != before_last_n)
+ {
+ if(cache_last){
+ if(node_traits::get_next(prev_pos_n) == this->get_end_node()){
+ this->set_last_node(before_last_n);
+ }
+ if(node_traits::get_next(before_last_n) == x.get_end_node()){
+ x.set_last_node(before_first_n);
+ }
+ }
+ node_algorithms::transfer_after(prev_pos_n, before_first_n, before_last_n);
+ }
+ }
+
+ void priv_reverse(detail::bool_<false>)
+ { node_algorithms::reverse(this->get_root_node()); }
+
+ void priv_reverse(detail::bool_<true>)
+ {
+ node_ptr new_first = node_algorithms::reverse
+ (node_traits::get_next(this->get_root_node()));
+ node_traits::set_next(this->get_root_node(), new_first);
+ }
+
+ void priv_shift_backwards(size_type n, detail::bool_<false>)
+ {
+ node_ptr last = node_algorithms::move_forward(this->get_root_node(), (std::size_t)n);
+ if(cache_last && last){
+ this->set_last_node(last);
+ }
+ }
+
+ void priv_shift_backwards(size_type n, detail::bool_<true>)
+ {
+ std::pair<node_ptr, node_ptr> ret(
+ node_algorithms::move_first_n_forward
+ (node_traits::get_next(this->get_root_node()), (std::size_t)n));
+ if(ret.first){
+ node_traits::set_next(this->get_root_node(), ret.first);
+ if(cache_last){
+ this->set_last_node(ret.second);
+ }
+ }
+ }
+
+ void priv_shift_forward(size_type n, detail::bool_<false>)
+ {
+ node_ptr last = node_algorithms::move_backwards(this->get_root_node(), (std::size_t)n);
+ if(cache_last && last){
+ this->set_last_node(last);
+ }
+ }
+
+ void priv_shift_forward(size_type n, detail::bool_<true>)
+ {
+ std::pair<node_ptr, node_ptr> ret(
+ node_algorithms::move_first_n_backwards
+ (node_traits::get_next(this->get_root_node()), (std::size_t)n));
+ if(ret.first){
+ node_traits::set_next(this->get_root_node(), ret.first);
+ if(cache_last){
+ this->set_last_node(ret.second);
+ }
+ }
+ }
+
+ void priv_swap_cache_last(slist_impl &other)
+ {
+ node_ptr other_last(other.get_last_node());
+ node_ptr this_last(this->get_last_node());
+ node_ptr other_bfirst(other.get_root_node());
+ node_ptr this_bfirst(this->get_root_node());
+ node_algorithms::transfer_after(this_bfirst, other_bfirst, other_last);
+ node_algorithms::transfer_after(other_bfirst, other_last != other_bfirst? other_last : this_bfirst, this_last);
+ node_ptr tmp(this->get_last_node());
+ this->set_last_node(other.get_last_node());
+ other.set_last_node(tmp);
+ if(this->get_last_node() == other_bfirst){
+ this->set_last_node(this_bfirst);
+ }
+ if(other.get_last_node() == this_bfirst){
+ other.set_last_node(other_bfirst);
+ }
+ }
+
+ //circular version
+ static void priv_swap_lists(node_ptr this_node, node_ptr other_node, detail::bool_<false>)
+ { node_algorithms::swap_nodes(this_node, other_node); }
+
+ //linear version
+ static void priv_swap_lists(node_ptr this_node, node_ptr other_node, detail::bool_<true>)
+ { node_algorithms::swap_trailing_nodes(this_node, other_node); }
+
+ static slist_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ //Obtaining the container from the end iterator is not possible with linear
+ //singly linked lists (because "end" is represented by the null pointer)
+ BOOST_STATIC_ASSERT(!linear);
+ root_plus_size *r = detail::parent_from_member<root_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), (&root_plus_size::root_));
+ data_t *d = detail::parent_from_member<data_t, root_plus_size>
+ ( r, &data_t::root_plus_size_);
+ slist_impl *s = detail::parent_from_member<slist_impl, data_t>(d, &slist_impl::data_);
+ return *s;
+ }
+};
+
+#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 slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{
+ typedef slist_impl<Config> slist_type;
+ typedef typename slist_type::const_iterator const_iterator;
+ const bool C = slist_type::constant_time_size;
+ if(C && x.size() != y.size()){
+ return false;
+ }
+ const_iterator end1 = x.end();
+
+ const_iterator i1 = x.begin();
+ const_iterator i2 = y.begin();
+ if(C){
+ 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 Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const slist_impl<T, Options...> &x, const slist_impl<T, Options...> &y)
+#else
+(const slist_impl<Config> &x, const slist_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(slist_impl<T, Options...> &x, slist_impl<T, Options...> &y)
+#else
+(slist_impl<Config> &x, slist_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c slist 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, class O5 = none>
+#endif
+struct make_slist
+{
+ /// @cond
+ typedef typename pack_options
+ < slist_defaults<T>,
+ #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::value_traits>::type value_traits;
+ typedef slist_impl
+ <
+ slistopt
+ < value_traits
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ , packed_options::linear
+ , packed_options::cache_last
+ >
+ > 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 slist
+ : public make_slist<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_slist
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4, O5
+ #else
+ Options...
+ #endif
+ >::type Base;
+ typedef typename Base::real_value_traits real_value_traits;
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+ public:
+ typedef typename Base::value_traits value_traits;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+
+ slist(const value_traits &v_traits = value_traits())
+ : Base(v_traits)
+ {}
+
+ template<class Iterator>
+ slist(Iterator b, Iterator e, const value_traits &v_traits = value_traits())
+ : Base(b, e, v_traits)
+ {}
+
+ static slist &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<slist &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const slist &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const slist &>(Base::container_from_end_iterator(end_iterator)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SLIST_HPP

Added: sandbox/boost/intrusive/slist_hook.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/slist_hook.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,292 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_SLIST_HOOK_HPP
+#define BOOST_INTRUSIVE_SLIST_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/slist_node.hpp>
+#include <boost/intrusive/circular_slist_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/generic_hook.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+template<class VoidPointer>
+struct get_slist_node_algo
+{
+ typedef circular_slist_algorithms<slist_node_traits<VoidPointer> > type;
+};
+
+/// @endcond
+
+//! Helper metafunction to define a \c slist_base_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_slist_base_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_slist_node_algo<typename packed_options::void_pointer>
+ , typename packed_options::tag
+ , packed_options::link_mode
+ , detail::SlistBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Derive a class from slist_base_hook in order to store objects in
+//! in an list. slist_base_hook holds the data necessary to maintain the
+//! list and provides an appropriate value_traits class for list.
+//!
+//! The hook admits the following options: \c tag<>, \c void_pointer<> and
+//! \c link_mode<>.
+//!
+//! \c tag<> defines a tag to identify the node.
+//! The same tag value can be used in different classes, but if a class is
+//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
+//! unique tag.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class slist_base_hook
+ : public make_slist_base_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ slist_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ slist_base_hook(const slist_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ slist_base_hook& operator=(const slist_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an slist an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~slist_base_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(slist_base_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c slist::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+//! Helper metafunction to define a \c slist_member_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_slist_member_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_slist_node_algo<typename packed_options::void_pointer>
+ , member_tag
+ , packed_options::link_mode
+ , detail::NoBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Put a public data member slist_member_hook in order to store objects of this class in
+//! an list. slist_member_hook holds the data necessary for maintaining the list and
+//! provides an appropriate value_traits class for list.
+//!
+//! The hook admits the following options: \c void_pointer<> and
+//! \c link_mode<>.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class slist_member_hook
+ : public make_slist_member_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ slist_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ slist_member_hook(const slist_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ slist_member_hook& operator=(const slist_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an slist an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~slist_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(slist_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c slist::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SLIST_HOOK_HPP

Added: sandbox/boost/intrusive/splay_set.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/splay_set.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,2365 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_INTRUSIVE_SPLAY_SET_HPP
+#define BOOST_INTRUSIVE_SPLAY_SET_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/splaytree.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <iterator>
+
+namespace boost {
+namespace intrusive {
+
+//! The class template splay_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 Config>
+#endif
+class splay_set_impl
+{
+ /// @cond
+ typedef splaytree_impl<Config> tree_type;
+ //! This class is
+ //! non-copyable
+ splay_set_impl (const splay_set_impl&);
+
+ //! This class is
+ //! non-assignable
+ splay_set_impl &operator =(const splay_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor of the value_compare object throws.
+ splay_set_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty splay_set and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise amortized N * log N, where N is std::distance(last, first).
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ splay_set_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(true, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the splay_set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splay_set_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of splay_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static splay_set_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<splay_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &splay_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of splay_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splay_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const splay_set_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<splay_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &splay_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static splay_set_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<splay_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &splay_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const splay_set_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<splay_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &splay_set_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the splay_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the splay_set.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two splay_sets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(splay_set_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const splay_set_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to inserts value into the splay_set.
+ //!
+ //! <b>Returns</b>: If the value
+ //! is not already present inserts it and returns a pair containing the
+ //! iterator to the new value and true. If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert(reference value)
+ { return tree_.insert_unique(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to to insert x into the splay_set, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the
+ //! new element was inserted into the splay_set.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(const_iterator hint, reference value)
+ { return tree_.insert_unique(hint, value); }
+
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces
+ //! the same strict weak ordering as value_compare. The difference is that
+ //! key_value_comp compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using
+ //! a user provided key instead of the value itself.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that
+ //! part to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the splay_set.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ { return tree_.insert_unique_check(key, key_value_comp, commit_data); }
+
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces
+ //! the same strict weak ordering as value_compare. The difference is that
+ //! key_value_comp compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the splay_set, using
+ //! a user provided key instead of the value itself, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! constructing that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that key
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This can give a total
+ //! constant-time complexity to the insertion: check(O(1)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the splay_set.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ { return tree_.insert_unique_check(hint, key, key_value_comp, commit_data); }
+
+ //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
+ //! must have been obtained from a previous call to "insert_check".
+ //! No objects should have been inserted or erased from the splay_set between
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
+ //!
+ //! <b>Effects</b>: Inserts the value in the splay_set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Returns</b>: An iterator to the newly inserted object.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ iterator insert_commit(reference value, const insert_commit_data &commit_data)
+ { return tree_.insert_unique_commit(value, commit_data); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the splay_set.
+ //!
+ //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_unique(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is amortized
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator b, const_iterator e)
+ { return tree_.erase(b, e); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size()) + this->count(value)).
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ size_type erase(const_reference value)
+ { return tree_.erase(value); }
+
+ //! <b>Effects</b>: Erases all the elements that compare equal with
+ //! the given key and the given comparison functor.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
+ //!
+ //! <b>Throws</b>: If the comp ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ 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); }
+
+ #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 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.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
+ { return tree_.erase_and_dispose(b, e, disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)). Basic guarantee.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class Disposer>
+ size_type erase_and_dispose(const_reference value, Disposer disposer)
+ { return tree_.erase_and_dispose(value, disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given key.
+ //! according to the comparison functor "comp".
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
+ //!
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ 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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ { return tree_.clear_and_dispose(disposer); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ size_type count(const_reference value)
+ { return tree_.find(value) != end(); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the same key
+ //! compared with the given comparison functor.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ template<class KeyType, class KeyValueCompare>
+ size_type count(const KeyType& key, KeyValueCompare comp)
+ { return tree_.find(key, comp) != end(); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ size_type count_dont_splay(const_reference value)const
+ { return tree_.find_dont_splay(value) != end(); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the same key
+ //! compared with the given comparison functor.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ template<class KeyType, class KeyValueCompare>
+ size_type count_dont_splay(const KeyType& key, KeyValueCompare comp)const
+ { return tree_.find_dont_splay(key, comp) != end(); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator lower_bound(const_reference value)
+ { return tree_.lower_bound(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key according to the comparison functor is not less than k or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType& key, KeyValueCompare comp)
+ { return tree_.lower_bound(key, comp); }
+
+ //! <b>Effects</b>: Returns a const iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator lower_bound_dont_splay(const_reference value) const
+ { return tree_.lower_bound_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose
+ //! key according to the comparison functor is not less than k or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.lower_bound_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator upper_bound(const_reference value)
+ { return tree_.upper_bound(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key according to the comparison functor is greater than key or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType& key, KeyValueCompare comp)
+ { return tree_.upper_bound(key, comp); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator upper_bound_dont_splay(const_reference value) const
+ { return tree_.upper_bound_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose
+ //! key according to the comparison functor is greater than key or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.upper_bound_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Finds an iterator to the first element whose value is
+ //! "value" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator find(const_reference value)
+ { return tree_.find(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! "key" according to the comparison functor or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType& key, KeyValueCompare comp)
+ { return tree_.find(key, comp); }
+
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
+ //! "value" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator find_dont_splay(const_reference value) const
+ { return tree_.find_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
+ //! "key" according to the comparison functor or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.find_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ std::pair<iterator,iterator> equal_range(const_reference value)
+ { return tree_.equal_range(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k
+ //! according to the comparison functor or an empty range
+ //! that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ 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<const_iterator, const_iterator>
+ equal_range_dont_splay(const_reference value) const
+ { return tree_.equal_range_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k
+ //! according to the comparison functor or an empty range
+ //! that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.equal_range_dont_splay(key, comp); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! splay_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the splay_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a splay_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! splay_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a splay_set/multisplay_set.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Requires</b>: i must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
+ //! is placed as the root of the tree, improving future searches of this value.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void splay_up(iterator i)
+ { tree_.splay_up(i); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree. If the element is not present returns the last node compared with the key.
+ //! If the tree is empty, end() is returned.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the comparison functor throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ iterator splay_down(const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_.splay_down(key, comp); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the predicate throws.
+ iterator splay_down(const value_type &value)
+ { return tree_.splay_down(value); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ /// @cond
+ friend bool operator==(const splay_set_impl &x, const splay_set_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const splay_set_impl &x, const splay_set_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y)
+#else
+(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y)
+#else
+(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y)
+#else
+(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_set_impl<T, Options...> &x, const splay_set_impl<T, Options...> &y)
+#else
+(const splay_set_impl<Config> &x, const splay_set_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(splay_set_impl<T, Options...> &x, splay_set_impl<T, Options...> &y)
+#else
+(splay_set_impl<Config> &x, splay_set_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c splay_set that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_splay_set
+{
+ /// @cond
+ typedef splay_set_impl
+ < typename make_splaytree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class splay_set
+ : public make_splay_set<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_splay_set
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ splay_set( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ splay_set( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static splay_set &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<splay_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const splay_set &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const splay_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static splay_set &container_from_iterator(iterator it)
+ { return static_cast<splay_set &>(Base::container_from_iterator(it)); }
+
+ static const splay_set &container_from_iterator(const_iterator it)
+ { return static_cast<const splay_set &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+//! The class template splay_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 Config>
+#endif
+class splay_multiset_impl
+{
+ /// @cond
+ typedef splaytree_impl<Config> tree_type;
+
+ //Non-copyable and non-assignable
+ splay_multiset_impl (const splay_multiset_impl&);
+ splay_multiset_impl &operator =(const splay_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ splay_multiset_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty splay_multiset and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise amortized N * log N, where N is the distance between first and last.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws.
+ template<class Iterator>
+ splay_multiset_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(false, b, e, cmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splay_multiset_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of splay_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static splay_multiset_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<splay_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &splay_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of splay_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splay_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const splay_multiset_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<splay_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &splay_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static splay_multiset_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<splay_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &splay_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const splay_multiset_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<splay_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &splay_multiset_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the splay_multiset.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two splay_multisets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(splay_multiset_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const splay_multiset_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the splay_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(reference value)
+ { return tree_.insert_equal(this->end(), value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts x into the splay_multiset, using pos as a hint to
+ //! where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(const_iterator hint, reference value)
+ { return tree_.insert_equal(hint, value); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the splay_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Insert range is amortized O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_equal(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is amortized
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator b, const_iterator e)
+ { return tree_.erase(b, e); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ size_type erase(const_reference value)
+ { return tree_.erase(value); }
+
+ //! <b>Effects</b>: Erases all the elements that compare equal with
+ //! the given key and the given comparison functor.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
+ //!
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ 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); }
+
+ #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>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is amortized
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
+ { return tree_.erase_and_dispose(b, e, disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(value)).
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class Disposer>
+ size_type erase_and_dispose(const_reference value, Disposer disposer)
+ { return tree_.erase_and_dispose(value, disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given key.
+ //! according to the comparison functor "comp".
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + this->count(key, comp)).
+ //!
+ //! <b>Throws</b>: If comp ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ 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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ { return tree_.clear_and_dispose(disposer); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ size_type count(const_reference value)
+ { return tree_.count(value); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the same key
+ //! compared with the given comparison functor.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ template<class KeyType, class KeyValueCompare>
+ size_type count(const KeyType& key, KeyValueCompare comp)
+ { return tree_.count(key, comp); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ size_type count_dont_splay(const_reference value) const
+ { return tree_.count_dont_splay(value); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the same key
+ //! compared with the given comparison functor.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ template<class KeyType, class KeyValueCompare>
+ size_type count_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.count_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator lower_bound(const_reference value)
+ { return tree_.lower_bound(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key according to the comparison functor is not less than k or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType& key, KeyValueCompare comp)
+ { return tree_.lower_bound(key, comp); }
+
+ //! <b>Effects</b>: Returns a const iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator lower_bound_dont_splay(const_reference value) const
+ { return tree_.lower_bound_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose
+ //! key according to the comparison functor is not less than k or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.lower_bound_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator upper_bound(const_reference value)
+ { return tree_.upper_bound(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key according to the comparison functor is greater than key or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType& key, KeyValueCompare comp)
+ { return tree_.upper_bound(key, comp); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator upper_bound_dont_splay(const_reference value) const
+ { return tree_.upper_bound_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Returns a const_iterator to the first element whose
+ //! key according to the comparison functor is greater than key or
+ //! end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.upper_bound_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Finds an iterator to the first element whose value is
+ //! "value" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ iterator find(const_reference value)
+ { return tree_.find(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! "key" according to the comparison functor or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType& key, KeyValueCompare comp)
+ { return tree_.find(key, comp); }
+
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose value is
+ //! "value" or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ const_iterator find_dont_splay(const_reference value) const
+ { return tree_.find_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
+ //! "key" according to the comparison functor or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.find_dont_splay(key, comp); }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws.
+ std::pair<iterator,iterator> equal_range(const_reference value)
+ { return tree_.equal_range(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k
+ //! according to the comparison functor or an empty range
+ //! that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ 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<const_iterator, const_iterator>
+ equal_range_dont_splay(const_reference value) const
+ { return tree_.equal_range_dont_splay(value); }
+
+ //! <b>Requires</b>: comp must imply the same element order as
+ //! value_compare. Usually key is the part of the value_type
+ //! that is used in the ordering functor.
+ //!
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k
+ //! according to the comparison functor or an empty range
+ //! that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If comp ordering function throws.
+ //!
+ //! <b>Note</b>: This function is used when constructing a value_type
+ //! is expensive and the value_type can be compared with a cheaper
+ //! key type. Usually this key is part of the value_type.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range_dont_splay(const KeyType& key, KeyValueCompare comp) const
+ { return tree_.equal_range_dont_splay(key, comp); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a set/splay_multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Requires</b>: i must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
+ //! is placed as the root of the tree, improving future searches of this value.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void splay_up(iterator i)
+ { tree_.splay_up(i); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree. If the element is not present returns the last node compared with the key.
+ //! If the tree is empty, end() is returned.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the comparison functor throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ iterator splay_down(const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_.splay_down(key, comp); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the predicate throws.
+ iterator splay_down(const value_type &value)
+ { return tree_.splay_down(value); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ /// @cond
+ friend bool operator==(const splay_multiset_impl &x, const splay_multiset_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const splay_multiset_impl &x, const splay_multiset_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y)
+#else
+(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y)
+#else
+(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y)
+#else
+(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splay_multiset_impl<T, Options...> &x, const splay_multiset_impl<T, Options...> &y)
+#else
+(const splay_multiset_impl<Config> &x, const splay_multiset_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(splay_multiset_impl<T, Options...> &x, splay_multiset_impl<T, Options...> &y)
+#else
+(splay_multiset_impl<Config> &x, splay_multiset_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c splay_multiset that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_splay_multiset
+{
+ /// @cond
+ typedef splay_multiset_impl
+ < typename make_splaytree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class splay_multiset
+ : public make_splay_multiset<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_splay_multiset
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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));
+
+ splay_multiset( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ splay_multiset( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, v_traits)
+ {}
+
+ static splay_multiset &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<splay_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const splay_multiset &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const splay_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static splay_multiset &container_from_iterator(iterator it)
+ { return static_cast<splay_multiset &>(Base::container_from_iterator(it)); }
+
+ static const splay_multiset &container_from_iterator(const_iterator it)
+ { return static_cast<const splay_multiset &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAY_SET_HPP

Added: sandbox/boost/intrusive/splay_set_hook.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/splay_set_hook.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,290 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
+#define BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
+#include <boost/intrusive/splaytree_algorithms.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/generic_hook.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+template<class VoidPointer>
+struct get_splay_set_node_algo
+{
+ typedef splaytree_algorithms<tree_node_traits<VoidPointer> > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c splay_set_base_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_splay_set_base_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_splay_set_node_algo<typename packed_options::void_pointer>
+ , typename packed_options::tag
+ , packed_options::link_mode
+ , detail::SplaySetBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Derive a class from splay_set_base_hook in order to store objects in
+//! in a splay_set/splay_multiset. splay_set_base_hook holds the data necessary to maintain
+//! the splay_set/splay_multiset and provides an appropriate value_traits class for splay_set/splay_multiset.
+//!
+//! The hook admits the following options: \c tag<>, \c void_pointer<>,
+//! \c link_mode<> and \c optimize_size<>.
+//!
+//! \c tag<> defines a tag to identify the node.
+//! The same tag value can be used in different classes, but if a class is
+//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
+//! unique tag.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class splay_set_base_hook
+ : public make_splay_set_base_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ splay_set_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_base_hook(const splay_set_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_base_hook& operator=(const splay_set_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in a set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splay_set_base_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(splay_set_base_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+//! Helper metafunction to define a \c splay_set_member_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none>
+#endif
+struct make_splay_set_member_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_splay_set_node_algo<typename packed_options::void_pointer>
+ , member_tag
+ , packed_options::link_mode
+ , detail::NoBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Put a public data member splay_set_member_hook in order to store objects of this
+//! class in a splay_set/splay_multiset. splay_set_member_hook holds the data
+//! necessary for maintaining the splay_set/splay_multiset and provides an appropriate
+//! value_traits class for splay_set/splay_multiset.
+//!
+//! The hook admits the following options: \c void_pointer<>,
+//! \c link_mode<> and \c optimize_size<>.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class splay_set_member_hook
+ : public make_splay_set_member_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ splay_set_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_member_hook(const splay_set_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_member_hook& operator=(const splay_set_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in a set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splay_set_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(splay_set_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP

Added: sandbox/boost/intrusive/splaytree.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/splaytree.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1652 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_SPLAYTREE_HPP
+#define BOOST_INTRUSIVE_SPLAYTREE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <functional>
+#include <iterator>
+#include <utility>
+#include <cstddef>
+#include <algorithm>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/splay_set_hook.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/splaytree_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize>
+struct splaysetopt
+{
+ typedef ValueTraits value_traits;
+ typedef Compare compare;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+};
+
+template <class T>
+struct splay_set_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_splay_set_hook>
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ , compare<std::less<T> >
+ >::type
+{};
+
+/// @endcond
+
+//! The class template splaytree is an intrusive splay tree container that
+//! is used to construct intrusive splay_set and splay_multiset containers. The no-throw
+//! guarantee holds only, if the value_compare object
+//! doesn't throw.
+//!
+//! 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 Config>
+#endif
+class splaytree_impl
+ : private detail::clear_on_destructor_base<splaytree_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef value_type key_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_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<splaytree_impl, false> iterator;
+ typedef tree_iterator<splaytree_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef splaytree_algorithms<node_traits> node_algorithms;
+
+ static const bool constant_time_size = Config::constant_time_size;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<splaytree_impl>::value;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //noncopyable
+ splaytree_impl (const splaytree_impl&);
+ splaytree_impl operator =(const splaytree_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ struct header_plus_size : public size_traits
+ { node header_; };
+
+ struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare>
+ {
+ node_plus_pred_t(const value_compare &comp)
+ : detail::ebo_functor_holder<value_compare>(comp)
+ {}
+ header_plus_size header_plus_size_;
+ };
+
+ struct data_t : public splaytree_impl::value_traits
+ {
+ typedef typename splaytree_impl::value_traits value_traits;
+ data_t(const value_compare & comp, const value_traits &val_traits)
+ : value_traits(val_traits), node_plus_pred_(comp)
+ {}
+ node_plus_pred_t node_plus_pred_;
+ } data_;
+
+ const value_compare &priv_comp() const
+ { return data_.node_plus_pred_.get(); }
+
+ value_compare &priv_comp()
+ { return data_.node_plus_pred_.get(); }
+
+ const node &priv_header() const
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ node &priv_header()
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(detail::get_pointer(ptr)));
+ }
+
+ size_traits &priv_size_traits()
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ typedef typename node_algorithms::insert_commit_data insert_commit_data;
+
+ //! <b>Effects</b>: Constructs an empty tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructorof the value_compare object throws. Basic guarantee.
+ splaytree_impl( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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 amortized N * log N, where N is the distance between first and last.
+ //!
+ //! <b>Throws</b>: If value_traits::node_traits::node
+ //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
+ //! or the copy constructor/operator() of the value_compare object throws. Basic guarantee.
+ template<class Iterator>
+ splaytree_impl ( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called), but the nodes according to
+ //! the value_traits template parameter are reinitialized and thus can be reused.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splaytree_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return iterator(node_algorithms::begin_node(&priv_header()), 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_algorithms::begin_node(&priv_header()), 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 (node_ptr(&priv_header()), 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(const_node_ptr(&priv_header())), 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 splaytree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static splaytree_impl &container_from_end_iterator(iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of splaytree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: it must be a valid iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static splaytree_impl &container_from_iterator(iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <b>Precondition</b>: it must be a valid end const_iterator
+ //! of rbtree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const splaytree_impl &container_from_iterator(const_iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <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 this->cbegin() == this->cend(); }
+
+ //! <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(const_node_ptr(&priv_header()));
+ }
+ }
+
+ //! <b>Effects</b>: Swaps the contents of two splaytrees.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the comparison functor's swap call throws.
+ void swap(splaytree_impl& other)
+ {
+ //This can throw
+ using std::swap;
+ swap(priv_comp(), priv_comp());
+ //These can't throw
+ node_algorithms::swap_tree(node_ptr(&priv_header()), node_ptr(&other.priv_header()));
+ 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 lower bound.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is amortized
+ //! logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, splaytree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal_lower_bound
+ (node_ptr(&priv_header()), to_insert, key_node_comp), this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator.
+ //!
+ //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to
+ //! where it will be inserted. If "hint" is the upper_bound
+ //! the insertion takes constant time (two comparisons in the worst case)
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(const_iterator hint, reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, splaytree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal
+ (node_ptr(&priv_header()), hint.pointed_node(), to_insert, key_node_comp), this);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a each element of a range into the tree
+ //! before the upper bound of the key of each element.
+ //!
+ //! <b>Complexity</b>: Insert range is in general amortized O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert_equal(Iterator b, Iterator e)
+ {
+ if(this->empty()){
+ iterator end(this->end());
+ for (; b != e; ++b)
+ this->insert_equal(end, *b);
+ }
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the tree if the value
+ //! is not already present.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert_unique(reference value)
+ {
+ insert_commit_data commit_data;
+ std::pair<iterator, bool> ret = insert_unique_check(value, priv_comp(), commit_data);
+ if(!ret.second)
+ return ret;
+ return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator
+ //!
+ //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint
+ //! to where it will be inserted.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic in general, but it is amortized
+ //! constant time (two comparisons in the worst case)
+ //! if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_unique(const_iterator hint, reference value)
+ {
+ insert_commit_data commit_data;
+ std::pair<iterator, bool> ret = insert_unique_check(hint, value, priv_comp(), commit_data);
+ if(!ret.second)
+ return ret.first;
+ return insert_unique_commit(value, commit_data);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Tries to insert each element of a range into the tree.
+ //!
+ //! <b>Complexity</b>: Insert range is in general amortized O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert_unique(Iterator b, Iterator e)
+ {
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), 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));
+ this->priv_size_traits().increment();
+ node_algorithms::insert_unique_commit
+ (node_ptr(&priv_header()), to_insert, commit_data);
+ return iterator(to_insert, this);
+ }
+
+ //! <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(&priv_header(), 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 amortized
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator b, const_iterator e)
+ { size_type n; return private_erase(b, e, n); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ size_type erase(const_reference value)
+ { return this->erase(value, priv_comp()); }
+
+ //! <b>Effects</b>: Erases all the elements with the given key.
+ //! according to the comparison functor "comp".
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: Amortized O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class KeyType, class KeyValueCompare>
+ size_type erase(const KeyType& key, KeyValueCompare comp
+ /// @cond
+ , typename detail::enable_if_c<!detail::is_convertible<KeyValueCompare, const_iterator>::value >::type * = 0
+ /// @endcond
+ )
+ {
+ std::pair<iterator,iterator> p = this->equal_range(key, comp);
+ size_type n;
+ private_erase(p.first, p.second, n);
+ return n;
+ }
+
+ //! <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)
+ 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 amortized
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ 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>: Amortized O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class 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>: Amortized 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;
+ 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(&priv_header());
+ 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>: Amortized O(log(size() + N)),
+ //! where N is the number of elements in the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. Calls N times to disposer functor.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ node_algorithms::clear_and_dispose(node_ptr(&priv_header())
+ , detail::node_disposer<Disposer, splaytree_impl>(disposer, this));
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(0);
+ }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given value
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given value.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type count(const_reference value)
+ { return this->count(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ size_type count(const KeyType &key, KeyValueCompare comp)
+ {
+ std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
+ return std::distance(ret.first, ret.second);
+ }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given value
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given value.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type count_dont_splay(const_reference value) const
+ { return this->count_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ size_type count_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ std::pair<const_iterator, const_iterator> ret = this->equal_range_dont_splay(key, comp);
+ return std::distance(ret.first, ret.second);
+ }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator lower_bound(const_reference value)
+ { return this->lower_bound(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator lower_bound_dont_splay(const_reference value) const
+ { return this->lower_bound_dont_splay(value, priv_comp()); }
+
+ //! <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.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), key, key_node_comp, false), 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>: Amortized 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>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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_dont_splay(const_reference value) const
+ { return this->upper_bound_dont_splay(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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::upper_bound_dont_splay
+ (const_node_ptr(&priv_header()), key, key_node_comp, false), 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>: Amortized 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>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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_dont_splay(const_reference value) const
+ { return this->find_dont_splay(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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), key, key_node_comp, false), 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>: Amortized 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>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), 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<const_iterator, const_iterator>
+ equal_range_dont_splay(const_reference value) const
+ { return this->equal_range_dont_splay(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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp, false));
+ 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 splaytree_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!src.empty()){
+ detail::exception_disposer<splaytree_impl, Disposer>
+ rollback(*this, disposer);
+ node_algorithms::clone
+ (const_node_ptr(&src.priv_header())
+ ,node_ptr(&this->priv_header())
+ ,detail::node_cloner<Cloner, splaytree_impl>(cloner, this)
+ ,detail::node_disposer<Disposer, splaytree_impl>(disposer, this));
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ this->priv_comp() = src.priv_comp();
+ rollback.release();
+ }
+ }
+
+ //! <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
+ (node_ptr(&priv_header())));
+ 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>: i must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
+ //! is placed as the root of the tree, improving future searches of this value.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void splay_up(iterator i)
+ { return node_algorithms::splay_up(i.pointed_node(), &priv_header()); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree. If the element is not present returns the last node compared with the key.
+ //! If the tree is empty, end() is returned.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the comparison functor throws.
+ template<class KeyType, class KeyValueCompare>
+ iterator splay_down(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ node_ptr r = node_algorithms::splay_down(&priv_header(), key, key_node_comp);
+ return iterator(r, this);
+ }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree.
+ //!
+ //! <b>Complexity</b>: Amortized logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the predicate throws.
+ iterator splay_down(const value_type &value)
+ { return this->splay_down(value, priv_comp()); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ {
+ node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this)
+ , node_ptr(&priv_header())
+ , get_real_value_traits().to_node_ptr(with_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 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>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { node_algorithms::rebalance(node_ptr(&priv_header())); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return iterator(node_algorithms::rebalance_subtree(root.pointed_node()), this); }
+
+/*
+ //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect,
+ //! if x is not in such a tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This static function is only usable with the "safe mode"
+ //! hook and non-constant time size lists. Otherwise, the user must use
+ //! the non-static "erase(reference )" member. If the user calls
+ //! this function with a non "safe mode" or constant time size list
+ //! a compilation error will be issued.
+ template<class T>
+ static void remove_node(T& value)
+ {
+ //This function is only usable for safe mode hooks and non-constant
+ //time lists.
+ //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size)));
+ BOOST_STATIC_ASSERT((!constant_time_size));
+ BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value));
+ node_ptr to_remove(value_traits::to_node_ptr(value));
+ node_algorithms::unlink_and_rebalance(to_remove);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_remove);
+ }
+*/
+
+ /// @cond
+ private:
+ template<class Disposer>
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase_and_dispose(b++, disposer);
+ return b.unconst();
+ }
+
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase(b++);
+ return b.unconst();
+ }
+ /// @endcond
+
+ private:
+ static splaytree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ header_plus_size *r = detail::parent_from_member<header_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &header_plus_size::header_);
+ node_plus_pred_t *n = detail::parent_from_member
+ <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_);
+ data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_);
+ splaytree_impl *rb = detail::parent_from_member<splaytree_impl, data_t>(d, &splaytree_impl::data_);
+ return *rb;
+ }
+
+ static splaytree_impl &priv_container_from_iterator(const const_iterator &it)
+ { return priv_container_from_end_iterator(it.end_iterator_from_it()); }
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{
+ typedef splaytree_impl<Config> tree_type;
+ typedef typename tree_type::const_iterator const_iterator;
+
+ if(tree_type::constant_time_size && x.size() != y.size()){
+ return false;
+ }
+ const_iterator end1 = x.end();
+ const_iterator i1 = x.begin();
+ const_iterator i2 = y.begin();
+ if(tree_type::constant_time_size){
+ while (i1 != end1 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1;
+ }
+ else{
+ const_iterator end2 = y.end();
+ while (i1 != end1 && i2 != end2 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1 && i2 == end2;
+ }
+}
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(splaytree_impl<T, Options...> &x, splaytree_impl<T, Options...> &y)
+#else
+(splaytree_impl<Config> &x, splaytree_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+/// @cond
+
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#else
+template<class T, class ...Options>
+#endif
+struct make_splaytree_opt
+{
+ typedef typename pack_options
+ < splay_set_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef splaysetopt
+ < value_traits
+ , typename packed_options::compare
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c splaytree that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_splaytree
+{
+ /// @cond
+ typedef splaytree_impl
+ < typename make_splaytree_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::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>
+#else
+template<class T, class ...Options>
+#endif
+class splaytree
+ : public make_splaytree<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_splaytree
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ 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;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ splaytree( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ splaytree( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(unique, b, e, cmp, v_traits)
+ {}
+
+ static splaytree &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<splaytree &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const splaytree &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const splaytree &>(Base::container_from_end_iterator(end_iterator)); }
+};
+
+#endif
+
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAYTREE_HPP

Added: sandbox/boost/intrusive/splaytree_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/splaytree_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,893 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// 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.
+//
+/////////////////////////////////////////////////////////////////////////////
+// The implementation of splay trees is based on the article and code published
+// in C++ Users Journal "Implementing Splay Trees in C++" (September 1, 2005).
+//
+// The code has been modified and (supposely) improved by Ion Gaztanaga.
+// Here is the header of the file used as base code:
+//
+// splay_tree.h -- implementation of a STL complatible splay tree.
+//
+// Copyright (c) 2004 Ralf Mattethat
+//
+// Permission to copy, use, modify, sell and distribute this software
+// is granted provided this copyright notice appears in all copies.
+// This software is provided "as is" without express or implied
+// warranty, and with no claim as to its suitability for any purpose.
+//
+// Please send questions, comments, complaints, performance data, etc to
+// ralf.mattethat_at_[hidden]
+//
+// Requirements for element type
+// * must be copy-constructible
+// * destructor must not throw exception
+//
+// Methods marked with note A only throws an exception if the evaluation of the
+// predicate throws an exception. If an exception is thrown the call has no
+// effect on the containers state
+//
+// Methods marked with note B only throws an exception if the coppy constructor
+// or assignment operator of the predicate throws an exception. If an exception
+// is thrown the call has no effect on the containers state
+//
+// iterators are only invalidated, if the element pointed to by the iterator
+// is deleted. The same goes for element references
+//
+
+#ifndef BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
+
+#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/detail/tree_algorithms.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+namespace detail {
+
+template<class NodeTraits>
+struct splaydown_rollback
+{
+ typedef typename NodeTraits::node_ptr node_ptr;
+ splaydown_rollback( const node_ptr *pcur_subtree, node_ptr header
+ , node_ptr leftmost , node_ptr rightmost)
+ : pcur_subtree_(pcur_subtree) , header_(header)
+ , leftmost_(leftmost) , rightmost_(rightmost)
+ {}
+
+ void release()
+ { pcur_subtree_ = 0; }
+
+ ~splaydown_rollback()
+ {
+ if(pcur_subtree_){
+ //Exception can only be thrown by comp, but
+ //tree invariants still hold. *pcur_subtree is the current root
+ //so link it to the header.
+ NodeTraits::set_parent(*pcur_subtree_, header_);
+ NodeTraits::set_parent(header_, *pcur_subtree_);
+ //Recover leftmost/rightmost pointers
+ NodeTraits::set_left (header_, leftmost_);
+ NodeTraits::set_right(header_, rightmost_);
+ }
+ }
+ const node_ptr *pcur_subtree_;
+ node_ptr header_, leftmost_, rightmost_;
+};
+
+} //namespace detail {
+/// @endcond
+
+//! A splay tree is an implementation of a binary search tree. The tree is
+//! self balancing using the splay algorithm as described in
+//!
+//! "Self-Adjusting Binary Search Trees
+//! by Daniel Dominic Sleator and Robert Endre Tarjan
+//! AT&T Bell Laboratories, Murray Hill, NJ
+//! Journal of the ACM, Vol 32, no 3, July 1985, pp 652-686
+
+//! splaytree_algorithms is configured with a NodeTraits class, which encapsulates the
+//! information about the node to be manipulated. NodeTraits must support the
+//! following interface:
+//!
+//! <b>Typedefs</b>:
+//!
+//! <tt>node</tt>: The type of the node that forms the circular list
+//!
+//! <tt>node_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class splaytree_algorithms
+{
+ /// @cond
+ private:
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+ /// @endcond
+
+ 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
+ typedef typename tree_algorithms::insert_commit_data insert_commit_data;
+
+ /// @cond
+ private:
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return tree_algorithms::end_node(header); }
+
+ //! <b>Requires</b>: node is a node of the tree or an node initialized
+ //! by init(...).
+ //!
+ //! <b>Effects</b>: Returns true if the node is initialized by init().
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool unique(const_node_ptr node)
+ { return tree_algorithms::unique(node); }
+
+ static void unlink(node_ptr node)
+ { tree_algorithms::unlink(node); }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::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
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ { tree_algorithms::swap_nodes(node1, header1, node2, header2); }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, 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);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ { return tree_algorithms::next_node(p); }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ { return tree_algorithms::prev_node(p); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ { tree_algorithms::init(node); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ { tree_algorithms::init_header(header); }
+
+ //! <b>Requires</b>: "disposer" must be an object function
+ //! taking a node_ptr parameter and shouldn't throw.
+ //!
+ //! <b>Effects</b>: Empties the target tree calling
+ //! <tt>void disposer::operator()(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.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ { tree_algorithms::clear_and_dispose(header, disposer); }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ { return tree_algorithms::count(node); }
+
+ //! <b>Requires</b>: header is the header node of the tree.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes above the header.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t size(const_node_ptr header)
+ { return tree_algorithms::size(header); }
+
+ //! <b>Requires</b>: header1 and header2 must be the header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two trees. After the function header1 will contain
+ //! links to the second tree and header2 will have links to the first tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_tree(node_ptr header1, node_ptr header2)
+ { return tree_algorithms::swap_tree(header1, header2); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_value, const insert_commit_data &commit_data)
+ { tree_algorithms::insert_unique_commit(header, new_value, commit_data); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (node_ptr header, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ splay_down(header, key, comp);
+ return tree_algorithms::insert_unique_check(header, key, comp, commit_data);
+ }
+
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (node_ptr header, node_ptr hint, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ splay_down(header, key, comp);
+ return tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data);
+ }
+
+ static bool is_header(const_node_ptr p)
+ { return tree_algorithms::is_header(p); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true)
+ {
+ if(splay)
+ splay_down(uncast(header), key, comp);
+ node_ptr end = uncast(header);
+ node_ptr y = lower_bound(header, key, comp, false);
+ node_ptr r = (y == end || comp(key, y)) ? end : y;
+ return r;
+ }
+
+ //! <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.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true)
+ {
+ //if(splay)
+ //splay_down(uncast(header), key, comp);
+ std::pair<node_ptr, node_ptr> ret =
+ tree_algorithms::equal_range(header, key, comp);
+
+ if(splay)
+ splay_up(ret.first, uncast(header));
+ return ret;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true)
+ {
+ //if(splay)
+ //splay_down(uncast(header), key, comp);
+ node_ptr y = tree_algorithms::lower_bound(header, key, comp);
+ if(splay)
+ splay_up(y, uncast(header));
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true)
+ {
+ //if(splay)
+ //splay_down(uncast(header), key, comp);
+ node_ptr y = tree_algorithms::upper_bound(header, key, comp);
+ if(splay)
+ splay_up(y, uncast(header));
+ return y;
+ }
+
+ //! <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
+ (node_ptr header, node_ptr hint, node_ptr new_node, NodePtrCompare comp)
+ {
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal(header, hint, new_node, comp);
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr header, node_ptr new_node, NodePtrCompare comp)
+ {
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal_upper_bound(header, new_node, comp);
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr header, node_ptr new_node, NodePtrCompare comp)
+ {
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal_lower_bound(header, new_node, comp);
+ }
+
+ //! <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()(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()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ { tree_algorithms::clone(source_header, target_header, cloner, disposer); }
+
+ // delete node | complexity : constant | exception : nothrow
+ static void erase(node_ptr header, node_ptr z, bool splay = true)
+ {
+// node_base* n = t->right;
+// if( t->left != 0 ){
+// node_base* l = t->previous();
+// splay_up( l , t );
+// n = t->left;
+// n->right = t->right;
+// if( n->right != 0 )
+// n->right->parent = n;
+// }
+//
+// if( n != 0 )
+// n->parent = t->parent;
+//
+// if( t->parent->left == t )
+// t->parent->left = n;
+// else // must be ( t->parent->right == t )
+// t->parent->right = n;
+//
+// if( data_->parent == t )
+// data_->parent = find_leftmost();
+ //posibility 1
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = prev_node(z);
+ splay_up(l, header);
+ }
+ /*
+ //possibility 2
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = NodeTraits::get_left(z);
+ splay_up(l, header);
+ }*//*
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = prev_node(z);
+ splay_up_impl(l, z);
+ }*/
+ /*
+ //possibility 4
+ if(splay){
+ splay_up(z, header);
+ }*/
+
+ //if(splay)
+ //splay_up(z, header);
+ tree_algorithms::erase(header, z);
+ }
+
+ // bottom-up splay, use data_ as parent for n | complexity : logarithmic | exception : nothrow
+ static void splay_up(node_ptr n, node_ptr header)
+ {
+ if(n == header){ // do a splay for the right most node instead
+ // this is to boost performance of equal_range/count on equivalent containers in the case
+ // where there are many equal elements at the end
+ n = NodeTraits::get_right(header);
+ }
+
+ node_ptr t = header;
+
+ if( n == t ) return;
+
+ for( ;; ){
+ node_ptr p = NodeTraits::get_parent(n);
+ node_ptr g = NodeTraits::get_parent(p);
+
+ if( p == t ) break;
+
+ if( g == t ){
+ // zig
+ rotate(n);
+ }
+ else if ((NodeTraits::get_left(p) == n && NodeTraits::get_left(g) == p) ||
+ (NodeTraits::get_right(p) == n && NodeTraits::get_right(g) == p) ){
+ // zig-zig
+ rotate(p);
+ rotate(n);
+ }
+ else{
+ // zig-zag
+ rotate(n);
+ rotate(n);
+ }
+ }
+ }
+
+ // top-down splay | complexity : logarithmic | exception : strong, note A
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr splay_down(node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ if(!NodeTraits::get_parent(header))
+ return header;
+ //Most splay tree implementations use a dummy/null node to implement.
+ //this function. This has some problems for a generic library like Intrusive:
+ //
+ // * The node might not have a default constructor.
+ // * The default constructor could throw.
+ //
+ //We already have a header node. Leftmost and rightmost nodes of the tree
+ //are not changed when splaying (because the invariants of the tree don't
+ //change) We can back up them, use the header as the null node and
+ //reassign old values after the function has been completed.
+ node_ptr t = NodeTraits::get_parent(header);
+ //Check if tree has a single node
+ if(!NodeTraits::get_left(t) && !NodeTraits::get_right(t))
+ return t;
+ //Backup leftmost/rightmost
+ node_ptr leftmost = NodeTraits::get_left(header);
+ node_ptr rightmost = NodeTraits::get_right(header);
+
+ {
+ detail::splaydown_rollback<NodeTraits> rollback(&t, header, leftmost, rightmost);
+ node_ptr null = header;
+ node_ptr l = null;
+ node_ptr r = null;
+
+ for( ;; ){
+ if(comp(key, t)){
+ if(NodeTraits::get_left(t) == 0 )
+ break;
+ if(comp(key, NodeTraits::get_left(t))){
+ t = tree_algorithms::rotate_right(t);
+
+ if(NodeTraits::get_left(t) == 0)
+ break;
+ link_right(t, r);
+ }
+ else if(comp(NodeTraits::get_left(t), key)){
+ link_right(t, r);
+
+ if(NodeTraits::get_right(t) == 0 )
+ break;
+ link_left(t, l);
+ }
+ else{
+ link_right(t, r);
+ }
+ }
+ else if(comp(t, key)){
+ if(NodeTraits::get_right(t) == 0 )
+ break;
+
+ if(comp(NodeTraits::get_right(t), key)){
+ t = tree_algorithms::rotate_left( t );
+
+ if(NodeTraits::get_right(t) == 0 )
+ break;
+ link_left(t, l);
+ }
+ else if(comp(key, NodeTraits::get_right(t))){
+ link_left(t, l);
+
+ if(NodeTraits::get_left(t) == 0)
+ break;
+
+ link_right(t, r);
+ }
+ else{
+ link_left(t, l);
+ }
+ }
+ else{
+ break;
+ }
+ }
+
+ assemble(t, l, r, null);
+ rollback.release();
+ }
+
+ //t is the current root
+ NodeTraits::set_parent(header, t);
+ NodeTraits::set_parent(t, header);
+ //Recover leftmost/rightmost pointers
+ NodeTraits::set_left (header, leftmost);
+ NodeTraits::set_right(header, rightmost);
+ return t;
+ }
+
+ //! <b>Requires</b>: header must be the header of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ static void rebalance(node_ptr header)
+ { tree_algorithms::rebalance(header); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ static node_ptr rebalance_subtree(node_ptr old_root)
+ { return tree_algorithms::rebalance_subtree(old_root); }
+
+
+ //! <b>Requires</b>: "n" must be a node inserted in a tree.
+ //!
+ //! <b>Effects</b>: Returns a pointer to the header node of the tree.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr get_header(node_ptr n)
+ { return tree_algorithms::get_header(n); }
+
+ private:
+
+ /// @cond
+
+ // assemble the three sub-trees into new tree pointed to by t | complexity : constant | exception : nothrow
+ static void assemble( node_ptr t, node_ptr l, node_ptr r, const_node_ptr null_node )
+ {
+ NodeTraits::set_right(l, NodeTraits::get_left(t));
+ NodeTraits::set_left(r, NodeTraits::get_right(t));
+
+ if(NodeTraits::get_right(l) != 0){
+ NodeTraits::set_parent(NodeTraits::get_right(l), l);
+ }
+
+ if(NodeTraits::get_left(r) != 0){
+ NodeTraits::set_parent(NodeTraits::get_left(r), r);
+ }
+
+ NodeTraits::set_left (t, NodeTraits::get_right(null_node));
+ NodeTraits::set_right(t, NodeTraits::get_left(null_node));
+
+ if( NodeTraits::get_left(t) != 0 ){
+ NodeTraits::set_parent(NodeTraits::get_left(t), t);
+ }
+
+ if( NodeTraits::get_right(t) ){
+ NodeTraits::set_parent(NodeTraits::get_right(t), t);
+ }
+ }
+
+ // break link to left child node and attach it to left tree pointed to by l | complexity : constant | exception : nothrow
+ static void link_left(node_ptr& t, node_ptr& l)
+ {
+ NodeTraits::set_right(l, t);
+ NodeTraits::set_parent(t, l);
+ l = t;
+ t = NodeTraits::get_right(t);
+ }
+
+ // break link to right child node and attach it to right tree pointed to by r | complexity : constant | exception : nothrow
+ static void link_right(node_ptr& t, node_ptr& r)
+ {
+ NodeTraits::set_left(r, t);
+ NodeTraits::set_parent(t, r);
+ r = t;
+ t = NodeTraits::get_left(t);
+ }
+
+ // rotate n with its parent | complexity : constant | exception : nothrow
+ static void rotate(node_ptr n)
+ {
+ node_ptr p = NodeTraits::get_parent(n);
+ node_ptr g = NodeTraits::get_parent(p);
+ //Test if g is header before breaking tree
+ //invariants that would make is_header invalid
+ bool g_is_header = is_header(g);
+
+ if(NodeTraits::get_left(p) == n){
+ NodeTraits::set_left(p, NodeTraits::get_right(n));
+ if(NodeTraits::get_left(p) != 0)
+ NodeTraits::set_parent(NodeTraits::get_left(p), p);
+ NodeTraits::set_right(n, p);
+ }
+ else{ // must be ( p->right == n )
+ NodeTraits::set_right(p, NodeTraits::get_left(n));
+ if(NodeTraits::get_right(p) != 0)
+ NodeTraits::set_parent(NodeTraits::get_right(p), p);
+ NodeTraits::set_left(n, p);
+ }
+
+ NodeTraits::set_parent(p, n);
+ NodeTraits::set_parent(n, g);
+
+ if(g_is_header){
+ if(NodeTraits::get_parent(g) == p)
+ NodeTraits::set_parent(g, n);
+ else{//must be ( g->right == p )
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(0);
+ NodeTraits::set_right(g, n);
+ }
+ }
+ else{
+ if(NodeTraits::get_left(g) == p)
+ NodeTraits::set_left(g, n);
+ else //must be ( g->right == p )
+ NodeTraits::set_right(g, n);
+ }
+ }
+
+ /// @endcond
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/treap.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/treap.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,1663 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2008
+//
+// 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_TRIE_HPP
+#define BOOST_INTRUSIVE_TRIE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <algorithm>
+#include <cstddef>
+#include <functional>
+#include <iterator>
+#include <utility>
+
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/bs_set_hook.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/clear_on_destructor_base.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <boost/intrusive/treap_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+#include <boost/intrusive/priority_compare.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class ValueTraits, class Compare, class PrioCompare, class SizeType, bool ConstantTimeSize>
+struct treap_setopt
+{
+ typedef ValueTraits value_traits;
+ typedef Compare compare;
+ typedef PrioCompare priority_compare;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+};
+
+template <class T>
+struct treap_set_defaults
+ : pack_options
+ < none
+ , base_hook<detail::default_bs_set_hook>
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ , compare<std::less<T> >
+ , priority<boost::intrusive::priority_compare<T> >
+ >::type
+{};
+
+/// @endcond
+
+//! The class template treap is an intrusive treap container that
+//! is used to construct intrusive set and multiset containers. The no-throw
+//! guarantee holds only, if the value_compare object and priority_compare object
+//! don't throw.
+//!
+//! 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<>,
+//! \c compare<> and \c priority_compare<>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class treap_impl
+ : private detail::clear_on_destructor_base<treap_impl<Config> >
+{
+ template<class C> friend class detail::clear_on_destructor_base;
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef value_type key_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+ typedef typename Config::size_type size_type;
+ typedef typename Config::compare value_compare;
+ typedef typename Config::priority_compare priority_compare;
+ typedef value_compare key_compare;
+ typedef tree_iterator<treap_impl, false> iterator;
+ typedef tree_iterator<treap_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef treap_algorithms<node_traits> node_algorithms;
+
+ static const bool constant_time_size = Config::constant_time_size;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<treap_impl>::value;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //noncopyable
+ treap_impl (const treap_impl&);
+ treap_impl operator =(const treap_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ struct header_plus_size : public size_traits
+ { node header_; };
+
+ struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare>
+ {
+ node_plus_pred_t(const value_compare &comp, const priority_compare &p_comp)
+ : detail::ebo_functor_holder<value_compare>(comp)
+ , header_plus_priority_size_(p_comp)
+ {}
+ struct header_plus_priority_size
+ : public detail::ebo_functor_holder<priority_compare>
+ {
+ header_plus_priority_size(const priority_compare &p_comp)
+ : detail::ebo_functor_holder<priority_compare>(p_comp)
+ {}
+ header_plus_size header_plus_size_;
+ } header_plus_priority_size_;
+ };
+
+ struct data_t : public treap_impl::value_traits
+ {
+ typedef typename treap_impl::value_traits value_traits;
+ data_t(const value_compare & comp, const priority_compare &pcomp, const value_traits &val_traits)
+ : value_traits(val_traits), node_plus_pred_(comp, pcomp)
+ {}
+ node_plus_pred_t node_plus_pred_;
+ } data_;
+
+ const value_compare &priv_comp() const
+ { return data_.node_plus_pred_.get(); }
+
+ value_compare &priv_comp()
+ { return data_.node_plus_pred_.get(); }
+
+ const priority_compare &priv_pcomp() const
+ { return data_.node_plus_pred_.header_plus_priority_size_.get(); }
+
+ priority_compare &priv_pcomp()
+ { return data_.node_plus_pred_.header_plus_priority_size_.get(); }
+
+ const node &priv_header() const
+ { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_.header_; }
+
+ node &priv_header()
+ { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_.header_; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(detail::get_pointer(ptr)));
+ }
+
+ size_traits &priv_size_traits()
+ { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.node_plus_pred_.header_plus_priority_size_.header_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ typedef typename node_algorithms::insert_commit_data insert_commit_data;
+
+ //! <b>Effects</b>: Constructs an empty 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/priority_compare objects throw. Basic guarantee.
+ treap_impl( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, pcmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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/priority_compare objects
+ //! throw. Basic guarantee.
+ template<class Iterator>
+ treap_impl( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, pcmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ 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>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called), but the nodes according to
+ //! the value_traits template parameter are reinitialized and thus can be reused.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this
+ //! if constant-time size option is disabled. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~treap_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return iterator (node_traits::get_left(node_ptr(&priv_header())), 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 this->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(const_node_ptr(&priv_header())), 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 (node_ptr(&priv_header()), 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 this->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(const_node_ptr(&priv_header())), this); }
+
+
+ //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator top()
+ { return this->empty() ? this->end() : iterator (node_traits::get_parent(node_ptr(&priv_header())), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator top() const
+ { return this->ctop(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator ctop() const
+ { return this->empty() ? this->cend() : const_iterator (node_traits::get_parent(const_node_ptr(&priv_header())), 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(this->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(this->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(this->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(this->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(this->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(this->begin()); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
+ //! reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rtop()
+ { return reverse_iterator(this->top()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rtop() const
+ { return const_reverse_iterator(this->top()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crtop() const
+ { return const_reverse_iterator(this->top()); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of treap.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static treap_impl &container_from_end_iterator(iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of treap.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const treap_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: it must be a valid iterator
+ //! of treap.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static treap_impl &container_from_iterator(iterator it)
+ { return priv_container_from_iterator(it); }
+
+ //! <b>Precondition</b>: it must be a valid end const_iterator
+ //! of treap.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the tree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const treap_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 this->priv_comp(); }
+
+ //! <b>Effects</b>: Returns the priority_compare object used by the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If priority_compare copy-constructor throws.
+ priority_compare priority_comp() const
+ { return this->priv_pcomp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return node_algorithms::unique(const_node_ptr(&priv_header())); }
+
+ //! <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(const_node_ptr(&priv_header()));
+ }
+ }
+
+ //! <b>Effects</b>: Swaps the contents of two treaps.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the comparison functor's swap call throws.
+ void swap(treap_impl& other)
+ {
+ //This can throw
+ using std::swap;
+ swap(priv_comp(), priv_comp());
+ swap(priv_pcomp(), priv_pcomp());
+ //These can't throw
+ node_algorithms::swap_tree(node_ptr(&priv_header()), node_ptr(&other.priv_header()));
+ 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 or priority_compare funcstions throw. 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, treap_impl>
+ key_node_comp(priv_comp(), this);
+ detail::key_nodeptr_comp<priority_compare, treap_impl>
+ key_node_pcomp(priv_pcomp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal_upper_bound
+ (node_ptr(&priv_header()), to_insert, key_node_comp, key_node_pcomp), this);
+ }
+
+ //! <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 or priority_compare funcstions throw. 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, treap_impl>
+ key_node_comp(priv_comp(), this);
+ detail::key_nodeptr_comp<priority_compare, treap_impl>
+ key_node_pcomp(priv_pcomp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal
+ (node_ptr(&priv_header()), hint.pointed_node(), to_insert, key_node_comp, key_node_pcomp), this);
+ }
+
+ //! <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>: If the internal value_compare or priority_compare funcstions throw.
+ //! Strong guarantee.
+ //!
+ //! <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>: If the internal value_compare or priority_compare funcstions throw.
+ //! Strong guarantee.
+ //!
+ //! <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(), priv_pcomp(), 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>: If the internal value_compare or priority_compare funcstions throw.
+ //! Strong guarantee.
+ //!
+ //! <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(), priv_pcomp(), 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>: If the internal value_compare or priority_compare funcstions throw.
+ //! Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert_unique(Iterator b, Iterator e)
+ {
+ if(this->empty()){
+ iterator end(this->end());
+ for (; b != e; ++b)
+ this->insert_unique(end, *b);
+ }
+ else{
+ for (; b != e; ++b)
+ this->insert_unique(*b);
+ }
+ }
+
+ //! <b>Requires</b>: key_value_comp must be a comparison function that induces
+ //! the same strict weak ordering as value_compare. The difference is that
+ //! key_value_comp compares an arbitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the container, using
+ //! a user provided key instead of the value itself.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If the key_value_comp ordering function throws. Strong guarantee.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a value_type is expensive: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the value_type and this function offers the possibility to use that
+ //! part to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the value_type and use
+ //! "insert_commit" to insert the object in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
+ //! objects are inserted or erased from the container.
+ template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
+ std::pair<iterator, bool> insert_unique_check
+ ( const KeyType &key, KeyValueCompare key_value_comp
+ , KeyValuePrioCompare key_value_pcomp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ comp(key_value_comp, this);
+ detail::key_nodeptr_comp<KeyValuePrioCompare, treap_impl>
+ pcomp(key_value_pcomp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), key, comp, pcomp, 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.
+ template<class KeyType, class KeyValueCompare, class KeyValuePrioCompare>
+ std::pair<iterator, bool> insert_unique_check
+ ( const_iterator hint, const KeyType &key
+ , KeyValueCompare key_value_comp
+ , KeyValuePrioCompare key_value_pcomp
+ , insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ comp(key_value_comp, this);
+ detail::key_nodeptr_comp<KeyValuePrioCompare, treap_impl>
+ pcomp(key_value_pcomp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), hint.pointed_node(), key, comp, pcomp, 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));
+ this->priv_size_traits().increment();
+ node_algorithms::insert_unique_commit(node_ptr(&priv_header()), to_insert, commit_data);
+ return iterator(to_insert, this);
+ }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase element is constant time.
+ //!
+ //! <b>Throws</b>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (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));
+ detail::key_nodeptr_comp<priority_compare, treap_impl>
+ key_node_pcomp(priv_pcomp(), this);
+ node_algorithms::erase(&priv_header(), to_erase,key_node_pcomp);
+ 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>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator 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>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ 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>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ 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>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator i, Disposer disposer)
+ {
+ 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)
+ 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>: if the internal priority_compare function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(const_iterator 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>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
+ //! The safest thing would be to clear or destroy the container.
+ //!
+ //! <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;
+ 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>: if the priority_compare function throws then weak guarantee and heap invariants are broken.
+ //! The safest thing would be to clear or destroy the container.
+ //!
+ //! <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;
+ 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(&priv_header());
+ 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.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ node_algorithms::clear_and_dispose(node_ptr(&priv_header())
+ , detail::node_disposer<Disposer, treap_impl>(disposer, this));
+ node_algorithms::init_header(&priv_header());
+ 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.
+ 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ return const_iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), 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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), 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<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.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, treap_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp));
+ 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 treap_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!src.empty()){
+ detail::exception_disposer<treap_impl, Disposer>
+ rollback(*this, disposer);
+ node_algorithms::clone
+ (const_node_ptr(&src.priv_header())
+ ,node_ptr(&this->priv_header())
+ ,detail::node_cloner<Cloner, treap_impl>(cloner, this)
+ ,detail::node_disposer<Disposer, treap_impl>(disposer, this));
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ this->priv_comp() = src.priv_comp();
+ rollback.release();
+ }
+ }
+
+ //! <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
+ (node_ptr(&priv_header())));
+ 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 and priority rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ {
+ node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this)
+ , node_ptr(&priv_header())
+ , get_real_value_traits().to_node_ptr(with_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 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)); }
+
+ /// @cond
+ private:
+ template<class Disposer>
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n, Disposer disposer)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase_and_dispose(b++, disposer);
+ return b.unconst();
+ }
+
+ iterator private_erase(const_iterator b, const_iterator e, size_type &n)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase(b++);
+ return b.unconst();
+ }
+ /// @endcond
+
+ private:
+ static treap_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ header_plus_size *r = detail::parent_from_member<header_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &header_plus_size::header_);
+ typename node_plus_pred_t::header_plus_priority_size *n =
+ detail::parent_from_member
+ < typename node_plus_pred_t::header_plus_priority_size
+ , header_plus_size>
+ (r, &node_plus_pred_t::header_plus_priority_size::header_plus_size_);
+ node_plus_pred_t *pn = detail::parent_from_member
+ < node_plus_pred_t
+ , typename node_plus_pred_t::header_plus_priority_size>
+ (n, &node_plus_pred_t::header_plus_priority_size_);
+ data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(pn, &data_t::node_plus_pred_);
+ treap_impl *tr = detail::parent_from_member<treap_impl, data_t>(d, &treap_impl::data_);
+ return *tr;
+ }
+
+ static treap_impl &priv_container_from_iterator(const const_iterator &it)
+ { return priv_container_from_end_iterator(it.end_iterator_from_it()); }
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{
+ typedef treap_impl<Config> tree_type;
+ typedef typename tree_type::const_iterator const_iterator;
+
+ 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 Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_impl<T, Options...> &x, const treap_impl<T, Options...> &y)
+#else
+(const treap_impl<Config> &x, const treap_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(treap_impl<T, Options...> &x, treap_impl<T, Options...> &y)
+#else
+(treap_impl<Config> &x, treap_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+/// @cond
+#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none
+ >
+#else
+template<class T, class ...Options>
+#endif
+struct make_treap_opt
+{
+ typedef typename pack_options
+ < treap_set_defaults<T>,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef treap_setopt
+ < value_traits
+ , typename packed_options::compare
+ , typename packed_options::priority
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c treap that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_trie
+{
+ /// @cond
+ typedef treap_impl
+ < typename make_treap_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class treap
+ : public make_trie<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_trie
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ public:
+ typedef typename Base::value_compare value_compare;
+ typedef typename Base::priority_compare priority_compare;
+ typedef typename Base::value_traits value_traits;
+ typedef typename Base::real_value_traits real_value_traits;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ treap( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, pcmp, v_traits)
+ {}
+
+ template<class Iterator>
+ treap( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(unique, b, e, cmp, pcmp, v_traits)
+ {}
+
+ static treap &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<treap &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const treap &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const treap &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static treap &container_from_it(iterator it)
+ { return static_cast<treap &>(Base::container_from_iterator(it)); }
+
+ static const treap &container_from_it(const_iterator it)
+ { return static_cast<const treap &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TRIE_HPP

Added: sandbox/boost/intrusive/treap_algorithms.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/treap_algorithms.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,801 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008.
+//
+// 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_TRIE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_TRIE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.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 <algorithm>
+
+
+namespace boost {
+namespace intrusive {
+
+//! treap_algorithms provides basic algorithms to manipulate
+//! nodes forming a treap.
+//!
+//! (1) the header node is maintained with links not only to the root
+//! but also to the leftmost node of the tree, to enable constant time
+//! begin(), and to the rightmost node of the tree, to enable linear time
+//! performance when used with the generic set algorithms (set_union,
+//! etc.);
+//!
+//! (2) when a node being deleted has two children its successor node is
+//! relinked into its place, rather than copied, so that the only
+//! pointers invalidated are those referring to the deleted node.
+//!
+//! treap_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_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class treap_algorithms
+{
+ public:
+ typedef NodeTraits node_traits;
+ typedef typename NodeTraits::node node;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+
+ /// @cond
+ private:
+
+ class remove_on_destroy
+ {
+ remove_on_destroy(const remove_on_destroy&);
+ remove_on_destroy& operator=(const remove_on_destroy&);
+ public:
+ remove_on_destroy(node_ptr header, node_ptr z)
+ : header_(header), z_(z), remove_it_(true)
+ {}
+ ~remove_on_destroy()
+ {
+ if(remove_it_){
+ tree_algorithms::erase(header_, z_);
+ }
+ }
+
+ void release()
+ { remove_it_ = false; }
+
+ const node_ptr header_;
+ const node_ptr z_;
+ bool remove_it_;
+ };
+
+ class rerotate_on_destroy
+ {
+ rerotate_on_destroy(const remove_on_destroy&);
+ rerotate_on_destroy& operator=(const rerotate_on_destroy&);
+
+ public:
+ rerotate_on_destroy(node_ptr header, node_ptr p, std::size_t &n)
+ : header_(header), p_(p), n_(n), remove_it_(true)
+ {}
+
+ ~rerotate_on_destroy()
+ {
+ if(remove_it_){
+ rotate_up_n(header_, p_, n_);
+ }
+ }
+
+ void release()
+ { remove_it_ = false; }
+
+ const node_ptr header_;
+ const node_ptr p_;
+ std::size_t &n_;
+ bool remove_it_;
+ };
+
+ static void rotate_up_n(const node_ptr header, const node_ptr p, std::size_t n)
+ {
+ for( node_ptr p_parent = NodeTraits::get_parent(p)
+ ; n--
+ ; p_parent = NodeTraits::get_parent(p)){
+ //Check if left child
+ if(p == NodeTraits::get_left(p_parent)){
+ tree_algorithms::rotate_right(p_parent, header);
+ }
+ else{ //Right child
+ tree_algorithms::rotate_left(p_parent, header);
+ }
+ }
+ }
+
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return tree_algorithms::end_node(header); }
+
+ //! This type is the information that will be
+ //! filled by insert_unique_check
+ struct insert_commit_data
+ /// @cond
+ : public tree_algorithms::insert_commit_data
+ /// @endcond
+ {
+ /// @cond
+ std::size_t rotations;
+ /// @endcond
+ };
+
+ //! <b>Requires</b>: header1 and header2 must be the header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two trees. After the function header1 will contain
+ //! links to the second tree and header2 will have links to the first tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_tree(node_ptr header1, node_ptr header2)
+ { return tree_algorithms::swap_tree(header1, header2); }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::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
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ { tree_algorithms::swap_nodes(node1, header1, node2, header2); }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, 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);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); }
+
+ //! <b>Requires</b>: node is a tree node but not the header.
+ //!
+ //! <b>Effects</b>: Unlinks the node and rebalances the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class NodePriorityCompare>
+ static void unlink(node_ptr node, NodePriorityCompare prio)
+ {
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
+ while(!is_header(x))
+ x = NodeTraits::get_parent(x);
+ erase(x, node, prio);
+ }
+ }
+
+ //! <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(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_node_ptr node)
+ { return tree_algorithms::unique(node); }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ { return tree_algorithms::count(node); }
+
+ //! <b>Requires</b>: header is the header node of the tree.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes above the header.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t size(const_node_ptr header)
+ { return tree_algorithms::size(header); }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ { return tree_algorithms::next_node(p); }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ { return tree_algorithms::prev_node(p); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ { tree_algorithms::init(node); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ {
+ tree_algorithms::init_header(header);
+ }
+
+ //! <b>Requires</b>: header must be the header of a tree, z a node
+ //! of that tree and z != header.
+ //!
+ //! <b>Effects</b>: Erases node "z" from the tree with header "header".
+ //!
+ //! <b>Complexity</b>: Amortized constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class NodePriorityCompare>
+ static node_ptr erase(node_ptr header, node_ptr z, NodePriorityCompare pcomp)
+ {
+ rebalance_for_erasure(header, z, pcomp);
+ tree_algorithms::erase(header, z);
+// assert(check_invariant(header, pcomp));
+ 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()(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()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ {
+ tree_algorithms::clone(source_header, target_header, 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()(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.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ { tree_algorithms::clear_and_dispose(header, disposer); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::lower_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::upper_bound(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::find(header, key, comp); }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an a pair of node_ptr delimiting a range containing
+ //! all elements that are equivalent to "key" according to "comp" or an
+ //! empty range that indicates the position where those elements would be
+ //! if they there are no equivalent elements.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, node_ptr> equal_range
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ { return tree_algorithms::equal_range(header, key, comp); }
+
+ //! <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, class PriorityNodeCompare>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp, PriorityNodeCompare pcomp)
+ {
+ insert_commit_data commit_data;
+ tree_algorithms::insert_equal_upper_bound_check(h, new_node, comp, commit_data);
+ rebalance_after_insertion_check(h, commit_data.node, new_node, pcomp, commit_data.rotations);
+ tree_algorithms::insert_unique_commit(h, new_node, commit_data);
+ rebalance_after_insertion_commit(h, new_node, commit_data.rotations);
+ 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, class NodePriorityCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp, NodePriorityCompare pcomp)
+ {
+ insert_commit_data commit_data;
+ tree_algorithms::insert_equal_lower_bound_check(h, new_node, comp, commit_data);
+ rebalance_after_insertion_check(h, commit_data.node, new_node, pcomp, commit_data.rotations);
+ tree_algorithms::insert_unique_commit(h, new_node, commit_data);
+ rebalance_after_insertion_commit(h, new_node, commit_data.rotations);
+ 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.
+ template<class NodePtrCompare, class NodePriorityCompare>
+ static node_ptr insert_equal
+ (node_ptr h, node_ptr hint, node_ptr new_node, NodePtrCompare comp, NodePriorityCompare pcomp)
+ {
+ insert_commit_data commit_data;
+ tree_algorithms::insert_equal_check(h, hint, new_node, comp, commit_data);
+ rebalance_after_insertion_check(h, commit_data.node, new_node, pcomp, commit_data.rotations);
+ tree_algorithms::insert_unique_commit(h, new_node, commit_data);
+ rebalance_after_insertion_commit(h, new_node, commit_data.rotations);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare, class KeyNodePtrPrioCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, const KeyType &key
+ ,KeyNodePtrCompare comp, KeyNodePtrPrioCompare pcomp
+ ,insert_commit_data &commit_data)
+ {
+ std::pair<node_ptr, bool> ret =
+ tree_algorithms::insert_unique_check(header, key, comp, commit_data);
+ if(ret.second)
+ rebalance_after_insertion_check(header, commit_data.node, key, pcomp, commit_data.rotations);
+ return ret;
+ }
+
+ //! <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, class KeyNodePtrPrioCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, node_ptr hint, const KeyType &key
+ ,KeyNodePtrCompare comp, KeyNodePtrPrioCompare pcomp, insert_commit_data &commit_data)
+ {
+ std::pair<node_ptr, bool> ret =
+ tree_algorithms::insert_unique_check(header, hint, key, comp, commit_data);
+ if(ret.second)
+ rebalance_after_insertion_check(header, commit_data.node, key, pcomp, commit_data.rotations);
+ return ret;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_node, const insert_commit_data &commit_data)
+ {
+ tree_algorithms::insert_unique_commit(header, new_node, commit_data);
+ rebalance_after_insertion_commit(header, new_node, commit_data.rotations);
+ }
+
+ //! <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(node_ptr n)
+ { return tree_algorithms::get_header(n); }
+
+ /// @cond
+ private:
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is the header of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_header(const_node_ptr p)
+ {
+ return tree_algorithms::is_header(p);
+ }
+
+ template<class NodePriorityCompare>
+ static void rebalance_for_erasure(node_ptr header, node_ptr z, NodePriorityCompare pcomp)
+ {
+ std::size_t n = 0;
+ rerotate_on_destroy rb(header, z, n);
+
+ node_ptr z_left = NodeTraits::get_left(z);
+ node_ptr z_right = NodeTraits::get_right(z);
+ while(z_left || z_right){
+ if(!z_right || (z_left && pcomp(z_left, z_right))){
+ tree_algorithms::rotate_right(z, header);
+ }
+ else{
+ tree_algorithms::rotate_left(z, header);
+ }
+ ++n;
+ z_left = NodeTraits::get_left(z);
+ z_right = NodeTraits::get_right(z);
+ }
+ rb.release();
+ }
+
+ template<class Key, class KeyNodePriorityCompare>
+ static void rebalance_after_insertion_check
+ ( const_node_ptr header, const_node_ptr upnode, const Key &k
+ , KeyNodePriorityCompare pcomp, std::size_t &num_rotations)
+ {
+ //First check rotations since pcomp can throw
+ num_rotations = 0;
+ std::size_t n = 0;
+ while(upnode != header && pcomp(k, upnode)){
+ ++n;
+ upnode = NodeTraits::get_parent(upnode);
+ }
+ num_rotations = n;
+ }
+
+ static void rebalance_after_insertion_commit(node_ptr header, node_ptr p, std::size_t n)
+ {
+ // Now to n rotations
+ for( node_ptr p_parent = NodeTraits::get_parent(p)
+ ; n--
+ ; p_parent = NodeTraits::get_parent(p)){
+ //Check if left child
+ if(p == NodeTraits::get_left(p_parent)){
+ tree_algorithms::rotate_right(p_parent, header);
+ }
+ else{ //Right child
+ tree_algorithms::rotate_left(p_parent, header);
+ }
+ }
+ }
+
+ template<class NodePriorityCompare>
+ static bool check_invariant(const_node_ptr header, NodePriorityCompare pcomp)
+ {
+ node_ptr beg = begin_node(header);
+ node_ptr end = end_node(header);
+
+ while(beg != end){
+ node_ptr p = NodeTraits::get_parent(beg);
+ if(p != header){
+ if(pcomp(beg, p))
+ return false;
+ }
+ beg = next_node(beg);
+ }
+ return true;
+ }
+
+ /// @endcond
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TRIE_ALGORITHMS_HPP

Added: sandbox/boost/intrusive/treap_set.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/treap_set.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,2406 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2008
+//
+// 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_TRIE_SET_HPP
+#define BOOST_INTRUSIVE_TRIE_SET_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/treap.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+#include <iterator>
+
+namespace boost {
+namespace intrusive {
+
+//! The class template treap_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<>,
+//! \c compare<> and \c priority_compare<>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class treap_set_impl
+{
+ /// @cond
+ typedef treap_impl<Config> tree_type;
+ //! This class is
+ //! non-copyable
+ treap_set_impl (const treap_set_impl&);
+
+ //! This class is
+ //! non-assignable
+ treap_set_impl &operator =(const treap_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::priority_compare priority_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty treap_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.
+ treap_set_impl( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, pcmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty treap_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.
+ template<class Iterator>
+ treap_set_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(true, b, e, cmp, pcmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_set
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~treap_set_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator top()
+ { return tree_.top(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator top() const
+ { return this->ctop(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator ctop() const
+ { return tree_.ctop(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
+ //! reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rtop()
+ { return tree_.rtop(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rtop() const
+ { return tree_.crtop(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crtop() const
+ { return tree_.crtop(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of treap_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static treap_set_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<treap_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &treap_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of treap_set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap_set associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const treap_set_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<treap_set_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &treap_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static treap_set_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<treap_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &treap_set_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of set.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the set associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ static const treap_set_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<treap_set_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &treap_set_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the treap_set.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the treap_set.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two sets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(treap_set_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const treap_set_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to inserts value into the treap_set.
+ //!
+ //! <b>Returns</b>: If the value
+ //! is not already present inserts it and returns a pair containing the
+ //! iterator to the new value and true. If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert(reference value)
+ { return tree_.insert_unique(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Tries to to insert x into the treap_set, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the
+ //! new element was inserted into the treap_set.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ 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 ascapegoatitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using
+ //! a user provided key instead of the value itself.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If 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 treap_set.
+ 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 ascapegoatitrary key with the contained values.
+ //!
+ //! <b>Effects</b>: Checks if a value can be inserted in the treap_set, using
+ //! a user provided key instead of the value itself, using "hint"
+ //! as a hint to where it will be inserted.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing an iterator to the already present value
+ //! and false. If the value can be inserted returns true in the returned
+ //! pair boolean and fills "commit_data" that is meant to be used with
+ //! the "insert_commit" function.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it's amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If 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 treap_set.
+ 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 treap_set between
+ //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
+ //!
+ //! <b>Effects</b>: Inserts the value in the treap_set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Returns</b>: An iterator to the newly inserted object.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ iterator insert_commit(reference value, const insert_commit_data &commit_data)
+ { return tree_.insert_unique_commit(value, commit_data); }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a range into the treap_set.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Basic guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_unique(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is 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.
+ 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); }
+
+ #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 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.
+ 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.
+ 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.
+ 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.
+ 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_.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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a treap_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! treap_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! treap_set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a treap_set/treap_multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ //! <b>Returns</b>: The balance factor (alpha) used in this tree
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ float balance_factor() const
+ { return tree_.balance_factor(); }
+
+ //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
+ //!
+ //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
+ //! the tree if the new balance factor is stricter (less) than the old factor.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ void balance_factor(float new_alpha)
+ { tree_.balance_factor(new_alpha); }
+
+ /// @cond
+ friend bool operator==(const treap_set_impl &x, const treap_set_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const treap_set_impl &x, const treap_set_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y)
+#else
+(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y)
+#else
+(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y)
+#else
+(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_set_impl<T, Options...> &x, const treap_set_impl<T, Options...> &y)
+#else
+(const treap_set_impl<Config> &x, const treap_set_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(treap_set_impl<T, Options...> &x, treap_set_impl<T, Options...> &y)
+#else
+(treap_set_impl<Config> &x, treap_set_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c treap_set that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_treap_set
+{
+ /// @cond
+ typedef treap_set_impl
+ < typename make_treap_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::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>
+#else
+template<class T, class ...Options>
+#endif
+class treap_set
+ : public make_treap_set<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_treap_set
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ public:
+ typedef typename Base::value_compare value_compare;
+ typedef typename Base::priority_compare priority_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));
+
+ treap_set( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, pcmp, v_traits)
+ {}
+
+ template<class Iterator>
+ treap_set( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, pcmp, v_traits)
+ {}
+
+ static treap_set &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<treap_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const treap_set &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const treap_set &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static treap_set &container_from_iterator(iterator it)
+ { return static_cast<treap_set &>(Base::container_from_iterator(it)); }
+
+ static const treap_set &container_from_iterator(const_iterator it)
+ { return static_cast<const treap_set &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+//! The class template treap_multiset is an intrusive container, that mimics most of
+//! the interface of std::treap_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<>,
+//! \c compare<> and \c priority_compare<>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class treap_multiset_impl
+{
+ /// @cond
+ typedef treap_impl<Config> tree_type;
+
+ //Non-copyable and non-assignable
+ treap_multiset_impl (const treap_multiset_impl&);
+ treap_multiset_impl &operator =(const treap_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::priority_compare priority_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;
+
+ /// @cond
+ private:
+ tree_type tree_;
+ /// @endcond
+
+ public:
+ //! <b>Effects</b>: Constructs an empty treap_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 of the value_compare/priority_compare objects throw.
+ treap_multiset_impl( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(cmp, pcmp, v_traits)
+ {}
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty treap_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/priority_compare objects throw.
+ template<class Iterator>
+ treap_multiset_impl( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : tree_(false, b, e, cmp, pcmp, v_traits)
+ {}
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the treap_multiset
+ //! are not deleted (i.e. no destructors are called).
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~treap_multiset_impl()
+ {}
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return tree_.begin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return tree_.cbegin(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return tree_.end(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return tree_.cend(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the highest priority object of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator top()
+ { return tree_.top(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator top() const
+ { return this->ctop(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the highest priority object of the tree..
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator ctop() const
+ { return tree_.ctop(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return tree_.rbegin(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return tree_.crbegin(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return tree_.rend(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return tree_.crend(); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the highest priority object of the
+ //! reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rtop()
+ { return tree_.rtop(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority objec
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rtop() const
+ { return tree_.crtop(); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the highest priority object
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crtop() const
+ { return tree_.crtop(); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of treap_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static treap_multiset_impl &container_from_end_iterator(iterator end_iterator)
+ {
+ return *detail::parent_from_member<treap_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &treap_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of treap_multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the treap_multiset associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const treap_multiset_impl &container_from_end_iterator(const_iterator end_iterator)
+ {
+ return *detail::parent_from_member<treap_multiset_impl, tree_type>
+ ( &tree_type::container_from_end_iterator(end_iterator)
+ , &treap_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static treap_multiset_impl &container_from_iterator(iterator it)
+ {
+ return *detail::parent_from_member<treap_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &treap_multiset_impl::tree_);
+ }
+
+ //! <b>Precondition</b>: it must be a valid const_iterator of multiset.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the multiset associated to the iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const treap_multiset_impl &container_from_iterator(const_iterator it)
+ {
+ return *detail::parent_from_member<treap_multiset_impl, tree_type>
+ ( &tree_type::container_from_iterator(it)
+ , &treap_multiset_impl::tree_);
+ }
+
+ //! <b>Effects</b>: Returns the key_compare object used by the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If key_compare copy-constructor throws.
+ key_compare key_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return tree_.value_comp(); }
+
+ //! <b>Effects</b>: Returns true if the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return tree_.empty(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the treap_multiset.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this if,
+ //! constant-time size option is enabled. Constant-time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ { return tree_.size(); }
+
+ //! <b>Effects</b>: Swaps the contents of two treap_multisets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the swap() call for the comparison functor
+ //! found using ADL throws. Strong guarantee.
+ void swap(treap_multiset_impl& other)
+ { tree_.swap(other.tree_); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //! Cloner should yield to nodes equivalent to the original nodes.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this. Copies the predicate from the source container.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws or predicate copy assignment throws. Basic guarantee.
+ template <class Cloner, class Disposer>
+ void clone_from(const treap_multiset_impl &src, Cloner cloner, Disposer disposer)
+ { tree_.clone_from(src.tree_, cloner, disposer); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the treap_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: If the internal value_compare ordering function throws. Strong guarantee.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert(reference value)
+ { return tree_.insert_equal(value); }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts x into the treap_multiset, using pos as a hint to
+ //! where it will be inserted.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: If 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(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 treap_multiset.
+ //!
+ //! <b>Returns</b>: An iterator that points to the position where the new
+ //! element was inserted.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: If 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.
+ template<class Iterator>
+ void insert(Iterator b, Iterator e)
+ { tree_.insert_equal(b, e); }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased element.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(const_iterator i)
+ { return tree_.erase(i); }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Returns</b>: An iterator to the element after the erased elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is 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.
+ 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); }
+
+ #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>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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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.
+ 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<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.
+ 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>: value must be an lvalue and shall be in a treap_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! treap_multiset that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ { return tree_type::s_iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the treap_multiset
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a treap_multiset of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! treap_multiset that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return tree_.iterator_to(value); }
+
+ //! <b>Requires</b>: value shall not be in a treap_multiset/treap_multiset.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { tree_type::init_node(value); }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ { tree_.replace_node(replace_this, with_this); }
+
+ //! <b>Effects</b>: Rebalances the tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear.
+ void rebalance()
+ { tree_.rebalance(); }
+
+ //! <b>Requires</b>: old_root is a node of a tree.
+ //!
+ //! <b>Effects</b>: Rebalances the subtree rooted at old_root.
+ //!
+ //! <b>Returns</b>: The new root of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ iterator rebalance_subtree(iterator root)
+ { return tree_.rebalance_subtree(root); }
+
+ //! <b>Returns</b>: The balance factor (alpha) used in this tree
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ float balance_factor() const
+ { return tree_.balance_factor(); }
+
+ //! <b>Requires</b>: new_alpha must be a value between 0.5 and 1.0
+ //!
+ //! <b>Effects</b>: Establishes a new balance factor (alpha) and rebalances
+ //! the tree if the new balance factor is stricter (less) than the old factor.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Linear to the elements in the subtree.
+ void balance_factor(float new_alpha)
+ { tree_.balance_factor(new_alpha); }
+
+ /// @cond
+ friend bool operator==(const treap_multiset_impl &x, const treap_multiset_impl &y)
+ { return x.tree_ == y.tree_; }
+
+ friend bool operator<(const treap_multiset_impl &x, const treap_multiset_impl &y)
+ { return x.tree_ < y.tree_; }
+ /// @endcond
+};
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y)
+#else
+(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y)
+#else
+(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y)
+#else
+(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(const treap_multiset_impl<T, Options...> &x, const treap_multiset_impl<T, Options...> &y)
+#else
+(const treap_multiset_impl<Config> &x, const treap_multiset_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+(treap_multiset_impl<T, Options...> &x, treap_multiset_impl<T, Options...> &y)
+#else
+(treap_multiset_impl<Config> &x, treap_multiset_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+//! Helper metafunction to define a \c treap_multiset that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_treap_multiset
+{
+ /// @cond
+ typedef treap_multiset_impl
+ < typename make_treap_opt<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+ > implementation_defined;
+ /// @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>
+#else
+template<class T, class ...Options>
+#endif
+class treap_multiset
+ : public make_treap_multiset<T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ typedef typename make_treap_multiset
+ <T,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type Base;
+
+ public:
+ typedef typename Base::value_compare value_compare;
+ typedef typename Base::priority_compare priority_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));
+
+ treap_multiset( const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, pcmp, v_traits)
+ {}
+
+ template<class Iterator>
+ treap_multiset( Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const priority_compare &pcmp = priority_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(b, e, cmp, pcmp, v_traits)
+ {}
+
+ static treap_multiset &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<treap_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const treap_multiset &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const treap_multiset &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static treap_multiset &container_from_iterator(iterator it)
+ { return static_cast<treap_multiset &>(Base::container_from_iterator(it)); }
+
+ static const treap_multiset &container_from_iterator(const_iterator it)
+ { return static_cast<const treap_multiset &>(Base::container_from_iterator(it)); }
+};
+
+#endif
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TRIE_SET_HPP

Added: sandbox/boost/intrusive/trivial_value_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/trivial_value_traits.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,43 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_TRIVIAL_VALUE_TRAITS_HPP
+#define BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP
+
+#include <boost/intrusive/link_mode.hpp>
+
+namespace boost {
+namespace intrusive {
+
+//!This value traits template is used to create value traits
+//!from user defined node traits where value_traits::value_type and
+//!node_traits::node should be equal
+template<class NodeTraits, link_mode_type LinkMode = normal_link>
+struct trivial_value_traits
+{
+ typedef NodeTraits node_traits;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename node_traits::const_node_ptr const_node_ptr;
+ typedef typename node_traits::node value_type;
+ typedef node_ptr pointer;
+ typedef const_node_ptr const_pointer;
+ static const link_mode_type link_mode = LinkMode;
+ static node_ptr to_node_ptr (value_type &value) { return node_ptr(&value); }
+ static const_node_ptr to_node_ptr (const value_type &value) { return const_node_ptr(&value); }
+ static pointer to_value_ptr(node_ptr n) { return pointer(n); }
+ static const_pointer to_value_ptr(const_node_ptr n) { return const_pointer(n); }
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#endif //BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP

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

Added: sandbox/boost/intrusive/unordered_set_hook.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/intrusive/unordered_set_hook.hpp 2009-02-17 13:15:44 EST (Tue, 17 Feb 2009)
@@ -0,0 +1,425 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-2008
+//
+// 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_UNORDERED_SET_HOOK_HPP
+#define BOOST_INTRUSIVE_UNORDERED_SET_HOOK_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/slist_hook.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/detail/generic_hook.hpp>
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template<class VoidPointer, bool StoreHash, bool OptimizeMultiKey>
+struct unordered_node
+ : public slist_node<VoidPointer>
+{
+ typedef typename boost::pointer_to_other
+ < VoidPointer
+ , unordered_node<VoidPointer, StoreHash, OptimizeMultiKey>
+ >::type node_ptr;
+ node_ptr prev_in_group_;
+ std::size_t hash_;
+};
+
+template<class VoidPointer>
+struct unordered_node<VoidPointer, false, true>
+ : public slist_node<VoidPointer>
+{
+ typedef typename boost::pointer_to_other
+ < VoidPointer
+ , unordered_node<VoidPointer, false, true>
+ >::type node_ptr;
+ node_ptr prev_in_group_;
+};
+
+template<class VoidPointer>
+struct unordered_node<VoidPointer, true, false>
+ : public slist_node<VoidPointer>
+{
+ typedef typename boost::pointer_to_other
+ < VoidPointer
+ , unordered_node<VoidPointer, true, false>
+ >::type node_ptr;
+ std::size_t hash_;
+};
+
+template<class VoidPointer, bool StoreHash, bool OptimizeMultiKey>
+struct unordered_node_traits
+ : public slist_node_traits<VoidPointer>
+{
+ typedef slist_node_traits<VoidPointer> reduced_slist_node_traits;
+ typedef unordered_node<VoidPointer, StoreHash, OptimizeMultiKey> node;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ static const bool store_hash = StoreHash;
+ static const bool optimize_multikey = OptimizeMultiKey;
+
+ static node_ptr get_next(const_node_ptr n)
+ { return node_ptr(&static_cast<node &>(*n->next_)); }
+
+ static void set_next(node_ptr n, node_ptr next)
+ { n->next_ = next; }
+
+ static node_ptr get_prev_in_group(const_node_ptr n)
+ { return n->prev_in_group_; }
+
+ static void set_prev_in_group(node_ptr n, node_ptr prev)
+ { n->prev_in_group_ = prev; }
+
+ static std::size_t get_hash(const_node_ptr n)
+ { return n->hash_; }
+
+ static void set_hash(node_ptr n, std::size_t h)
+ { n->hash_ = h; }
+};
+
+template<class NodeTraits>
+struct unordered_group_adapter
+{
+ typedef typename NodeTraits::node node;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+
+ static node_ptr get_next(const_node_ptr n)
+ { return NodeTraits::get_prev_in_group(n); }
+
+ static void set_next(node_ptr n, node_ptr next)
+ { NodeTraits::set_prev_in_group(n, next); }
+};
+
+template<class NodeTraits>
+struct unordered_algorithms
+ : public circular_slist_algorithms<NodeTraits>
+{
+ typedef circular_slist_algorithms<NodeTraits> base_type;
+ typedef unordered_group_adapter<NodeTraits> group_traits;
+ typedef circular_slist_algorithms<group_traits> group_algorithms;
+
+ static void init(typename base_type::node_ptr n)
+ {
+ base_type::init(n);
+ group_algorithms::init(n);
+ }
+
+ static void init_header(typename base_type::node_ptr n)
+ {
+ base_type::init_header(n);
+ group_algorithms::init_header(n);
+ }
+
+ static void unlink(typename base_type::node_ptr n)
+ {
+ base_type::unlink(n);
+ group_algorithms::unlink(n);
+ }
+};
+
+template<class VoidPointer, bool StoreHash, bool OptimizeMultiKey>
+struct get_uset_node_algo
+{
+ typedef typename detail::if_c
+ < (StoreHash || OptimizeMultiKey)
+ , unordered_node_traits<VoidPointer, StoreHash, OptimizeMultiKey>
+ , slist_node_traits<VoidPointer>
+ >::type node_traits_type;
+ typedef typename detail::if_c
+ < OptimizeMultiKey
+ , unordered_algorithms<node_traits_type>
+ , circular_slist_algorithms<node_traits_type>
+ >::type type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c unordered_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>
+#endif
+struct make_unordered_set_base_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_uset_node_algo<typename packed_options::void_pointer
+ , packed_options::store_hash
+ , packed_options::optimize_multikey
+ >
+ , typename packed_options::tag
+ , packed_options::link_mode
+ , detail::UsetBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Derive a class from unordered_set_base_hook in order to store objects in
+//! in an unordered_set/unordered_multi_set. unordered_set_base_hook holds the data necessary to maintain
+//! the unordered_set/unordered_multi_set and provides an appropriate value_traits class for unordered_set/unordered_multi_set.
+//!
+//! The hook admits the following options: \c tag<>, \c void_pointer<>,
+//! \c link_mode<>, \c store_hash<> and \c optimize_multikey<>.
+//!
+//! \c tag<> defines a tag to identify the node.
+//! The same tag value can be used in different classes, but if a class is
+//! derived from more than one \c list_base_hook, then each \c list_base_hook needs its
+//! unique tag.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c store_hash<> will tell the hook to store the hash of the value
+//! to speed up rehashings.
+//!
+//! \c optimize_multikey<> will tell the hook to store a link to form a group
+//! with other value with the same value to speed up searches and insertions
+//! in unordered_multisets with a great number of with equivalent keys.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3, class O4>
+#endif
+class unordered_set_base_hook
+ : public make_unordered_set_base_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ unordered_set_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ unordered_set_base_hook(const unordered_set_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ unordered_set_base_hook& operator=(const unordered_set_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an unordered_set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~unordered_set_base_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(unordered_set_base_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c unordered_set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+
+//! Helper metafunction to define a \c unordered_set_member_hook that yields to the same
+//! type when the same options (either explicitly or implicitly) are used.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1 = none, class O2 = none, class O3 = none, class O4 = none>
+#endif
+struct make_unordered_set_member_hook
+{
+ /// @cond
+ typedef typename pack_options
+ < hook_defaults,
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type packed_options;
+
+ typedef detail::generic_hook
+ < get_uset_node_algo< typename packed_options::void_pointer
+ , packed_options::store_hash
+ , packed_options::optimize_multikey
+ >
+ , member_tag
+ , packed_options::link_mode
+ , detail::NoBaseHook
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+//! Put a public data member unordered_set_member_hook in order to store objects of this class in
+//! an unordered_set/unordered_multi_set. unordered_set_member_hook holds the data necessary for maintaining the
+//! unordered_set/unordered_multi_set and provides an appropriate value_traits class for unordered_set/unordered_multi_set.
+//!
+//! The hook admits the following options: \c void_pointer<>,
+//! \c link_mode<> and \c store_hash<>.
+//!
+//! \c void_pointer<> is the pointer type that will be used internally in the hook
+//! and the the container configured to use this hook.
+//!
+//! \c link_mode<> will specify the linking mode of the hook (\c normal_link,
+//! \c auto_unlink or \c safe_link).
+//!
+//! \c store_hash<> will tell the hook to store the hash of the value
+//! to speed up rehashings.
+#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+template<class ...Options>
+#else
+template<class O1, class O2, class O3, class O4>
+#endif
+class unordered_set_member_hook
+ : public make_unordered_set_member_hook<
+ #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
+ O1, O2, O3, O4
+ #else
+ Options...
+ #endif
+ >::type
+{
+ #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ unordered_set_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ unordered_set_member_hook(const unordered_set_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ unordered_set_member_hook& operator=(const unordered_set_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an unordered_set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~unordered_set_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(unordered_set_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c unordered_set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_UNORDERED_SET_HOOK_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk