Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

View File

@@ -0,0 +1,344 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_ANY_HOOK_HPP
#define BOOST_INTRUSIVE_ANY_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/any_node_and_algorithms.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/detail/generic_hook.hpp>
#include <boost/intrusive/detail/pointer_to_other.hpp>
namespace boost {
namespace intrusive {
/// @cond
template<class VoidPointer>
struct get_any_node_algo
{
typedef any_algorithms<VoidPointer> type;
};
/// @endcond
//! Helper metafunction to define a \c \c any_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = none, class O2 = none, class O3 = none>
#endif
struct make_any_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_any_node_algo<typename packed_options::void_pointer>
, typename packed_options::tag
, packed_options::link_mode
, detail::AnyBaseHook
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from this hook in order to store objects of that class
//! in an intrusive container.
//!
//! 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 any_base_hook, then each \c any_base_hook needs its
//! unique tag.
//!
//! \c link_mode<> will specify the linking mode of the hook (\c normal_link, \c safe_link).
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the the container configured to use this hook.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1, class O2, class O3>
#endif
class any_base_hook
: public make_any_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
any_base_hook();
//! <b>Effects</b>: If link_mode is 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.
any_base_hook(const any_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.
any_base_hook& operator=(const any_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 container an assertion is raised.
//!
//! <b>Throws</b>: Nothing.
~any_base_hook();
//! <b>Precondition</b>: link_mode must be \c safe_link.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c container::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
#endif
};
//! Helper metafunction to define a \c \c any_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_any_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_any_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 intrusive container.
//!
//! 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 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 any_member_hook
: public make_any_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
any_member_hook();
//! <b>Effects</b>: If link_mode is 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.
any_member_hook(const any_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.
any_member_hook& operator=(const any_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 container an assertion is raised.
//!
//! <b>Throws</b>: Nothing.
~any_member_hook();
//! <b>Precondition</b>: link_mode must be \c safe_link.
//!
//! <b>Returns</b>: true, if the node belongs to a container, false
//! otherwise. This function can be used to test whether \c container::iterator_to
//! will return a valid iterator.
//!
//! <b>Complexity</b>: Constant
bool is_linked() const;
#endif
};
/// @cond
namespace detail{
template<class ValueTraits>
struct any_to_get_base_pointer_type
{
typedef typename pointer_to_other
<typename ValueTraits::boost_intrusive_tags::node_traits::node_ptr, void>::type type;
};
template<class ValueTraits>
struct any_to_get_member_pointer_type
{
typedef typename pointer_to_other
<typename ValueTraits::node_ptr, void>::type type;
};
//!This option setter specifies that the container
//!must use the specified base hook
template<class BaseHook, template <class> class NodeTraits>
struct any_to_some_hook
{
typedef typename BaseHook::template pack<none>::value_traits old_value_traits;
template<class Base>
struct pack : public Base
{
struct value_traits : public old_value_traits
{
static const bool is_any_hook = true;
typedef typename detail::eval_if_c
< detail::internal_base_hook_bool_is_true<old_value_traits>::value
, any_to_get_base_pointer_type<old_value_traits>
, any_to_get_member_pointer_type<old_value_traits>
>::type void_pointer;
typedef NodeTraits<void_pointer> node_traits;
};
};
};
} //namespace detail{
/// @endcond
//!This option setter specifies that
//!any hook should behave as an slist hook
template<class BaseHook>
struct any_to_slist_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_slist_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as an list hook
template<class BaseHook>
struct any_to_list_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_list_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as a set hook
template<class BaseHook>
struct any_to_set_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_rbtree_node_traits>
/// @endcond
{};
//!This option setter specifies that
//!any hook should behave as an avl_set hook
template<class BaseHook>
struct any_to_avl_set_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_avltree_node_traits>
/// @endcond
{};
//!This option setter specifies that any
//!hook should behave as a bs_set hook
template<class BaseHook>
struct any_to_bs_set_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_tree_node_traits>
/// @endcond
{};
//!This option setter specifies that any hook
//!should behave as an unordered set hook
template<class BaseHook>
struct any_to_unordered_set_hook
/// @cond
: public detail::any_to_some_hook<BaseHook, any_unordered_node_traits>
/// @endcond
{};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_ANY_HOOK_HPP

2358
test/external/boost/intrusive/avl_set.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,297 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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_AVL_SET_HOOK_HPP
#define BOOST_INTRUSIVE_AVL_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/avltree_node.hpp>
#include <boost/intrusive/avltree_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_avl_set_node_algo
{
typedef avltree_algorithms<avltree_node_traits<VoidPointer, OptimizeSize> > type;
};
/// @endcond
//! Helper metafunction to define a \c avl_set_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = none, class O2 = none, class O3 = none, class O4 = none>
#endif
struct make_avl_set_base_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<hook_defaults, O1, O2, O3, O4>
#else
<hook_defaults, Options...>
#endif
::type packed_options;
typedef detail::generic_hook
< get_avl_set_node_algo<typename packed_options::void_pointer
,packed_options::optimize_size>
, typename packed_options::tag
, packed_options::link_mode
, detail::AvlSetBaseHook
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from avl_set_base_hook in order to store objects in
//! in an avl_set/avl_multiset. avl_set_base_hook holds the data necessary to maintain
//! the avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_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 avl_set_base_hook
: public make_avl_set_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3, O4>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
avl_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.
avl_set_base_hook(const avl_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.
avl_set_base_hook& operator=(const avl_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.
~avl_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(avl_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 avl_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_avl_set_member_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<hook_defaults, O1, O2, O3, O4>
#else
<hook_defaults, Options...>
#endif
::type packed_options;
typedef detail::generic_hook
< get_avl_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 avl_set_member_hook in order to store objects of this class in
//! an avl_set/avl_multiset. avl_set_member_hook holds the data necessary for maintaining the
//! avl_set/avl_multiset and provides an appropriate value_traits class for avl_set/avl_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 avl_set_member_hook
: public make_avl_set_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3, O4>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
avl_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.
avl_set_member_hook(const avl_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.
avl_set_member_hook& operator=(const avl_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.
~avl_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(avl_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_AVL_SET_HOOK_HPP

1682
test/external/boost/intrusive/avltree.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,943 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Daniel K. O. 2005.
// (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_AVLTREE_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_AVLTREE_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 {
//! avltree_algorithms is configured with a NodeTraits class, which encapsulates the
//! information about the node to be manipulated. NodeTraits must support the
//! following interface:
//!
//! <b>Typedefs</b>:
//!
//! <tt>node</tt>: The type of the node that forms the circular list
//!
//! <tt>node_ptr</tt>: A pointer to a node
//!
//! <tt>const_node_ptr</tt>: A pointer to a const node
//!
//! <tt>balance</tt>: The type of the balance factor
//!
//! <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 balance get_balance(const_node_ptr n);</tt>
//!
//! <tt>static void set_balance(node_ptr n, balance b);</tt>
//!
//! <tt>static balance negative();</tt>
//!
//! <tt>static balance zero();</tt>
//!
//! <tt>static balance positive();</tt>
template<class NodeTraits>
class avltree_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;
typedef typename NodeTraits::balance balance;
/// @cond
private:
typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
template<class F>
struct avltree_node_cloner
: private detail::ebo_functor_holder<F>
{
typedef detail::ebo_functor_holder<F> base_t;
avltree_node_cloner(F f)
: base_t(f)
{}
node_ptr operator()(node_ptr p)
{
node_ptr n = base_t::get()(p);
NodeTraits::set_balance(n, NodeTraits::get_balance(p));
return n;
}
};
struct avltree_erase_fixup
{
void operator()(node_ptr to_erase, node_ptr successor)
{ NodeTraits::set_balance(successor, NodeTraits::get_balance(to_erase)); }
};
static node_ptr uncast(const_node_ptr ptr)
{
return node_ptr(const_cast<node*>(::boost::intrusive::detail::boost_intrusive_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 balance
balance c = NodeTraits::get_balance(node1);
NodeTraits::set_balance(node1, NodeTraits::get_balance(node2));
NodeTraits::set_balance(node2, c);
}
//! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
//! and new_node must not be inserted in a tree.
//!
//! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
//! tree with new_node. The tree does not need to be rebalanced
//!
//! <b>Complexity</b>: Logarithmic.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: This function will break container ordering invariants if
//! new_node is not equivalent to node_to_be_replaced according to the
//! ordering rules. This function is faster than erasing and inserting
//! the node, since no rebalancing and comparison is needed.
//!
//!Experimental function
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_balance(new_node, NodeTraits::get_balance(node_to_be_replaced));
}
//! <b>Requires</b>: node is a tree node but not the header.
//!
//! <b>Effects</b>: Unlinks the node and rebalances the tree.
//!
//! <b>Complexity</b>: Average complexity is constant time.
//!
//! <b>Throws</b>: Nothing.
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_balance(header, NodeTraits::zero());
}
//! <b>Requires</b>: header must be the header of a tree, z a node
//! of that tree and z != header.
//!
//! <b>Effects</b>: Erases node "z" from the tree with header "header".
//!
//! <b>Complexity</b>: Amortized constant time.
//!
//! <b>Throws</b>: Nothing.
static node_ptr erase(node_ptr header, node_ptr z)
{
typename tree_algorithms::data_for_rebalance info;
tree_algorithms::erase(header, z, avltree_erase_fixup(), info);
node_ptr x = info.x;
node_ptr x_parent = info.x_parent;
//Rebalance avltree
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)
{
avltree_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.
//! "pos" must be a valid iterator or header (end) node.
//! "pos" must be an iterator pointing to the successor to "new_node"
//! once inserted according to the order of already inserted nodes. This function does not
//! check "pos" and this precondition must be guaranteed by the caller.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node"
//! tree invariants might be broken.
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node)
{
tree_algorithms::insert_before(header, pos, new_node);
rebalance_after_insertion(header, new_node);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering no less than the
//! greatest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is less than the greatest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_back(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_back(header, new_node);
rebalance_after_insertion(header, new_node);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering, no greater than the
//! lowest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is greater than the lowest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_front(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_front(header, new_node);
rebalance_after_insertion(header, new_node);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! KeyNodePtrCompare is a function object that induces a strict weak
//! ordering compatible with the strict weak ordering used to create the
//! the tree. NodePtrCompare compares KeyType with a node_ptr.
//!
//! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
//! tree according to "comp" and obtains the needed information to realize
//! a constant-time node insertion if there is no equivalent node.
//!
//! <b>Returns</b>: If there is an equivalent value
//! returns a pair containing a node_ptr to the already present node
//! and false. If there is not equivalent key can be inserted returns true
//! in the returned pair's boolean and fills "commit_data" that is meant to
//! be used with the "insert_commit" function to achieve a constant-time
//! insertion function.
//!
//! <b>Complexity</b>: Average complexity is at most logarithmic.
//!
//! <b>Throws</b>: If "comp" throws.
//!
//! <b>Notes</b>: This function is used to improve performance when constructing
//! a node is expensive and the user does not want to have two equivalent nodes
//! in the tree: if there is an equivalent value
//! the constructed object must be discarded. Many times, the part of the
//! node that is used to impose the order is much cheaper to construct
//! than the node and this function offers the possibility to use that part
//! to check if the insertion will be successful.
//!
//! If the check is successful, the user can construct the node and use
//! "insert_commit" to insert the node in constant-time. This gives a total
//! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
//!
//! "commit_data" remains valid for a subsequent "insert_unique_commit" only
//! if no more objects are inserted or erased from the set.
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_balance(p) == NodeTraits::zero() && tree_algorithms::is_header(p); }
static void rebalance_after_erasure(node_ptr header, node_ptr x, node_ptr x_parent)
{
for (node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)) {
const balance x_parent_balance = NodeTraits::get_balance(x_parent);
if(x_parent_balance == NodeTraits::zero()){
NodeTraits::set_balance(x_parent,
(x == NodeTraits::get_right(x_parent) ? NodeTraits::negative() : NodeTraits::positive()));
break; // the height didn't change, let's stop here
}
else if(x_parent_balance == NodeTraits::negative()){
if (x == NodeTraits::get_left(x_parent)) {
NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced
x = x_parent;
x_parent = NodeTraits::get_parent(x_parent);
}
else {
// x is right child
// a is left child
node_ptr a = NodeTraits::get_left(x_parent);
BOOST_INTRUSIVE_INVARIANT_ASSERT(a);
if (NodeTraits::get_balance(a) == NodeTraits::positive()) {
// a MUST have a right child
BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_right(a));
rotate_left_right(x_parent, header);
x = NodeTraits::get_parent(x_parent);
x_parent = NodeTraits::get_parent(x);
}
else {
rotate_right(x_parent, header);
x = NodeTraits::get_parent(x_parent);
x_parent = NodeTraits::get_parent(x);
}
// if changed from negative to NodeTraits::positive(), no need to check above
if (NodeTraits::get_balance(x) == NodeTraits::positive()){
break;
}
}
}
else if(x_parent_balance == NodeTraits::positive()){
if (x == NodeTraits::get_right(x_parent)) {
NodeTraits::set_balance(x_parent, NodeTraits::zero()); // balanced
x = x_parent;
x_parent = NodeTraits::get_parent(x_parent);
}
else {
// x is left child
// a is right child
node_ptr a = NodeTraits::get_right(x_parent);
BOOST_INTRUSIVE_INVARIANT_ASSERT(a);
if (NodeTraits::get_balance(a) == NodeTraits::negative()) {
// a MUST have then a left child
BOOST_INTRUSIVE_INVARIANT_ASSERT(NodeTraits::get_left(a));
rotate_right_left(x_parent, header);
x = NodeTraits::get_parent(x_parent);
x_parent = NodeTraits::get_parent(x);
}
else {
rotate_left(x_parent, header);
x = NodeTraits::get_parent(x_parent);
x_parent = NodeTraits::get_parent(x);
}
// if changed from NodeTraits::positive() to negative, no need to check above
if (NodeTraits::get_balance(x) == NodeTraits::negative()){
break;
}
}
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
}
static void rebalance_after_insertion(node_ptr header, node_ptr x)
{
NodeTraits::set_balance(x, NodeTraits::zero());
// Rebalance.
for(node_ptr root = NodeTraits::get_parent(header); x != root; root = NodeTraits::get_parent(header)){
const balance x_parent_balance = NodeTraits::get_balance(NodeTraits::get_parent(x));
if(x_parent_balance == NodeTraits::zero()){
// if x is left, parent will have parent->bal_factor = negative
// else, parent->bal_factor = NodeTraits::positive()
NodeTraits::set_balance( NodeTraits::get_parent(x)
, x == NodeTraits::get_left(NodeTraits::get_parent(x))
? NodeTraits::negative() : NodeTraits::positive() );
x = NodeTraits::get_parent(x);
}
else if(x_parent_balance == NodeTraits::positive()){
// if x is a left child, parent->bal_factor = zero
if (x == NodeTraits::get_left(NodeTraits::get_parent(x)))
NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero());
else{ // x is a right child, needs rebalancing
if (NodeTraits::get_balance(x) == NodeTraits::negative())
rotate_right_left(NodeTraits::get_parent(x), header);
else
rotate_left(NodeTraits::get_parent(x), header);
}
break;
}
else if(x_parent_balance == NodeTraits::negative()){
// if x is a left child, needs rebalancing
if (x == NodeTraits::get_left(NodeTraits::get_parent(x))) {
if (NodeTraits::get_balance(x) == NodeTraits::positive())
rotate_left_right(NodeTraits::get_parent(x), header);
else
rotate_right(NodeTraits::get_parent(x), header);
}
else
NodeTraits::set_balance(NodeTraits::get_parent(x), NodeTraits::zero());
break;
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
}
static void left_right_balancing(node_ptr a, node_ptr b, node_ptr c)
{
// balancing...
const balance c_balance = NodeTraits::get_balance(c);
const balance zero_balance = NodeTraits::zero();
NodeTraits::set_balance(c, zero_balance);
if(c_balance == NodeTraits::negative()){
NodeTraits::set_balance(a, NodeTraits::positive());
NodeTraits::set_balance(b, zero_balance);
}
else if(c_balance == zero_balance){
NodeTraits::set_balance(a, zero_balance);
NodeTraits::set_balance(b, zero_balance);
}
else if(c_balance == NodeTraits::positive()){
NodeTraits::set_balance(a, zero_balance);
NodeTraits::set_balance(b, NodeTraits::negative());
}
else{
BOOST_INTRUSIVE_INVARIANT_ASSERT(false); // never reached
}
}
static void rotate_left_right(const node_ptr a, node_ptr hdr)
{
// | | //
// a(-2) c //
// / \ / \ //
// / \ ==> / \ //
// (pos)b [g] b a //
// / \ / \ / \ //
// [d] c [d] e f [g] //
// / \ //
// e f //
node_ptr b = NodeTraits::get_left(a), c = NodeTraits::get_right(b);
tree_algorithms::rotate_left(b, hdr);
tree_algorithms::rotate_right(a, hdr);
left_right_balancing(a, b, c);
}
static void rotate_right_left(const node_ptr a, node_ptr hdr)
{
// | | //
// a(pos) c //
// / \ / \ //
// / \ / \ //
// [d] b(neg) ==> a b //
// / \ / \ / \ //
// c [g] [d] e f [g] //
// / \ //
// e f //
node_ptr b = NodeTraits::get_right(a), c = NodeTraits::get_left(b);
tree_algorithms::rotate_right(b, hdr);
tree_algorithms::rotate_left(a, hdr);
left_right_balancing(b, a, c);
}
static void rotate_left(const node_ptr x, node_ptr hdr)
{
const node_ptr y = NodeTraits::get_right(x);
tree_algorithms::rotate_left(x, hdr);
// reset the balancing factor
if (NodeTraits::get_balance(y) == NodeTraits::positive()) {
NodeTraits::set_balance(x, NodeTraits::zero());
NodeTraits::set_balance(y, NodeTraits::zero());
}
else { // this doesn't happen during insertions
NodeTraits::set_balance(x, NodeTraits::positive());
NodeTraits::set_balance(y, NodeTraits::negative());
}
}
static void rotate_right(const node_ptr x, node_ptr hdr)
{
const node_ptr y = NodeTraits::get_left(x);
tree_algorithms::rotate_right(x, hdr);
// reset the balancing factor
if (NodeTraits::get_balance(y) == NodeTraits::negative()) {
NodeTraits::set_balance(x, NodeTraits::zero());
NodeTraits::set_balance(y, NodeTraits::zero());
}
else { // this doesn't happen during insertions
NodeTraits::set_balance(x, NodeTraits::negative());
NodeTraits::set_balance(y, NodeTraits::positive());
}
}
/// @endcond
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVLTREE_ALGORITHMS_HPP

View File

@@ -0,0 +1,296 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_BS_SET_HOOK_HPP
#define BOOST_INTRUSIVE_BS_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/detail/tree_algorithms.hpp>
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/detail/generic_hook.hpp>
namespace boost {
namespace intrusive {
/// @cond
template<class VoidPointer>
struct get_bs_set_node_algo
{
typedef detail::tree_algorithms<tree_node_traits<VoidPointer> > type;
};
/// @endcond
//! Helper metafunction to define a \c bs_set_base_hook that yields to the same
//! type when the same options (either explicitly or implicitly) are used.
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template<class ...Options>
#else
template<class O1 = none, class O2 = none, class O3 = none>
#endif
struct make_bs_set_base_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
< hook_defaults, O1, O2, O3>
#else
< hook_defaults, Options...>
#endif
::type packed_options;
//Scapegoat trees can't be auto unlink trees
BOOST_STATIC_ASSERT(((int)packed_options::link_mode != (int)auto_unlink));
typedef detail::generic_hook
< get_bs_set_node_algo<typename packed_options::void_pointer>
, typename packed_options::tag
, packed_options::link_mode
, detail::BsSetBaseHook
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Derive a class from bs_set_base_hook in order to store objects in
//! in a bs_set/bs_multiset. bs_set_base_hook holds the data necessary to maintain
//! the bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
//!
//! The hook admits the following options: \c tag<>, \c void_pointer<>,
//! \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 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 bs_set_base_hook
: public make_bs_set_base_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
bs_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.
bs_set_base_hook(const bs_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.
bs_set_base_hook& operator=(const bs_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.
~bs_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(bs_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 bs_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_bs_set_member_hook
{
/// @cond
typedef typename pack_options
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
< hook_defaults, O1, O2, O3>
#else
< hook_defaults, Options...>
#endif
::type packed_options;
//Scapegoat trees can't be auto unlink trees
BOOST_STATIC_ASSERT(((int)packed_options::link_mode != (int)auto_unlink));
typedef detail::generic_hook
< get_bs_set_node_algo<typename packed_options::void_pointer>
, member_tag
, packed_options::link_mode
, detail::NoBaseHook
> implementation_defined;
/// @endcond
typedef implementation_defined type;
};
//! Put a public data member bs_set_member_hook in order to store objects of this class in
//! a bs_set/bs_multiset. bs_set_member_hook holds the data necessary for maintaining the
//! bs_set/bs_multiset and provides an appropriate value_traits class for bs_set/bs_multiset.
//!
//! The hook admits the following options: \c void_pointer<>, \c link_mode<>.
//!
//! \c void_pointer<> is the pointer type that will be used internally in the hook
//! and the the container configured to use this hook.
//!
//! \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 bs_set_member_hook
: public make_bs_set_member_hook
#if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
<O1, O2, O3>
#else
<Options...>
#endif
::type
{
#if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
bs_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.
bs_set_member_hook(const bs_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.
bs_set_member_hook& operator=(const bs_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.
~bs_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(bs_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_BS_SET_HOOK_HPP

View File

@@ -0,0 +1,407 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_CIRCULAR_LIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
//! circular_list_algorithms provides basic algorithms to manipulate nodes
//! forming a circular doubly linked list. An empty circular list is formed by a node
//! whose pointers point to itself.
//!
//! circular_list_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_previous(const_node_ptr n);</tt>
//!
//! <tt>static void set_previous(node_ptr n, node_ptr prev);</tt>
//!
//! <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 circular_list_algorithms
{
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;
//! <b>Effects</b>: Constructs an non-used list element, so that
//! inited(this_node) == true
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void init(node_ptr this_node)
{
NodeTraits::set_next(this_node, node_ptr(0));
NodeTraits::set_previous(this_node, node_ptr(0));
}
//! <b>Effects</b>: Returns true is "this_node" is in a non-used state
//! as if it was initialized by the "init" function.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static bool inited(const_node_ptr this_node)
{ return !NodeTraits::get_next(this_node); }
//! <b>Effects</b>: Constructs an empty list, making this_node the only
//! node of the circular list:
//! <tt>NodeTraits::get_next(this_node) == NodeTraits::get_previous(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, this_node);
NodeTraits::set_previous(this_node, 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:
//! <tt>return NodeTraits::get_next(this_node) == this_node</tt>
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static bool unique(const_node_ptr this_node)
{
node_ptr next = NodeTraits::get_next(this_node);
return !next || next == this_node;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in a circular list. If the circular list
//! is empty, returns 1.
//!
//! <b>Complexity</b>: Linear
//!
//! <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 != this_node);
return result;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Unlinks the node from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static node_ptr unlink(node_ptr this_node)
{
if(NodeTraits::get_next(this_node)){
node_ptr next(NodeTraits::get_next(this_node));
node_ptr prev(NodeTraits::get_previous(this_node));
NodeTraits::set_next(prev, next);
NodeTraits::set_previous(next, prev);
return next;
}
else{
return this_node;
}
}
//! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range.
//!
//! <b>Effects</b>: Unlinks the node [b, e) from the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void unlink(node_ptr b, node_ptr e)
{
if (b != e) {
node_ptr prevb(NodeTraits::get_previous(b));
NodeTraits::set_previous(e, prevb);
NodeTraits::set_next(prevb, e);
}
}
//! <b>Requires</b>: nxt_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node before nxt_node in the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void link_before(node_ptr nxt_node, node_ptr this_node)
{
node_ptr prev(NodeTraits::get_previous(nxt_node));
NodeTraits::set_previous(this_node, prev);
NodeTraits::set_next(prev, this_node);
NodeTraits::set_previous(nxt_node, this_node);
NodeTraits::set_next(this_node, nxt_node);
}
//! <b>Requires</b>: prev_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node after prev_node in the circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void link_after(node_ptr prev_node, node_ptr this_node)
{
node_ptr next(NodeTraits::get_next(prev_node));
NodeTraits::set_previous(this_node, prev_node);
NodeTraits::set_next(this_node, next);
NodeTraits::set_previous(next, this_node);
NodeTraits::set_next(prev_node, this_node);
}
//! <b>Requires</b>: this_node and other_node must be nodes inserted
//! in circular lists or be empty circular lists.
//!
//! <b>Effects</b>: Swaps the position of the nodes: this_node is inserted in
//! other_nodes position in the second circular list and the other_node is inserted
//! in this_node's position in the first circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
/*
static void swap_nodes(node_ptr this_node, node_ptr other_node)
{
if (other_node == this_node)
return;
bool empty1 = unique(this_node);
bool empty2 = unique(other_node);
node_ptr next_this(NodeTraits::get_next(this_node));
node_ptr prev_this(NodeTraits::get_previous(this_node));
node_ptr next_other(NodeTraits::get_next(other_node));
node_ptr prev_other(NodeTraits::get_previous(other_node));
//Do the swap
NodeTraits::set_next(this_node, next_other);
NodeTraits::set_next(other_node, next_this);
NodeTraits::set_previous(this_node, prev_other);
NodeTraits::set_previous(other_node, prev_this);
if (empty2){
init(this_node);
}
else{
NodeTraits::set_next(prev_other, this_node);
NodeTraits::set_previous(next_other, this_node);
}
if (empty1){
init(other_node);
}
else{
NodeTraits::set_next(prev_this, other_node);
NodeTraits::set_previous(next_this, other_node);
}
}
*/
//Watanabe version
private:
static void swap_prev(node_ptr this_node, node_ptr other_node)
{
node_ptr temp(NodeTraits::get_previous(this_node));
NodeTraits::set_previous(this_node, NodeTraits::get_previous(other_node));
NodeTraits::set_previous(other_node, temp);
}
static void swap_next(node_ptr this_node, node_ptr other_node)
{
node_ptr temp(NodeTraits::get_next(this_node));
NodeTraits::set_next(this_node, NodeTraits::get_next(other_node));
NodeTraits::set_next(other_node, temp);
}
public:
static void swap_nodes(node_ptr this_node, node_ptr other_node)
{
if (other_node == this_node)
return;
bool this_inited = inited(this_node);
bool other_inited = inited(other_node);
if(this_inited){
init_header(this_node);
}
if(other_inited){
init_header(other_node);
}
node_ptr next_this(NodeTraits::get_next(this_node));
node_ptr prev_this(NodeTraits::get_previous(this_node));
node_ptr next_other(NodeTraits::get_next(other_node));
node_ptr prev_other(NodeTraits::get_previous(other_node));
//these first two swaps must happen before the other two
swap_prev(next_this, next_other);
swap_next(prev_this, prev_other);
swap_next(this_node, other_node);
swap_prev(this_node, other_node);
if(this_inited){
init(other_node);
}
if(other_inited){
init(this_node);
}
}
//! <b>Requires</b>: b and e must be nodes of the same circular list or an empty range.
//! and p must be a node of a different circular list or may not be an iterator in
// [b, e).
//!
//! <b>Effects</b>: Removes the nodes from [b, e) range from their circular list and inserts
//! them before p in p's circular list.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void transfer(node_ptr p, node_ptr b, node_ptr e)
{
if (b != e) {
node_ptr prev_p(NodeTraits::get_previous(p));
node_ptr prev_b(NodeTraits::get_previous(b));
node_ptr prev_e(NodeTraits::get_previous(e));
NodeTraits::set_next(prev_e, p);
NodeTraits::set_previous(p, prev_e);
NodeTraits::set_next(prev_b, e);
NodeTraits::set_previous(e, prev_b);
NodeTraits::set_next(prev_p, b);
NodeTraits::set_previous(b, prev_p);
}
}
//! <b>Requires</b>: i must a node of a circular list
//! and p must be a node of a different circular list.
//!
//! <b>Effects</b>: Removes the node i from its circular list and inserts
//! it before p in p's circular list.
//! If p == i or p == NodeTraits::get_next(i), this function is a null operation.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing.
static void transfer(node_ptr p, node_ptr i)
{
node_ptr n(NodeTraits::get_next(i));
if(n != p && i != p){
node_ptr prev_p(NodeTraits::get_previous(p));
node_ptr prev_i(NodeTraits::get_previous(i));
NodeTraits::set_next(prev_p, i);
NodeTraits::set_previous(i, prev_p);
NodeTraits::set_next(i, p);
NodeTraits::set_previous(p, i);
NodeTraits::set_previous(n, prev_i);
NodeTraits::set_next(prev_i, n);
}
}
//! <b>Effects</b>: Reverses the order of elements in the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: This function is linear time.
static void reverse(node_ptr p)
{
node_ptr f(NodeTraits::get_next(p));
node_ptr i(NodeTraits::get_next(f)), e(p);
while(i != e) {
node_ptr n = i;
i = NodeTraits::get_next(i);
transfer(f, n, i);
f = n;
}
}
//! <b>Effects</b>: Moves the node p n positions towards the end of the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of moved positions.
static void move_backwards(node_ptr p, std::size_t n)
{
//Null shift, nothing to do
if(!n) return;
node_ptr first = NodeTraits::get_next(p);
//size() == 0 or 1, nothing to do
if(first == NodeTraits::get_previous(p)) return;
unlink(p);
//Now get the new first node
while(n--){
first = NodeTraits::get_next(first);
}
link_before(first, p);
}
//! <b>Effects</b>: Moves the node p n positions towards the beginning of the list.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of moved positions.
static void move_forward(node_ptr p, std::size_t n)
{
//Null shift, nothing to do
if(!n) return;
node_ptr last = NodeTraits::get_previous(p);
//size() == 0 or 1, nothing to do
if(last == NodeTraits::get_next(p)) return;
unlink(p);
//Now get the new last node
while(n--){
last = NodeTraits::get_previous(last);
}
link_after(last, p);
}
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_CIRCULAR_LIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,405 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_CIRCULAR_SLIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_CIRCULAR_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 <boost/intrusive/detail/assert.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
//! circular_slist_algorithms provides basic algorithms to manipulate nodes
//! forming a circular singly linked list. An empty circular list is formed by a node
//! whose pointer to the next node points to itself.
//!
//! circular_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 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_next(const_node_ptr n);</tt>
//!
//! <tt>static void set_next(node_ptr n, node_ptr next);</tt>
template<class NodeTraits>
class circular_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</tt>
//!
//! <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 circular 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 circular list.
//!
//! <b>Effects</b>: Links this_node after prev_node in the circular 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 circular list or an empty range.
//! and p must be a node of a different circular list.
//!
//! <b>Effects</b>: Removes the nodes from (b, e] range from their circular list and inserts
//! them after p in p's circular 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, this_node); }
//! <b>Requires</b>: this_node and prev_init_node must be in the same circular list.
//!
//! <b>Effects</b>: Returns the previous node of this_node in the circular list starting.
//! the search from prev_init_node. The first node checked for equality
//! is NodeTraits::get_next(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 circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the previous node of this_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
static node_ptr get_previous_node(node_ptr this_node)
{ return base_t::get_previous_node(this_node, this_node); }
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
static node_ptr get_previous_previous_node(node_ptr this_node)
{ return get_previous_previous_node(this_node, this_node); }
//! <b>Requires</b>: this_node and prev_prev_init_node must be in the same circular list.
//!
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the
//! circular list starting. the search from prev_init_node. The first node checked
//! for equality is NodeTraits::get_next((NodeTraits::get_next(prev_prev_init_node)).
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
static node_ptr get_previous_previous_node(node_ptr prev_prev_init_node, node_ptr this_node)
{
node_ptr p = prev_prev_init_node;
node_ptr p_next = NodeTraits::get_next(p);
node_ptr p_next_next = NodeTraits::get_next(p_next);
while (this_node != p_next_next){
p = p_next;
p_next = p_next_next;
p_next_next = NodeTraits::get_next(p_next);
}
return p;
}
//! <b>Requires</b>: this_node must be in a circular list or be an empty circular list.
//!
//! <b>Effects</b>: Returns the number of nodes in a circular list. If the circular list
//! is empty, returns 1.
//!
//! <b>Complexity</b>: Linear
//!
//! <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 != this_node);
return result;
}
//! <b>Requires</b>: this_node must be in a circular list, be an empty circular list or be inited.
//!
//! <b>Effects</b>: Unlinks the node from the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list
//!
//! <b>Throws</b>: Nothing.
static void unlink(node_ptr this_node)
{
if(NodeTraits::get_next(this_node))
base_t::unlink_after(get_previous_node(this_node));
}
//! <b>Requires</b>: nxt_node must be a node of a circular list.
//!
//! <b>Effects</b>: Links this_node before nxt_node in the circular list.
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
static void link_before (node_ptr nxt_node, node_ptr this_node)
{ base_t::link_after(get_previous_node(nxt_node), this_node); }
//! <b>Requires</b>: this_node and other_node must be nodes inserted
//! in circular lists or be empty circular lists.
//!
//! <b>Effects</b>: Swaps the position of the nodes: this_node is inserted in
//! other_nodes position in the second circular list and the other_node is inserted
//! in this_node's position in the first circular list.
//!
//! <b>Complexity</b>: Linear to number of elements of both lists
//!
//! <b>Throws</b>: Nothing.
static void swap_nodes(node_ptr this_node, node_ptr other_node)
{
if (other_node == this_node)
return;
bool this_inited = base_t::inited(this_node);
bool other_inited = base_t::inited(other_node);
if(this_inited){
base_t::init_header(this_node);
}
if(other_inited){
base_t::init_header(other_node);
}
bool empty1 = base_t::unique(this_node);
bool empty2 = base_t::unique(other_node);
node_ptr prev_this (get_previous_node(this_node));
node_ptr prev_other(get_previous_node(other_node));
node_ptr this_next (NodeTraits::get_next(this_node));
node_ptr other_next(NodeTraits::get_next(other_node));
NodeTraits::set_next(this_node, other_next);
NodeTraits::set_next(other_node, this_next);
NodeTraits::set_next(empty1 ? other_node : prev_this, other_node);
NodeTraits::set_next(empty2 ? this_node : prev_other, this_node);
if(this_inited){
base_t::init(other_node);
}
if(other_inited){
base_t::init(this_node);
}
}
//! <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.
static void reverse(node_ptr p)
{
node_ptr i = NodeTraits::get_next(p), e(p);
for (;;) {
node_ptr nxt(NodeTraits::get_next(i));
if (nxt == e)
break;
base_t::transfer_after(e, i, nxt);
}
}
//! <b>Effects</b>: Moves the node p n positions towards the end of the list.
//!
//! <b>Returns</b>: The previous node of p after the function if there has been any movement,
//! Null 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 node_ptr move_backwards(node_ptr p, std::size_t n)
{
//Null shift, nothing to do
if(!n) return node_ptr(0);
node_ptr first = NodeTraits::get_next(p);
//count() == 1 or 2, nothing to do
if(NodeTraits::get_next(first) == p)
return node_ptr(0);
bool end_found = false;
node_ptr new_last(0);
//Now find the new last node according to the shift count.
//If we find p 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 == p){
//Shortcut the shift with the modulo of the size of the list
n %= i;
if(!n)
return node_ptr(0);
i = 0;
//Unlink p and continue the new first node search
first = NodeTraits::get_next(p);
base_t::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){
base_t::unlink_after(base_t::get_previous_node(first, p));
}
//Now link p after the new last node
base_t::link_after(new_last, p);
return new_last;
}
//! <b>Effects</b>: Moves the node p n positions towards the beginning of the list.
//!
//! <b>Returns</b>: The previous node of p after the function if there has been any movement,
//! Null if n leads equals to no movement.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Linear to the number of elements plus the number moved positions.
static node_ptr move_forward(node_ptr p, std::size_t n)
{
//Null shift, nothing to do
if(!n) return node_ptr(0);
node_ptr first = node_traits::get_next(p);
//count() == 1 or 2, nothing to do
if(node_traits::get_next(first) == p) return node_ptr(0);
//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(p != (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 node_ptr(0);
for( new_last = p
; new_before_last_pos--
; new_last = node_traits::get_next(new_last)){
//empty
}
}
//Now unlink p and link it after the new last node
base_t::unlink_after(old_last);
base_t::link_after(new_last, p);
return new_last;
}
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,67 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_DERIVATION_VALUE_TRAITS_HPP
#define BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP
#include <boost/intrusive/link_mode.hpp>
#include <boost/pointer_cast.hpp>
#include <iterator>
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
//!derive from node_traits::node
template<class T, class NodeTraits, link_mode_type LinkMode = safe_link>
struct derivation_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); }
static const_node_ptr to_node_ptr(const_reference value)
{ return node_ptr(&value); }
static pointer to_value_ptr(node_ptr n)
{
// This still fails in gcc < 4.4 so forget about it
// using ::boost::static_pointer_cast;
// return static_pointer_cast<value_type>(n));
return pointer(&static_cast<value_type&>(*n));
}
static const_pointer to_value_ptr(const_node_ptr n)
{
// This still fails in gcc < 4.4 so forget about it
// using ::boost::static_pointer_cast;
// return static_pointer_cast<const value_type>(n));
return const_pointer(&static_cast<const value_type&>(*n));
}
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_DERIVATION_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,300 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_ANY_NODE_HPP
#define BOOST_INTRUSIVE_ANY_NODE_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <iterator>
#include <boost/intrusive/detail/assert.hpp>
#include <boost/intrusive/detail/pointer_to_other.hpp>
#include <cstddef>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/pointer_cast.hpp>
namespace boost {
namespace intrusive {
template<class VoidPointer>
struct any_node
{
typedef typename boost::pointer_to_other
<VoidPointer, any_node>::type node_ptr;
node_ptr node_ptr_1;
node_ptr node_ptr_2;
node_ptr node_ptr_3;
std::size_t size_t_1;
};
template<class VoidPointer>
struct any_list_node_traits
{
typedef any_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->node_ptr_1; }
static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
static node_ptr get_previous(const_node_ptr n)
{ return n->node_ptr_2; }
static void set_previous(node_ptr n, node_ptr prev)
{ n->node_ptr_2 = prev; }
};
template<class VoidPointer>
struct any_slist_node_traits
{
typedef any_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->node_ptr_1; }
static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
};
template<class VoidPointer>
struct any_unordered_node_traits
: public any_slist_node_traits<VoidPointer>
{
typedef any_slist_node_traits<VoidPointer> reduced_slist_node_traits;
typedef typename reduced_slist_node_traits::node node;
typedef typename reduced_slist_node_traits::node_ptr node_ptr;
typedef typename reduced_slist_node_traits::const_node_ptr const_node_ptr;
static const bool store_hash = true;
static const bool optimize_multikey = true;
static node_ptr get_next(const_node_ptr n)
{
using ::boost::static_pointer_cast;
return static_pointer_cast<node>(n->node_ptr_1);
}
static void set_next(node_ptr n, node_ptr next)
{ n->node_ptr_1 = next; }
static node_ptr get_prev_in_group(const_node_ptr n)
{ return n->node_ptr_2; }
static void set_prev_in_group(node_ptr n, node_ptr prev)
{ n->node_ptr_2 = prev; }
static std::size_t get_hash(const_node_ptr n)
{ return n->size_t_1; }
static void set_hash(node_ptr n, std::size_t h)
{ n->size_t_1 = h; }
};
template<class VoidPointer>
struct any_rbtree_node_traits
{
typedef any_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 std::size_t color;
static node_ptr get_parent(const_node_ptr n)
{ return n->node_ptr_1; }
static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
static color get_color(const_node_ptr n)
{ return n->size_t_1; }
static void set_color(node_ptr n, color c)
{ n->size_t_1 = c; }
static color black()
{ return 0u; }
static color red()
{ return 1u; }
};
template<class VoidPointer>
struct any_avltree_node_traits
{
typedef any_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 std::size_t balance;
static node_ptr get_parent(const_node_ptr n)
{ return n->node_ptr_1; }
static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
static balance get_balance(const_node_ptr n)
{ return n->size_t_1; }
static void set_balance(node_ptr n, balance b)
{ n->size_t_1 = b; }
static balance negative()
{ return 0u; }
static balance zero()
{ return 1u; }
static balance positive()
{ return 2u; }
};
template<class VoidPointer>
struct any_tree_node_traits
{
typedef any_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->node_ptr_1; }
static void set_parent(node_ptr n, node_ptr p)
{ n->node_ptr_1 = p; }
static node_ptr get_left(const_node_ptr n)
{ return n->node_ptr_2; }
static void set_left(node_ptr n, node_ptr l)
{ n->node_ptr_2 = l; }
static node_ptr get_right(const_node_ptr n)
{ return n->node_ptr_3; }
static void set_right(node_ptr n, node_ptr r)
{ n->node_ptr_3 = r; }
};
template<class VoidPointer>
class any_node_traits
{
public:
typedef any_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;
};
template<class VoidPointer>
class any_algorithms
{
template <class T>
static void function_not_available_for_any_hooks(typename detail::enable_if<detail::is_same<T, bool> >::type)
{}
public:
typedef any_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 any_node_traits<VoidPointer> node_traits;
//! <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)
{ node->node_ptr_1 = 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 !node->node_ptr_1; };
static bool unique(const_node_ptr node)
{ return 0 == node->node_ptr_1; }
static void unlink(node_ptr)
{
//Auto-unlink hooks and unlink() are not available for any hooks
any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
}
static void swap_nodes(node_ptr l, node_ptr r)
{
//Any nodes have no swap_nodes capability because they don't know
//what algorithm they must use to unlink the node from the container
any_algorithms<VoidPointer>::template function_not_available_for_any_hooks<node_ptr>();
}
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_ANY_NODE_HPP

View File

@@ -0,0 +1,41 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_ASSERT_HPP
#define BOOST_INTRUSIVE_DETAIL_ASSERT_HPP
#if defined(_MSC_VER)&&(_MSC_VER>=1200)
#pragma once
#endif
#if !defined(BOOST_INTRUSIVE_INVARIANT_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_INVARIANT_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_INVARIANT_ASSERT_INCLUDE
#endif
#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE
#endif
#if !defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT)
#include <boost/assert.hpp>
#define BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT BOOST_ASSERT
#elif defined(BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE)
#include BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE
#endif
#endif //BOOST_INTRUSIVE_DETAIL_ASSERT_HPP

View File

@@ -0,0 +1,179 @@
/////////////////////////////////////////////////////////////////////////////
//
// (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_AVLTREE_NODE_HPP
#define BOOST_INTRUSIVE_AVLTREE_NODE_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <iterator>
#include <boost/intrusive/detail/pointer_to_other.hpp>
#include <boost/intrusive/avltree_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_avltree_node
{
typedef typename pointer_to_other
<VoidPointer
,compact_avltree_node<VoidPointer> >::type node_ptr;
enum balance { negative_t, zero_t, positive_t };
node_ptr parent_, left_, right_;
};
//This is the normal representation: 3 pointers + enum
template<class VoidPointer>
struct avltree_node
{
typedef typename pointer_to_other
<VoidPointer
,avltree_node<VoidPointer> >::type node_ptr;
enum balance { negative_t, zero_t, positive_t };
node_ptr parent_, left_, right_;
balance balance_;
};
//This is the default node traits implementation
//using a node with 3 generic pointers plus an enum
template<class VoidPointer>
struct default_avltree_node_traits_impl
{
typedef avltree_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::balance balance;
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 balance get_balance(const_node_ptr n)
{ return n->balance_; }
static void set_balance(node_ptr n, balance b)
{ n->balance_ = b; }
static balance negative()
{ return node::negative_t; }
static balance zero()
{ return node::zero_t; }
static balance positive()
{ return node::positive_t; }
};
//This is the compact node traits implementation
//using a node with 3 generic pointers
template<class VoidPointer>
struct compact_avltree_node_traits_impl
{
typedef compact_avltree_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::balance balance;
typedef pointer_plus_bits<node_ptr, 2> ptr_bit;
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 balance get_balance(const_node_ptr n)
{ return (balance)ptr_bit::get_bits(n->parent_); }
static void set_balance(node_ptr n, balance b)
{ ptr_bit::set_bits(n->parent_, (std::size_t)b); }
static balance negative()
{ return node::negative_t; }
static balance zero()
{ return node::zero_t; }
static balance positive()
{ return node::positive_t; }
};
//Dispatches the implementation based on the boolean
template<class VoidPointer, bool Compact>
struct avltree_node_traits_dispatch
: public default_avltree_node_traits_impl<VoidPointer>
{};
template<class VoidPointer>
struct avltree_node_traits_dispatch<VoidPointer, true>
: public compact_avltree_node_traits_impl<VoidPointer>
{};
//Inherit from the detail::link_dispatch depending on the embedding capabilities
template<class VoidPointer, bool OptimizeSize = false>
struct avltree_node_traits
: public avltree_node_traits_dispatch
< VoidPointer
, OptimizeSize &&
max_pointer_plus_bits
< VoidPointer
, detail::alignment_of<compact_avltree_node<VoidPointer> >::value
>::value >= 2u
>
{};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_AVLTREE_NODE_HPP

View File

@@ -0,0 +1,36 @@
//////} // ///////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2008-2009. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/intrusive for documentation.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP
#define BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP
#include <boost/intrusive/detail/config_begin.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class Derived>
class clear_on_destructor_base
{
protected:
~clear_on_destructor_base()
{
static_cast<Derived*>(this)->clear();
}
};
} // namespace detail {
} // namespace intrusive {
} // namespace boost {
#include <boost/intrusive/detail/config_end.hpp>
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_CLEAR_ON_DESTRUCTOR_HPP

View File

@@ -0,0 +1,103 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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_COMMON_SLIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/assert.hpp>
#include <cstddef>
namespace boost {
namespace intrusive {
namespace detail {
template<class NodeTraits>
class common_slist_algorithms
{
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;
static node_ptr get_previous_node(node_ptr prev_init_node, node_ptr this_node)
{
node_ptr p = prev_init_node;
for( node_ptr p_next
; this_node != (p_next = NodeTraits::get_next(p))
; p = p_next){
//Logic error: possible use of linear lists with
//operations only permitted with lists
BOOST_INTRUSIVE_INVARIANT_ASSERT(p);
}
return p;
}
static void init_header(node_ptr this_node)
{ NodeTraits::set_next(this_node, this_node); }
static void init(node_ptr this_node)
{ NodeTraits::set_next(this_node, node_ptr(0)); }
static bool unique(const_node_ptr this_node)
{
node_ptr next = NodeTraits::get_next(this_node);
return !next || next == this_node;
}
static bool inited(const_node_ptr this_node)
{ return !NodeTraits::get_next(this_node); }
static void unlink_after(node_ptr prev_node)
{
node_ptr this_node(NodeTraits::get_next(prev_node));
NodeTraits::set_next(prev_node, NodeTraits::get_next(this_node));
}
static void unlink_after(node_ptr prev_node, node_ptr last_node)
{ NodeTraits::set_next(prev_node, last_node); }
static void link_after(node_ptr prev_node, node_ptr this_node)
{
NodeTraits::set_next(this_node, NodeTraits::get_next(prev_node));
NodeTraits::set_next(prev_node, this_node);
}
static void incorporate_after(node_ptr bp, node_ptr b, node_ptr be)
{
node_ptr p(NodeTraits::get_next(bp));
NodeTraits::set_next(bp, b);
NodeTraits::set_next(be, p);
}
static void transfer_after(node_ptr bp, node_ptr bb, node_ptr be)
{
if (bp != bb && bp != be && bb != be) {
node_ptr next_b = NodeTraits::get_next(bb);
node_ptr next_e = NodeTraits::get_next(be);
node_ptr next_p = NodeTraits::get_next(bp);
NodeTraits::set_next(bb, next_e);
NodeTraits::set_next(be, next_p);
NodeTraits::set_next(bp, next_b);
}
}
};
} //namespace detail
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_COMMON_SLIST_ALGORITHMS_HPP

View File

@@ -0,0 +1,52 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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_CONFIG_INCLUDED
#define BOOST_INTRUSIVE_CONFIG_INCLUDED
#include <boost/config.hpp>
#endif
#ifdef BOOST_MSVC
#pragma warning (push)
//
//'function' : resolved overload was found by argument-dependent lookup
//A function found by argument-dependent lookup (Koenig lookup) was eventually
//chosen by overload resolution.
//
//In Visual C++ .NET and earlier compilers, a different function would have
//been called. To pick the original function, use an explicitly qualified name.
//
//warning C4275: non dll-interface class 'x' used as base for
//dll-interface class 'Y'
#pragma warning (disable : 4275)
//warning C4251: 'x' : class 'y' needs to have dll-interface to
//be used by clients of class 'z'
#pragma warning (disable : 4251)
#pragma warning (disable : 4675)
#pragma warning (disable : 4996)
#pragma warning (disable : 4503)
#pragma warning (disable : 4284) // odd return type for operator->
#pragma warning (disable : 4244) // possible loss of data
#pragma warning (disable : 4521) ////Disable "multiple copy constructors specified"
#pragma warning (disable : 4522)
#pragma warning (disable : 4146)
#pragma warning (disable : 4267) //conversion from 'X' to 'Y', possible loss of data
#pragma warning (disable : 4127) //conditional expression is constant
#pragma warning (disable : 4706) //assignment within conditional expression
#pragma warning (disable : 4541) //'typeid' used on polymorphic type 'boost::exception' with /GR-
#pragma warning (disable : 4512) //'typeid' used on polymorphic type 'boost::exception' with /GR-
#endif
//#define BOOST_INTRUSIVE_USE_ITERATOR_FACADE
//#define BOOST_INTRUSIVE_USE_ITERATOR_ENABLE_IF_CONVERTIBLE

View File

@@ -0,0 +1,15 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////
#if defined BOOST_MSVC
#pragma warning (pop)
#endif

View File

@@ -0,0 +1,95 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Joaquin M Lopez Munoz 2006-2009
//
// 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_EBO_HOLDER_HPP
#define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/mpl.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<typename T, bool IsEmpty = true>
class ebo_functor_holder_impl
{
public:
ebo_functor_holder_impl()
{}
ebo_functor_holder_impl(const T& t)
: t_(t)
{}
template<class Arg1, class Arg2>
ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
: t_(arg1, arg2)
{}
T& get(){return t_;}
const T& get()const{return t_;}
private:
T t_;
};
template<typename T>
class ebo_functor_holder_impl<T, false>
: public T
{
public:
ebo_functor_holder_impl()
{}
ebo_functor_holder_impl(const T& t)
: T(t)
{}
template<class Arg1, class Arg2>
ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
: T(arg1, arg2)
{}
T& get(){return *this;}
const T& get()const{return *this;}
};
template<typename T>
class ebo_functor_holder
: public ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value>
{
private:
typedef ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value> super;
public:
ebo_functor_holder(){}
ebo_functor_holder(const T& t)
: super(t)
{}
template<class Arg1, class Arg2>
ebo_functor_holder(const Arg1& arg1, const Arg2& arg2)
: super(arg1, arg2)
{}
ebo_functor_holder& operator=(const ebo_functor_holder& x)
{
this->get()=x.get();
return *this;
}
};
} //namespace detail {
} //namespace intrusive {
} //namespace boost {
#include <boost/intrusive/detail/config_end.hpp>
#endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP

View File

@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2009.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////
// This code was modified from the code posted by Alexandre Courpron in his
// article "Interface Detection" in The Code Project:
///////////////////////////////////////////////////////////////////////////////
// Copyright 2007 Alexandre Courpron
//
// Permission to use, copy, modify, redistribute and sell this software,
// provided that this copyright notice appears on all copies of the software.
///////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
#define BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP
#include <boost/intrusive/detail/config_begin.hpp>
namespace boost {
namespace intrusive {
namespace function_detector {
typedef char NotFoundType;
struct StaticFunctionType { NotFoundType x [2]; };
struct NonStaticFunctionType { NotFoundType x [3]; };
enum
{ NotFound = 0,
StaticFunction = sizeof( StaticFunctionType ) - sizeof( NotFoundType ),
NonStaticFunction = sizeof( NonStaticFunctionType ) - sizeof( NotFoundType )
};
} //namespace boost {
} //namespace intrusive {
} //namespace function_detector {
#define BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(Identifier, InstantiationKey) \
namespace boost { \
namespace intrusive { \
namespace function_detector { \
template < class T, \
class NonStaticType, \
class NonStaticConstType, \
class StaticType > \
class DetectMember_##InstantiationKey_##Identifier { \
template < NonStaticType > \
struct TestNonStaticNonConst ; \
\
template < NonStaticConstType > \
struct TestNonStaticConst ; \
\
template < StaticType > \
struct TestStatic ; \
\
template <class U > \
static NonStaticFunctionType Test( TestNonStaticNonConst<&U::Identifier>*, int ); \
\
template <class U > \
static NonStaticFunctionType Test( TestNonStaticConst<&U::Identifier>*, int ); \
\
template <class U> \
static StaticFunctionType Test( TestStatic<&U::Identifier>*, int ); \
\
template <class U> \
static NotFoundType Test( ... ); \
public : \
static const int check = NotFound + (sizeof(Test<T>(0, 0)) - sizeof(NotFoundType));\
};\
}}} //namespace boost::intrusive::function_detector {
#define BOOST_INTRUSIVE_DETECT_FUNCTION(Class, InstantiationKey, ReturnType, Identifier, Params) \
::boost::intrusive::function_detector::DetectMember_##InstantiationKey_##Identifier< Class,\
ReturnType (Class::*)Params,\
ReturnType (Class::*)Params const,\
ReturnType (*)Params \
>::check
#include <boost/intrusive/detail/config_end.hpp>
#endif //@ifndef BOOST_INTRUSIVE_DETAIL_FUNCTION_DETECTOR_HPP

View File

@@ -0,0 +1,203 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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_GENERIC_HOOK_HPP
#define BOOST_INTRUSIVE_GENERIC_HOOK_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/pointer_to_other.hpp>
#include <boost/intrusive/link_mode.hpp>
#include <boost/intrusive/detail/utilities.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/static_assert.hpp>
namespace boost {
namespace intrusive {
namespace detail {
/// @cond
enum
{ NoBaseHook
, ListBaseHook
, SlistBaseHook
, SetBaseHook
, UsetBaseHook
, SplaySetBaseHook
, AvlSetBaseHook
, BsSetBaseHook
, AnyBaseHook
};
struct no_default_definer{};
template <class Hook, unsigned int>
struct default_definer;
template <class Hook>
struct default_definer<Hook, ListBaseHook>
{ typedef Hook default_list_hook; };
template <class Hook>
struct default_definer<Hook, SlistBaseHook>
{ typedef Hook default_slist_hook; };
template <class Hook>
struct default_definer<Hook, SetBaseHook>
{ typedef Hook default_set_hook; };
template <class Hook>
struct default_definer<Hook, UsetBaseHook>
{ typedef Hook default_uset_hook; };
template <class Hook>
struct default_definer<Hook, SplaySetBaseHook>
{ typedef Hook default_splay_set_hook; };
template <class Hook>
struct default_definer<Hook, AvlSetBaseHook>
{ typedef Hook default_avl_set_hook; };
template <class Hook>
struct default_definer<Hook, BsSetBaseHook>
{ typedef Hook default_bs_set_hook; };
template <class Hook>
struct default_definer<Hook, AnyBaseHook>
{ typedef Hook default_any_hook; };
template <class Hook, unsigned int BaseHookType>
struct make_default_definer
{
typedef typename detail::if_c
< BaseHookType != 0
, default_definer<Hook, BaseHookType>
, no_default_definer>::type type;
};
template
< class GetNodeAlgorithms
, class Tag
, link_mode_type LinkMode
, int HookType
>
struct make_node_holder
{
typedef typename detail::if_c
<!detail::is_same<Tag, member_tag>::value
, detail::node_holder
< typename GetNodeAlgorithms::type::node
, Tag
, LinkMode
, HookType>
, typename GetNodeAlgorithms::type::node
>::type type;
};
/// @endcond
template
< class GetNodeAlgorithms
, class Tag
, link_mode_type LinkMode
, int HookType
>
class generic_hook
/// @cond
//If the hook is a base hook, derive generic hook from detail::node_holder
//so that a unique base class is created to convert from the node
//to the type. This mechanism will be used by base_hook_traits.
//
//If the hook is a member hook, generic hook will directly derive
//from the hook.
: public make_default_definer
< generic_hook<GetNodeAlgorithms, Tag, LinkMode, HookType>
, detail::is_same<Tag, default_tag>::value*HookType
>::type
, public make_node_holder<GetNodeAlgorithms, Tag, LinkMode, HookType>::type
/// @endcond
{
/// @cond
typedef typename GetNodeAlgorithms::type node_algorithms;
typedef typename node_algorithms::node node;
typedef typename node_algorithms::node_ptr node_ptr;
typedef typename node_algorithms::const_node_ptr const_node_ptr;
public:
struct boost_intrusive_tags
{
static const int hook_type = HookType;
static const link_mode_type link_mode = LinkMode;
typedef Tag tag;
typedef typename GetNodeAlgorithms::type::node_traits node_traits;
static const bool is_base_hook = !detail::is_same<Tag, member_tag>::value;
static const bool safemode_or_autounlink =
(int)link_mode == (int)auto_unlink || (int)link_mode == (int)safe_link;
};
public:
/// @endcond
generic_hook()
{
if(boost_intrusive_tags::safemode_or_autounlink){
node_algorithms::init(static_cast<node*>(this));
}
}
generic_hook(const generic_hook& )
{
if(boost_intrusive_tags::safemode_or_autounlink){
node_algorithms::init(static_cast<node*>(this));
}
}
generic_hook& operator=(const generic_hook& )
{ return *this; }
~generic_hook()
{
destructor_impl
(*this, detail::link_dispatch<boost_intrusive_tags::link_mode>());
}
void swap_nodes(generic_hook &other)
{
node_algorithms::swap_nodes
( static_cast<node*>(this), static_cast<node*>(&other));
}
bool is_linked() const
{
//is_linked() can be only used in safe-mode or auto-unlink
BOOST_STATIC_ASSERT(( boost_intrusive_tags::safemode_or_autounlink ));
return !node_algorithms::unique
(static_cast<const node*>(this));
}
void unlink()
{
BOOST_STATIC_ASSERT(( (int)boost_intrusive_tags::link_mode == (int)auto_unlink ));
node_algorithms::unlink(static_cast<node*>(this));
node_algorithms::init(static_cast<node*>(this));
}
};
} //namespace detail
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_GENERIC_HOOK_HPP

View File

@@ -0,0 +1,238 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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_NODE_HPP
#define BOOST_INTRUSIVE_HASHTABLE_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>
#include <boost/intrusive/circular_list_algorithms.hpp>
#include <boost/intrusive/detail/mpl.hpp>
#include <boost/intrusive/detail/utilities.hpp>
#include <boost/intrusive/detail/slist_node.hpp> //remove-me
#include <cstddef>
#include <boost/pointer_cast.hpp>
#include <boost/move/move.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<int Dummy = 0>
struct prime_list_holder
{
static const std::size_t prime_list[];
static const std::size_t prime_list_size;
};
template<int Dummy>
const std::size_t prime_list_holder<Dummy>::prime_list[] = {
3ul, 7ul, 11ul, 17ul, 29ul,
53ul, 97ul, 193ul, 389ul, 769ul,
1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
1610612741ul, 3221225473ul, 4294967291ul };
template<int Dummy>
const std::size_t prime_list_holder<Dummy>::prime_list_size
= sizeof(prime_list)/sizeof(std::size_t);
template <class Slist>
struct bucket_impl : public Slist
{
typedef Slist slist_type;
bucket_impl()
{}
bucket_impl(const bucket_impl &)
{}
~bucket_impl()
{
//This bucket is still being used!
BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
}
bucket_impl &operator=(const bucket_impl&)
{
//This bucket is still in use!
BOOST_INTRUSIVE_INVARIANT_ASSERT(Slist::empty());
//Slist::clear();
return *this;
}
};
template<class Slist>
struct bucket_traits_impl
{
private:
BOOST_COPYABLE_AND_MOVABLE(bucket_traits_impl)
public:
/// @cond
typedef typename boost::pointer_to_other
< typename Slist::pointer, bucket_impl<Slist> >::type bucket_ptr;
typedef typename Slist::size_type size_type;
/// @endcond
bucket_traits_impl(bucket_ptr buckets, size_type len)
: buckets_(buckets), buckets_len_(len)
{}
bucket_traits_impl(BOOST_RV_REF(bucket_traits_impl) x)
: buckets_(x.buckets_), buckets_len_(x.buckets_len_)
{ x.buckets_ = bucket_ptr(0); x.buckets_len_ = 0; }
bucket_traits_impl& operator=(BOOST_RV_REF(bucket_traits_impl) x)
{
buckets_ = x.buckets_; buckets_len_ = x.buckets_len_;
x.buckets_ = bucket_ptr(0); x.buckets_len_ = 0; return *this;
}
bucket_traits_impl& operator=(BOOST_COPY_ASSIGN_REF(bucket_traits_impl) x)
{
buckets_ = x.buckets_; buckets_len_ = x.buckets_len_; return *this;
}
bucket_ptr bucket_begin() const
{ return buckets_; }
size_type bucket_count() const
{ return buckets_len_; }
private:
bucket_ptr buckets_;
size_type buckets_len_;
};
template<class Container, bool IsConst>
class hashtable_iterator
: public std::iterator
< std::forward_iterator_tag
, typename Container::value_type
, typename std::iterator_traits<typename Container::value_type*>::difference_type
, typename detail::add_const_if_c
<typename Container::value_type, IsConst>::type *
, typename detail::add_const_if_c
<typename Container::value_type, IsConst>::type &
>
{
typedef typename Container::real_value_traits real_value_traits;
typedef typename Container::siterator siterator;
typedef typename Container::const_siterator const_siterator;
typedef typename Container::bucket_type bucket_type;
typedef typename boost::pointer_to_other
< typename Container::pointer, const Container>::type const_cont_ptr;
typedef typename Container::size_type size_type;
static typename Container::node_ptr downcast_bucket(typename bucket_type::node_ptr p)
{
// This still fails in gcc < 4.4 so forget about it
// using ::boost::static_pointer_cast;
// return static_pointer_cast<typename Container::node>(p);
return typename Container::node_ptr(&static_cast<typename Container::node&>(*p));
}
public:
typedef typename Container::value_type value_type;
typedef typename detail::add_const_if_c
<typename Container::value_type, IsConst>::type *pointer;
typedef typename detail::add_const_if_c
<typename Container::value_type, IsConst>::type &reference;
hashtable_iterator ()
{}
explicit hashtable_iterator(siterator ptr, const Container *cont)
: slist_it_ (ptr), cont_ (cont)
{}
hashtable_iterator(const hashtable_iterator<Container, false> &other)
: slist_it_(other.slist_it()), cont_(other.get_container())
{}
const siterator &slist_it() const
{ return slist_it_; }
hashtable_iterator<Container, false> unconst() const
{ return hashtable_iterator<Container, false>(this->slist_it(), this->get_container()); }
public:
hashtable_iterator& operator++()
{ this->increment(); return *this; }
hashtable_iterator operator++(int)
{
hashtable_iterator result (*this);
this->increment();
return result;
}
friend bool operator== (const hashtable_iterator& i, const hashtable_iterator& i2)
{ return i.slist_it_ == i2.slist_it_; }
friend bool operator!= (const hashtable_iterator& i, const hashtable_iterator& i2)
{ return !(i == i2); }
reference operator*() const
{ return *this->operator ->(); }
pointer operator->() const
{ return detail::boost_intrusive_get_pointer(this->get_real_value_traits()->to_value_ptr(downcast_bucket(slist_it_.pointed_node()))); }
const Container *get_container() const
{ return detail::boost_intrusive_get_pointer(cont_); }
const real_value_traits *get_real_value_traits() const
{ return &this->get_container()->get_real_value_traits(); }
private:
void increment()
{
const Container *cont = detail::boost_intrusive_get_pointer(cont_);
bucket_type* buckets = detail::boost_intrusive_get_pointer(cont->bucket_pointer());
size_type buckets_len = cont->bucket_count();
++slist_it_;
if(buckets[0].cend().pointed_node() <= slist_it_.pointed_node() &&
slist_it_.pointed_node()<= buckets[buckets_len].cend().pointed_node() ){
//Now get the bucket_impl from the iterator
const bucket_type &b = static_cast<const bucket_type&>
(bucket_type::slist_type::container_from_end_iterator(slist_it_));
//Now just calculate the index b has in the bucket array
size_type n_bucket = static_cast<size_type>(&b - &buckets[0]);
do{
if (++n_bucket == buckets_len){
slist_it_ = (&buckets[0] + buckets_len)->end();
break;
}
slist_it_ = buckets[n_bucket].begin();
}
while (slist_it_ == buckets[n_bucket].end());
}
}
siterator slist_it_;
const_cont_ptr cont_;
};
} //namespace detail {
} //namespace intrusive {
} //namespace boost {
#endif

View File

@@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2009-2009.
//
// 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_IS_STATEFUL_VALUE_TRAITS_HPP
#define BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#if defined(_MSC_VER) && (_MSC_VER <= 1310)
#include <boost/intrusive/detail/mpl.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template<class ValueTraits>
struct is_stateful_value_traits
{
static const bool value = !detail::is_empty_class<ValueTraits>::value;
};
}}}
#else
#include <boost/intrusive/detail/function_detector.hpp>
BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_node_ptr, boost_intrusive)
BOOST_INTRUSIVE_CREATE_FUNCTION_DETECTOR(to_value_ptr, boost_intrusive)
namespace boost {
namespace intrusive {
namespace detail {
template<class ValueTraits>
struct is_stateful_value_traits
{
typedef typename ValueTraits::node_ptr node_ptr;
typedef typename ValueTraits::pointer pointer;
typedef typename ValueTraits::value_type value_type;
typedef typename ValueTraits::const_node_ptr const_node_ptr;
typedef typename ValueTraits::const_pointer const_pointer;
typedef ValueTraits value_traits;
static const bool value =
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, node_ptr, to_node_ptr, (value_type&) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, pointer, to_value_ptr, (node_ptr) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_node_ptr, to_node_ptr, (const value_type&) )))
||
(boost::intrusive::function_detector::NonStaticFunction ==
(BOOST_INTRUSIVE_DETECT_FUNCTION(ValueTraits, boost_intrusive, const_pointer, to_value_ptr, (const_node_ptr) )))
;
};
}}}
#endif
#include <boost/intrusive/detail/config_end.hpp>
#endif //@ifndef BOOST_INTRUSIVE_DETAIL_IS_STATEFUL_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,188 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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 Container::value_type
, typename Container::difference_type
, typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
, typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
>
{
protected:
typedef typename Container::real_value_traits real_value_traits;
typedef typename real_value_traits::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef typename 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 Container::value_type value_type;
typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
list_iterator()
: members_ (node_ptr(0), 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;
}
friend bool operator== (const list_iterator& l, const list_iterator& r)
{ return l.pointed_node() == r.pointed_node(); }
friend bool operator!= (const list_iterator& l, const list_iterator& r)
{ return !(l == r); }
reference operator*() const
{ return *operator->(); }
pointer operator->() const
{ return detail::boost_intrusive_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

View File

@@ -0,0 +1,355 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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 <boost/intrusive/detail/config_begin.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; };
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R>
struct is_unary_or_binary_function_impl<R (*)()>
{ static const bool value = true; };
template <typename R>
struct is_unary_or_binary_function_impl<R (*)(...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R>
struct is_unary_or_binary_function_impl<R (__stdcall*)()>
{ static const bool value = true; };
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
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (*)(T0)>
{ static const bool value = true; };
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (*)(T0...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0>
struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)>
{ static const bool value = true; };
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
// see boost ticket #4094
// avoid duplicate definitions of is_unary_or_binary_function_impl
#ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (*)(T0, T1)>
{ static const bool value = true; };
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (*)(T0, T1...)>
{ static const bool value = true; };
#else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
template <typename R, class T0, class T1>
struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)>
{ static const bool value = true; };
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
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP

View File

@@ -0,0 +1,69 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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_PARENT_FROM_MEMBER_HPP
#define BOOST_INTRUSIVE_DETAIL_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_DETAIL_PARENT_FROM_MEMBER_HPP

View File

@@ -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

View File

@@ -0,0 +1,177 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009.
//
// 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

View File

@@ -0,0 +1,163 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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 Container::value_type
, typename Container::difference_type
, typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
, typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
>
{
protected:
typedef typename Container::real_value_traits real_value_traits;
typedef typename real_value_traits::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef typename 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 Container::value_type value_type;
typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
slist_iterator()
: members_ (node_ptr(0), 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;
}
friend bool operator== (const slist_iterator& l, const slist_iterator& r)
{ return l.pointed_node() == r.pointed_node(); }
friend bool operator!= (const slist_iterator& l, const slist_iterator& r)
{ return !(l == r); }
reference operator*() const
{ return *operator->(); }
pointer operator->() const
{ return detail::boost_intrusive_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

View File

@@ -0,0 +1,173 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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; }
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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,190 @@
/////////////////////////////////////////////////////////////////////////////
//
// (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 Container::value_type
, typename Container::difference_type
, typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type
, typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type
>
{
protected:
typedef typename Container::real_value_traits real_value_traits;
typedef typename Container::node_algorithms node_algorithms;
typedef typename real_value_traits::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename node_traits::node_ptr node_ptr;
typedef typename 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 Container::value_type value_type;
typedef typename detail::if_c<IsConst,typename Container::const_pointer,typename Container::pointer>::type pointer;
typedef typename detail::if_c<IsConst,typename Container::const_reference,typename Container::reference>::type reference;
tree_iterator()
: members_ (node_ptr(0), (const void *)0)
{}
explicit tree_iterator(node_ptr nodeptr, const Container *cont_ptr)
: members_ (nodeptr, cont_ptr)
{}
tree_iterator(tree_iterator<Container, false> const& other)
: members_(other.pointed_node(), other.get_container())
{}
const node_ptr &pointed_node() const
{ return members_.nodeptr_; }
tree_iterator &operator=(const node_ptr &nodeptr)
{ members_.nodeptr_ = nodeptr; return static_cast<tree_iterator&>(*this); }
public:
tree_iterator& operator++()
{
members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
return static_cast<tree_iterator&> (*this);
}
tree_iterator operator++(int)
{
tree_iterator result (*this);
members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
return result;
}
tree_iterator& operator--()
{
members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
return static_cast<tree_iterator&> (*this);
}
tree_iterator operator--(int)
{
tree_iterator result (*this);
members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
return result;
}
friend bool operator== (const tree_iterator& l, const tree_iterator& r)
{ return l.pointed_node() == r.pointed_node(); }
friend bool operator!= (const tree_iterator& l, const tree_iterator& r)
{ return !(l == r); }
reference operator*() const
{ return *operator->(); }
pointer operator->() const
{ return detail::boost_intrusive_get_pointer(this->get_real_value_traits()->to_value_ptr(members_.nodeptr_)); }
const Container *get_container() const
{ return static_cast<const Container*>(members_.get_ptr()); }
const real_value_traits *get_real_value_traits() const
{ return &this->get_container()->get_real_value_traits(); }
tree_iterator end_iterator_from_it() const
{
return tree_iterator(node_algorithms::get_header(this->pointed_node()), this->get_container());
}
tree_iterator<Container, false> unconst() const
{ return tree_iterator<Container, false>(this->pointed_node(), this->get_container()); }
private:
struct members
: public detail::select_constptr
<void_pointer, store_container_ptr>::type
{
typedef typename detail::select_constptr
<void_pointer, store_container_ptr>::type Base;
members(const node_ptr &n_ptr, const void *cont)
: Base(cont), nodeptr_(n_ptr)
{}
node_ptr nodeptr_;
} members_;
};
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_TREE_NODE_HPP

View File

@@ -0,0 +1,741 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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/intrusive/detail/is_stateful_value_traits.hpp>
#include <boost/cstdint.hpp>
#include <cstddef>
#include <climits>
#include <iterator>
#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>
namespace boost {
namespace intrusive {
namespace detail {
template <class T>
struct internal_member_value_traits
{
template <class U> static detail::one test(...);
template <class U> static detail::two test(typename U::member_value_traits* = 0);
static const bool value = sizeof(test<T>(0)) == sizeof(detail::two);
};
template <class T>
struct internal_base_hook_bool
{
template<bool Add>
struct two_or_three {one _[2 + Add];};
template <class U> static one test(...);
template <class U> static two_or_three<U::boost_intrusive_tags::is_base_hook> test (int);
static const std::size_t value = sizeof(test<T>(0));
};
template <class T>
struct internal_base_hook_bool_is_true
{
static const bool value = internal_base_hook_bool<T>::value > sizeof(one)*2;
};
template <class T>
struct internal_any_hook_bool
{
template<bool Add>
struct two_or_three {one _[2 + Add];};
template <class U> static one test(...);
template <class U> static two_or_three<U::is_any_hook> test (int);
static const std::size_t value = sizeof(test<T>(0));
};
template <class T>
struct internal_any_hook_bool_is_true
{
static const bool value = internal_any_hook_bool<T>::value > sizeof(one)*2;
};
template <class T>
struct external_value_traits_bool
{
template<bool Add>
struct two_or_three {one _[2 + Add];};
template <class U> static one test(...);
template <class U> static two_or_three<U::external_value_traits> test (int);
static const std::size_t value = sizeof(test<T>(0));
};
template <class T>
struct external_bucket_traits_bool
{
template<bool Add>
struct two_or_three {one _[2 + Add];};
template <class U> static one test(...);
template <class U> static two_or_three<U::external_bucket_traits> test (int);
static const std::size_t value = sizeof(test<T>(0));
};
template <class T>
struct external_value_traits_is_true
{
static const bool value = external_value_traits_bool<T>::value > sizeof(one)*2;
};
template<class Node, class Tag, link_mode_type LinkMode, int>
struct node_holder
: public Node
{};
template<class 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 boost_intrusive_get_pointer
template<class Ptr>
inline typename smart_ptr_type<Ptr>::pointer
boost_intrusive_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 Container::value_type value_type;
typedef typename real_value_traits::node_ptr node_ptr;
typedef typename real_value_traits::const_node_ptr const_node_ptr;
typedef detail::ebo_functor_holder<KeyValueCompare> base_t;
key_nodeptr_comp(KeyValueCompare kcomp, const Container *cont)
: base_t(kcomp), cont_(cont)
{}
template<class T>
struct is_node_ptr
{
static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value;
};
template<class T>
typename enable_if_c<is_node_ptr<T>::value, const value_type &>::type
key_forward(const T &node) const
{ return *cont_->get_real_value_traits().to_value_ptr(node); }
template<class T>
typename enable_if_c<!is_node_ptr<T>::value, const T &>::type
key_forward(const T &key) const
{ return key;}
template<class KeyType, class KeyType2>
bool operator()(const KeyType &key1, const KeyType2 &key2) const
{ return base_t::get()(this->key_forward(key1), this->key_forward(key2)); }
const Container *cont_;
};
template<class F, class Container>
struct node_cloner
: private detail::ebo_functor_holder<F>
{
typedef typename Container::real_value_traits real_value_traits;
typedef typename Container::node_algorithms node_algorithms;
typedef typename real_value_traits::value_type value_type;
typedef typename real_value_traits::pointer pointer;
typedef typename real_value_traits::node_traits::node node;
typedef typename real_value_traits::node_ptr node_ptr;
typedef typename real_value_traits::const_node_ptr const_node_ptr;
typedef detail::ebo_functor_holder<F> base_t;
enum { safemode_or_autounlink =
(int)real_value_traits::link_mode == (int)auto_unlink ||
(int)real_value_traits::link_mode == (int)safe_link };
node_cloner(F f, const Container *cont)
: base_t(f), cont_(cont)
{}
node_ptr operator()(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::boost_intrusive_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 T, bool Add>
struct add_const_if_c
{
typedef typename detail::if_c
< Add
, typename detail::add_const<T>::type
, T
>::type type;
};
template <link_mode_type LinkMode>
struct link_dispatch
{};
template<class Hook>
void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
{ //If this assertion raises, you might have destroyed an object
//while it was still inserted in a container that is alive.
//If so, remove the object from the container before destroying it.
(void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
}
template<class Hook>
void destructor_impl(Hook &hook, detail::link_dispatch<auto_unlink>)
{ hook.unlink(); }
template<class Hook>
void destructor_impl(Hook &, detail::link_dispatch<normal_link>)
{}
template<class T, class NodeTraits, link_mode_type LinkMode, class Tag, int HookType>
struct base_hook_traits
{
public:
typedef detail::node_holder
<typename NodeTraits::node, Tag, LinkMode, HookType> node_holder;
typedef 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 static_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::boost_intrusive_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::boost_intrusive_get_pointer(n)), P);
}
};
template<class Functor>
struct function_hook_traits
{
public:
typedef typename Functor::hook_type hook_type;
typedef typename Functor::hook_ptr hook_ptr;
typedef typename Functor::const_hook_ptr const_hook_ptr;
typedef typename hook_type::boost_intrusive_tags::node_traits node_traits;
typedef typename node_traits::node node;
typedef typename Functor::value_type value_type;
typedef typename node_traits::node_ptr node_ptr;
typedef typename node_traits::const_node_ptr const_node_ptr;
typedef typename boost::pointer_to_other<node_ptr, value_type>::type pointer;
typedef typename boost::pointer_to_other<node_ptr, const value_type>::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_type::boost_intrusive_tags::link_mode;
static node_ptr to_node_ptr(reference value)
{ return static_cast<node*>(&*Functor::to_hook_ptr(value)); }
static const_node_ptr to_node_ptr(const_reference value)
{ return static_cast<const node*>(&*Functor::to_hook_ptr(value)); }
static pointer to_value_ptr(node_ptr n)
{ return Functor::to_value_ptr(to_hook_ptr(n)); }
static const_pointer to_value_ptr(const_node_ptr n)
{ return Functor::to_value_ptr(to_hook_ptr(n)); }
private:
static hook_ptr to_hook_ptr(node_ptr n)
{ return hook_ptr(&*static_cast<hook_type*>(&*n)); }
static const_hook_ptr to_hook_ptr(const_node_ptr n)
{ return const_hook_ptr(&*static_cast<const hook_type*>(&*n)); }
};
//This function uses binary search to discover the
//highest set bit of the integer
inline std::size_t floor_log2 (std::size_t x)
{
const std::size_t Bits = sizeof(std::size_t)*CHAR_BIT;
const bool Size_t_Bits_Power_2= !(Bits & (Bits-1));
BOOST_STATIC_ASSERT(Size_t_Bits_Power_2);
std::size_t n = x;
std::size_t log2 = 0;
for(std::size_t shift = Bits >> 1; shift; shift >>= 1){
std::size_t tmp = n >> shift;
if (tmp)
log2 += shift, n = tmp;
}
return log2;
}
inline float fast_log2 (float val)
{
union caster_t
{
boost::uint32_t x;
float val;
} caster;
caster.val = val;
boost::uint32_t x = caster.x;
const int log_2 = (int)(((x >> 23) & 255) - 128);
x &= ~(255 << 23);
x += 127 << 23;
caster.x = x;
val = caster.val;
val = ((-1.0f/3) * 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_);
}
}
}
};
template<class ValueTraits, bool ExternalValueTraits>
struct store_cont_ptr_on_it_impl
{
static const bool value = is_stateful_value_traits<ValueTraits>::value;
};
template<class ValueTraits>
struct store_cont_ptr_on_it_impl<ValueTraits, true>
{
static const bool value = true;
};
template <class Container>
struct store_cont_ptr_on_it
{
typedef typename Container::value_traits value_traits;
static const bool value = store_cont_ptr_on_it_impl
<value_traits, external_value_traits_is_true<value_traits>::value>::value;
};
template<class Container, bool IsConst>
struct node_to_value
: public detail::select_constptr
< typename 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))); }
};
//This is not standard, but should work with all compilers
union max_align
{
char char_;
short short_;
int int_;
long long_;
#ifdef BOOST_HAS_LONG_LONG
long long long_long_;
#endif
float float_;
double double_;
long double long_double_;
void * void_ptr_;
};
template<class T, std::size_t N>
class array_initializer
{
public:
template<class CommonInitializer>
array_initializer(const CommonInitializer &init)
{
char *init_buf = (char*)rawbuf;
std::size_t i = 0;
try{
for(; i != N; ++i){
new(init_buf)T(init);
init_buf += sizeof(T);
}
}
catch(...){
while(i--){
init_buf -= sizeof(T);
((T*)init_buf)->~T();
}
throw;
}
}
operator T* ()
{ return (T*)(rawbuf); }
operator const T*() const
{ return (const T*)(rawbuf); }
~array_initializer()
{
char *init_buf = (char*)rawbuf + N*sizeof(T);
for(std::size_t i = 0; i != N; ++i){
init_buf -= sizeof(T);
((T*)init_buf)->~T();
}
}
private:
detail::max_align rawbuf[(N*sizeof(T)-1)/sizeof(detail::max_align)+1];
};
} //namespace detail
} //namespace intrusive
} //namespace boost
#include <boost/intrusive/detail/config_end.hpp>
#endif //BOOST_INTRUSIVE_DETAIL_UTILITIES_HPP

View File

@@ -0,0 +1,30 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2009. 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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,542 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class slist_base_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class slist_member_hook;
//list
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class list_base_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class list_member_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class list_hook;
//rbtree/set/multiset
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
>
#else
template<class T, class ...Options>
#endif
class rbtree;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class multiset;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class splaytree;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class splay_set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class splay_multiset;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class splay_set_base_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class splay_set_member_hook;
//avltree/avl_set/avl_multiset
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
>
#else
template<class T, class ...Options>
#endif
class avltree;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class avl_set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class avl_multiset;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class treap;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class treap_set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class treap_multiset;
//Default priority comparison functor
template <class T>
struct priority_compare;
//sgtree/sg_set/sg_multiset
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
>
#else
template<class T, class ...Options>
#endif
class sgtree;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class sg_set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !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
class sg_multiset;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class bs_set_base_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class bs_set_member_hook;
//hashtable/unordered_set/unordered_multiset
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
, class O5 = none
, class O6 = none
, class O7 = none
, class O8 = none
, class O9 = none
, class O10 = none
>
#else
template<class T, class ...Options>
#endif
class hashtable;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
, class O5 = none
, class O6 = none
, class O7 = none
, class O8 = none
, class O9 = none
, class O10 = none
>
#else
template<class T, class ...Options>
#endif
class unordered_set;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class T
, class O1 = none
, class O2 = none
, class O3 = none
, class O4 = none
, class O5 = none
, class O6 = none
, class O7 = none
, class O8 = none
, class O9 = none
, class O10 = none
>
#else
template<class T, class ...Options>
#endif
class unordered_multiset;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(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;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class any_base_hook;
#if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) && !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
template
< class O1 = none
, class O2 = none
, class O3 = none
>
#else
template<class ...Options>
#endif
class any_member_hook;
} //namespace intrusive {
} //namespace boost {
/// @endcond
#endif //#ifndef BOOST_INTRUSIVE_FWD_HPP

View File

@@ -0,0 +1,327 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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>: Linear
//!
//! <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

View File

@@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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

1527
test/external/boost/intrusive/list.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,290 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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

View File

@@ -0,0 +1,65 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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::boost_intrusive_get_pointer(n), PtrToMember));
}
static const_pointer to_value_ptr(const_node_ptr n)
{
return pointer(detail::parent_from_member<value_type, node>
(detail::boost_intrusive_get_pointer(n), PtrToMember));
}
};
} //namespace intrusive
} //namespace boost
#endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP

View File

@@ -0,0 +1,812 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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 the function object that will
//!be used to convert between values to be inserted in a container
//!and the hook to be used for that purpose.
template< typename Functor>
struct function_hook
{
/// @cond
typedef detail::function_hook_traits
<Functor> function_value_traits;
template<class Base>
struct pack : Base
{
typedef function_value_traits value_traits;
};
/// @endcond
};
//!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

View File

@@ -0,0 +1,42 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2010-2010
//
// 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_GET_PARENT_FROM_MEMBER_HPP
#define BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/detail/parent_from_member.hpp>
namespace boost {
namespace intrusive {
//! Given a pointer to a member and its corresponding pointer to data member,
//! this function returns the pointer of the parent containing that member.
//! Note: this function does not work with pointer to members that rely on
//! virtual inheritance.
template<class Parent, class Member>
inline Parent *get_parent_from_member(Member *member, const Member Parent::* ptr_to_member)
{ return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
//! Given a const pointer to a member and its corresponding const pointer to data member,
//! this function returns the const pointer of the parent containing that member.
//! Note: this function does not work with pointer to members that rely on
//! virtual inheritance.
template<class Parent, class Member>
inline const Parent *get_parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
{ return ::boost::intrusive::detail::parent_from_member(member, ptr_to_member); }
} //namespace intrusive {
} //namespace boost {
#include <boost/intrusive/detail/config_end.hpp>
#endif //#ifndef BOOST_INTRUSIVE_GET_PARENT_FROM_MEMBER_HPP

View File

@@ -0,0 +1,82 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2007-2009
//
// 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 bits 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

View File

@@ -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

1688
test/external/boost/intrusive/rbtree.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,909 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009.
//
// 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::boost_intrusive_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.
//! "pos" must be a valid iterator or header (end) node.
//! "pos" must be an iterator pointing to the successor to "new_node"
//! once inserted according to the order of already inserted nodes. This function does not
//! check "pos" and this precondition must be guaranteed by the caller.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node"
//! tree invariants might be broken.
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node)
{
tree_algorithms::insert_before(header, pos, new_node);
rebalance_after_insertion(header, new_node);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering no less than the
//! greatest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is less than the greatest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_back(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_back(header, new_node);
rebalance_after_insertion(header, new_node);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering, no greater than the
//! lowest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is greater than the lowest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_front(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_front(header, new_node);
rebalance_after_insertion(header, new_node);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! KeyNodePtrCompare is a function object that induces a strict weak
//! ordering compatible with the strict weak ordering used to create the
//! the tree. NodePtrCompare compares KeyType with a node_ptr.
//!
//! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
//! tree according to "comp" and obtains the needed information to realize
//! a constant-time node insertion if there is no equivalent node.
//!
//! <b>Returns</b>: If there is an equivalent value
//! returns a pair containing a node_ptr to the already present node
//! and false. If there is not equivalent key can be inserted returns true
//! in the returned pair's boolean and fills "commit_data" that is meant to
//! be used with the "insert_commit" function to achieve a constant-time
//! insertion function.
//!
//! <b>Complexity</b>: Average complexity is at most logarithmic.
//!
//! <b>Throws</b>: If "comp" throws.
//!
//! <b>Notes</b>: This function is used to improve performance when constructing
//! a node is expensive and the user does not want to have two equivalent nodes
//! in the tree: if there is an equivalent value
//! the constructed object must be discarded. Many times, the part of the
//! node that is used to impose the order is much cheaper to construct
//! than the node and this function offers the possibility to use that part
//! to check if the insertion will be successful.
//!
//! If the check is successful, the user can construct the node and use
//! "insert_commit" to insert the node in constant-time. This gives a total
//! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
//!
//! "commit_data" remains valid for a subsequent "insert_unique_commit" only
//! if no more objects are inserted or erased from the set.
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

2384
test/external/boost/intrusive/set.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,300 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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

2431
test/external/boost/intrusive/sg_set.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

1908
test/external/boost/intrusive/sgtree.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,783 @@
/////////////////////////////////////////////////////////////////////////////
//
// (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::boost_intrusive_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.
//! "pos" must be a valid iterator or header (end) node.
//! "pos" must be an iterator pointing to the successor to "new_node"
//! once inserted according to the order of already inserted nodes. This function does not
//! check "pos" and this precondition must be guaranteed by the caller.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node"
//! tree invariants might be broken.
template<class H_Alpha>
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node
,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
{
std::size_t depth;
tree_algorithms::insert_before(header, pos, new_node, &depth);
rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering no less than the
//! greatest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is less than the greatest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
template<class H_Alpha>
static void push_back(node_ptr header, node_ptr new_node
,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
{
std::size_t depth;
tree_algorithms::push_back(header, new_node, &depth);
rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering, no greater than the
//! lowest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is greater than the lowest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
template<class H_Alpha>
static void push_front(node_ptr header, node_ptr new_node
,std::size_t tree_size, H_Alpha h_alpha, std::size_t &max_tree_size)
{
std::size_t depth;
tree_algorithms::push_front(header, new_node, &depth);
rebalance_after_insertion(new_node, depth, tree_size+1, h_alpha, max_tree_size);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! KeyNodePtrCompare is a function object that induces a strict weak
//! ordering compatible with the strict weak ordering used to create the
//! the tree. NodePtrCompare compares KeyType with a node_ptr.
//! "hint" is node from the "header"'s tree.
//!
//! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
//! tree according to "comp" using "hint" as a hint to where it should be
//! inserted and obtains the needed information to realize
//! a constant-time node insertion if there is no equivalent node.
//! If "hint" is the upper_bound the function has constant time
//! complexity (two comparisons in the worst case).
//!
//! <b>Returns</b>: If there is an equivalent value
//! returns a pair containing a node_ptr to the already present node
//! and false. If there is not equivalent key can be inserted returns true
//! in the returned pair's boolean and fills "commit_data" that is meant to
//! be used with the "insert_commit" function to achieve a constant-time
//! insertion function.
//!
//! <b>Complexity</b>: Average complexity is at most logarithmic, but it is
//! amortized constant time if new_node should be inserted immediately before "hint".
//!
//! <b>Throws</b>: If "comp" throws.
//!
//! <b>Notes</b>: This function is used to improve performance when constructing
//! a node is expensive and the user does not want to have two equivalent nodes
//! in the tree: if there is an equivalent value
//! the constructed object must be discarded. Many times, the part of the
//! node that is used to impose the order is much cheaper to construct
//! than the node and this function offers the possibility to use that part
//! to check if the insertion will be successful.
//!
//! If the check is successful, the user can construct the node and use
//! "insert_commit" to insert the node in constant-time. This gives a total
//! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
//!
//! "commit_data" remains valid for a subsequent "insert_unique_commit" only
//! if no more objects are inserted or erased from the set.
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

2134
test/external/boost/intrusive/slist.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,294 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,976 @@
/////////////////////////////////////////////////////////////////////////////
//
// (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@teknologisk.dk
//
// Requirements for element type
// * must be copy-constructible
// * destructor must not throw exception
//
// Methods marked with note A only throws an exception if the evaluation of the
// predicate throws an exception. If an exception is thrown the call has no
// effect on the containers state
//
// Methods marked with note B only throws an exception if the coppy constructor
// or assignment operator of the predicate throws an exception. If an exception
// is thrown the call has no effect on the containers state
//
// iterators are only invalidated, if the element pointed to by the iterator
// is deleted. The same goes for element references
//
#ifndef BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
#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::boost_intrusive_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);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "pos" must be a valid iterator or header (end) node.
//! "pos" must be an iterator pointing to the successor to "new_node"
//! once inserted according to the order of already inserted nodes. This function does not
//! check "pos" and this precondition must be guaranteed by the caller.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node"
//! tree invariants might be broken.
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node)
{
tree_algorithms::insert_before(header, pos, new_node);
splay_up(new_node, header);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering no less than the
//! greatest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is less than the greatest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_back(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_back(header, new_node);
splay_up(new_node, header);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering, no greater than the
//! lowest inserted key.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Note</b>: If "new_node" is greater than the lowest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
static void push_front(node_ptr header, node_ptr new_node)
{
tree_algorithms::push_front(header, new_node);
splay_up(new_node, header);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! NodePtrCompare is a function object that induces a strict weak
//! ordering compatible with the strict weak ordering used to create the
//! the tree. NodePtrCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts new_node into the tree before the upper bound
//! according to "comp".
//!
//! <b>Complexity</b>: Average complexity for insert element is at
//! most logarithmic.
//!
//! <b>Throws</b>: If "comp" throws.
template<class NodePtrCompare>
static node_ptr insert_equal_upper_bound
(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);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! NodePtrCompare is a function object that induces a strict weak
//! ordering compatible with the strict weak ordering used to create the
//! the tree. NodePtrCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts new_node into the tree before the lower bound
//! according to "comp".
//!
//! <b>Complexity</b>: Average complexity for insert element is at
//! most logarithmic.
//!
//! <b>Throws</b>: If "comp" throws.
template<class NodePtrCompare>
static node_ptr insert_equal_lower_bound
(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)){
splay_up(prev_node(z), 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

1782
test/external/boost/intrusive/treap.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,894 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009.
//
// 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_TREAP_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_TREAP_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::boost_intrusive_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>: If "pcomp" throws, strong guarantee
template<class NodePtrPriorityCompare>
static void unlink(node_ptr node, NodePtrPriorityCompare pcomp)
{
node_ptr x = NodeTraits::get_parent(node);
if(x){
while(!is_header(x))
x = NodeTraits::get_parent(x);
erase(x, node, pcomp);
}
}
//! <b>Requires</b>: header is the header of a tree.
//!
//! <b>Effects</b>: Unlinks the leftmost node from the tree, and
//! updates the header link to the new leftmost node.
//!
//! <b>Complexity</b>: Average complexity is constant time.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Notes</b>: This function breaks the tree and the tree can
//! only be used for more unlink_leftmost_without_rebalance calls.
//! This function is normally used to achieve a step by step
//! controlled destruction of the tree.
static node_ptr unlink_leftmost_without_rebalance(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>: If "pcomp" throws, strong guarantee.
template<class NodePtrPriorityCompare>
static node_ptr erase(node_ptr header, node_ptr z, NodePtrPriorityCompare 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.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts new_node into the tree before the upper bound
//! according to "comp" and rotates the tree according to "pcomp".
//!
//! <b>Complexity</b>: Average complexity for insert element is at
//! most logarithmic.
//!
//! <b>Throws</b>: If "comp" throw or "pcomp" throw.
template<class NodePtrCompare, class NodePtrPriorityCompare>
static node_ptr insert_equal_upper_bound
(node_ptr h, node_ptr new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::insert_equal_upper_bound_check(h, new_node, comp, commit_data);
rebalance_check_and_commit(h, new_node, pcomp, commit_data);
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.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts new_node into the tree before the upper bound
//! according to "comp" and rotates the tree according to "pcomp".
//!
//! <b>Complexity</b>: Average complexity for insert element is at
//! most logarithmic.
//!
//! <b>Throws</b>: If "comp" throws.
template<class NodePtrCompare, class NodePtrPriorityCompare>
static node_ptr insert_equal_lower_bound
(node_ptr h, node_ptr new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::insert_equal_lower_bound_check(h, new_node, comp, commit_data);
rebalance_check_and_commit(h, new_node, pcomp, commit_data);
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.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <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).
//! Rotates the tree according to "pcomp".
//!
//! <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" throw or "pcomp" throw.
template<class NodePtrCompare, class NodePtrPriorityCompare>
static node_ptr insert_equal
(node_ptr h, node_ptr hint, node_ptr new_node, NodePtrCompare comp, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::insert_equal_check(h, hint, new_node, comp, commit_data);
rebalance_check_and_commit(h, new_node, pcomp, commit_data);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "pos" must be a valid node of the tree (including header end) node.
//! "pos" must be a node pointing to the successor to "new_node"
//! once inserted according to the order of already inserted nodes. This function does not
//! check "pos" and this precondition must be guaranteed by the caller.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts new_node into the tree before "pos"
//! and rotates the tree according to "pcomp".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: If "pcomp" throws, strong guarantee.
//!
//! <b>Note</b>: If "pos" is not the successor of the newly inserted "new_node"
//! tree invariants might be broken.
template<class NodePtrPriorityCompare>
static node_ptr insert_before
(node_ptr header, node_ptr pos, node_ptr new_node, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::insert_before_check(header, pos, commit_data);
rebalance_check_and_commit(header, new_node, pcomp, commit_data);
return new_node;
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering no less than the
//! greatest inserted key.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts x into the tree in the last position
//! and rotates the tree according to "pcomp".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: If "pcomp" throws, strong guarantee.
//!
//! <b>Note</b>: If "new_node" is less than the greatest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
template<class NodePtrPriorityCompare>
static void push_back(node_ptr header, node_ptr new_node, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::push_back_check(header, commit_data);
rebalance_check_and_commit(header, new_node, pcomp, commit_data);
}
//! <b>Requires</b>: "header" must be the header node of a tree.
//! "new_node" must be, according to the used ordering, no greater than the
//! lowest inserted key.
//! NodePtrPriorityCompare is a priority function object that induces a strict weak
//! ordering compatible with the one used to create the
//! the tree. NodePtrPriorityCompare compares two node_ptrs.
//!
//! <b>Effects</b>: Inserts x into the tree in the first position
//! and rotates the tree according to "pcomp".
//!
//! <b>Complexity</b>: Constant-time.
//!
//! <b>Throws</b>: If "pcomp" throws, strong guarantee.
//!
//! <b>Note</b>: If "new_node" is greater than the lowest inserted key
//! tree invariants are broken. This function is slightly faster than
//! using "insert_before".
template<class NodePtrPriorityCompare>
static void push_front(node_ptr header, node_ptr new_node, NodePtrPriorityCompare pcomp)
{
insert_commit_data commit_data;
tree_algorithms::push_front_check(header, commit_data);
rebalance_check_and_commit(header, new_node, pcomp, 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, 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 NodePtrPriorityCompare>
static void rebalance_for_erasure(node_ptr header, node_ptr z, NodePtrPriorityCompare 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 NodePtrPriorityCompare>
static void rebalance_check_and_commit
(node_ptr h, node_ptr new_node, NodePtrPriorityCompare pcomp, insert_commit_data &commit_data)
{
rebalance_after_insertion_check(h, commit_data.node, new_node, pcomp, commit_data.rotations);
//No-throw
tree_algorithms::insert_unique_commit(h, new_node, commit_data);
rebalance_after_insertion_commit(h, new_node, commit_data.rotations);
}
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 execute n rotations
for( node_ptr p_parent = NodeTraits::get_parent(p)
; n--
; p_parent = NodeTraits::get_parent(p)){
//Check if left child
if(p == NodeTraits::get_left(p_parent)){
tree_algorithms::rotate_right(p_parent, header);
}
else{ //Right child
tree_algorithms::rotate_left(p_parent, header);
}
}
}
template<class NodePtrPriorityCompare>
static bool check_invariant(const_node_ptr header, NodePtrPriorityCompare 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_TREAP_ALGORITHMS_HPP

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,433 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
// (C) Copyright Ion Gaztanaga 2006-2009
//
// 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/pointer_cast.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)
{
// This still fails in gcc < 4.4 so forget about it
// using ::boost::static_pointer_cast;
// return static_pointer_cast<node>(n->next_);
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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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)
public:
//! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
//! initializes the node to an unlinked state.
//!
//! <b>Throws</b>: Nothing.
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