Boost logo

Boost-Commit :

From: igaztanaga_at_[hidden]
Date: 2007-10-24 14:59:28


Author: igaztanaga
Date: 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
New Revision: 40428
URL: http://svn.boost.org/trac/boost/changeset/40428

Log:
Fixed Solaris-gcc errors and added splay trees
Added:
   trunk/boost/intrusive/detail/tree_algorithms.hpp (contents, props changed)
   trunk/boost/intrusive/detail/tree_node.hpp (contents, props changed)
   trunk/boost/intrusive/splay_set.hpp (contents, props changed)
   trunk/boost/intrusive/splay_set_hook.hpp (contents, props changed)
   trunk/boost/intrusive/splaytree.hpp (contents, props changed)
   trunk/boost/intrusive/splaytree_algorithms.hpp (contents, props changed)
Text files modified:
   trunk/boost/intrusive/detail/generic_hook.hpp | 7
   trunk/boost/intrusive/detail/mpl.hpp | 8
   trunk/boost/intrusive/detail/rbtree_node.hpp | 9
   trunk/boost/intrusive/detail/utilities.hpp | 10
   trunk/boost/intrusive/intrusive_fwd.hpp | 44 +
   trunk/boost/intrusive/options.hpp | 21
   trunk/boost/intrusive/pointer_plus_bit.hpp | 5
   trunk/boost/intrusive/rbtree.hpp | 95 +-
   trunk/boost/intrusive/rbtree_algorithms.hpp | 1086 ++++++---------------------------------
   trunk/boost/intrusive/set.hpp | 32 +
   trunk/boost/intrusive/set_hook.hpp | 26
   trunk/boost/intrusive/slist.hpp | 3
   12 files changed, 353 insertions(+), 993 deletions(-)

Modified: trunk/boost/intrusive/detail/generic_hook.hpp
==============================================================================
--- trunk/boost/intrusive/detail/generic_hook.hpp (original)
+++ trunk/boost/intrusive/detail/generic_hook.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -32,6 +32,7 @@
 , SlistBaseHook
 , SetBaseHook
 , UsetBaseHook
+, SplaySetBaseHook
 };
 
 struct no_default_definer{};
@@ -52,6 +53,10 @@
 { typedef Hook default_set_hook; };
 
 template <class Hook>
+struct default_definer<Hook, SplaySetBaseHook>
+{ typedef Hook default_splay_set_hook; };
+
+template <class Hook>
 struct default_definer<Hook, UsetBaseHook>
 { typedef Hook default_uset_hook; };
 
@@ -115,7 +120,7 @@
       static const link_mode_type link_mode = LinkMode;
       typedef Tag tag;
       typedef typename GetNodeAlgorithms::type node_algorithms;
- typedef typename node_algorithms::node_traits node_traits;
+ typedef typename node_algorithms::node_traits node_traits;
       typedef typename node_traits::node node;
       typedef typename node_traits::node_ptr node_ptr;
       typedef typename node_traits::const_node_ptr const_node_ptr;

Modified: trunk/boost/intrusive/detail/mpl.hpp
==============================================================================
--- trunk/boost/intrusive/detail/mpl.hpp (original)
+++ trunk/boost/intrusive/detail/mpl.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -253,6 +253,14 @@
 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
 {

Modified: trunk/boost/intrusive/detail/rbtree_node.hpp
==============================================================================
--- trunk/boost/intrusive/detail/rbtree_node.hpp (original)
+++ trunk/boost/intrusive/detail/rbtree_node.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -157,17 +157,18 @@
 {};
 
 //Inherit from the detail::link_dispatch depending on the embedding capabilities
-template<class VoidPointer>
+template<class VoidPointer, bool OptimizeSize = false>
 struct rbtree_node_traits
    : public rbtree_node_traits_dispatch
          < VoidPointer
- , has_pointer_plus_bit
+ , OptimizeSize &&
+ has_pointer_plus_bit
             < VoidPointer
             , detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
>::value
>
 {};
-
+/*
 /////////////////////////////////////////////////////////////////////////////
 // //
 // Implementation of the rbtree iterator //
@@ -291,7 +292,7 @@
       node_ptr nodeptr_;
    } members_;
 };
-
+*/
 } //namespace intrusive
 } //namespace boost
 

Added: trunk/boost/intrusive/detail/tree_algorithms.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/intrusive/detail/tree_algorithms.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -0,0 +1,1332 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <cstddef>
+#include <boost/intrusive/detail/no_exceptions_support.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+
+namespace boost {
+namespace intrusive {
+namespace detail {
+
+//! This is an implementation of a binary search tree.
+//! A node in the search tree has references to its children and its parent. This
+//! is to allow traversal of the whole tree from a given node making the
+//! implementation of iterator a pointer to a node.
+//! At the top of the tree a node is used specially. This node's parent pointer
+//! is pointing to the root of the tree. Its left pointer points to the
+//! leftmost node in the tree and the right pointer to the rightmost one.
+//! This node is used to represent the end-iterator.
+//!
+//! +---------+
+//! header------------------------------>| |
+//! | |
+//! +----------(left)--------| |--------(right)---------+
+//! | +---------+ |
+//! | | |
+//! | | (parent) |
+//! | | |
+//! | | |
+//! | +---------+ |
+//! root of tree ..|......................> | | |
+//! | | D | |
+//! | | | |
+//! | +-------+---------+-------+ |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | | | |
+//! | +---------+ +---------+ |
+//! | | | | | |
+//! | | B | | F | |
+//! | | | | | |
+//! | +--+---------+--+ +--+---------+--+ |
+//! | | | | | |
+//! | | | | | |
+//! | | | | | |
+//! | +---+-----+ +-----+---+ +---+-----+ +-----+---+ |
+//! +-->| | | | | | | |<--+
+//! | A | | C | | E | | G |
+//! | | | | | | | |
+//! +---------+ +---------+ +---------+ +---------+
+//!
+
+//! tree_algorithms is configured with a NodeTraits class, which encapsulates the
+//! information about the node to be manipulated. NodeTraits must support the
+//! following interface:
+//!
+//! <b>Typedefs</b>:
+//!
+//! <tt>node</tt>: The type of the node that forms the circular list
+//!
+//! <tt>node_ptr</tt>: A pointer to a node
+//!
+//! <tt>const_node_ptr</tt>: A pointer to a const node
+//!
+//! <b>Static functions</b>:
+//!
+//! <tt>static node_ptr get_parent(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_parent(node_ptr n, node_ptr parent);</tt>
+//!
+//! <tt>static node_ptr get_left(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_left(node_ptr n, node_ptr left);</tt>
+//!
+//! <tt>static node_ptr get_right(const_node_ptr n);</tt>
+//!
+//! <tt>static void set_right(node_ptr n, node_ptr right);</tt>
+template<class NodeTraits>
+class tree_algorithms
+{
+ /// @cond
+ private:
+ typedef typename NodeTraits::node node;
+ /// @endcond
+
+ public:
+ typedef NodeTraits node_traits;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+
+ //! This type is the information that will be filled by insert_unique_check
+ struct insert_commit_data
+ {
+ insert_commit_data()
+ : link_left(false)
+ , node(0)
+ {}
+ bool link_left;
+ node_ptr node;
+ };
+
+ struct nop_erase_fixup
+ {
+ void operator()(node_ptr to_erase, node_ptr successor){}
+ };
+
+ /// @cond
+ private:
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return node_traits::get_left(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return uncast(header); }
+
+ //! <b>Requires</b>: node is a node of the tree or an node initialized
+ //! by init(...).
+ //!
+ //! <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 NodeTraits::get_parent(node) == 0; }
+
+ static node_ptr get_header(const_node_ptr node)
+ {
+ node_ptr h = uncast(node);
+ if(NodeTraits::get_parent(node)){
+ h = NodeTraits::get_parent(node);
+ while(!is_header(h))
+ h = NodeTraits::get_parent(h);
+ }
+ return h;
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(get_header(node1)), header2(get_header(node2));
+ swap_nodes(node1, header1, node2, header2);
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees with header header1 and header2.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ {
+ if(node1 == node2)
+ return;
+
+ //node1 and node2 must not be header nodes
+ //BOOST_INTRUSIVE_INVARIANT_ASSERT((header1 != node1 && header2 != node2));
+ if(header1 != header2){
+ //Update header1 if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+
+ //Update header2 if necessary
+ if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+ }
+ else{
+ //If both nodes are from the same tree
+ //Update header if necessary
+ if(node1 == NodeTraits::get_left(header1)){
+ NodeTraits::set_left(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_left(header2)){
+ NodeTraits::set_left(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_right(header1)){
+ NodeTraits::set_right(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_right(header2)){
+ NodeTraits::set_right(header2, node1);
+ }
+
+ if(node1 == NodeTraits::get_parent(header1)){
+ NodeTraits::set_parent(header1, node2);
+ }
+ else if(node2 == NodeTraits::get_parent(header2)){
+ NodeTraits::set_parent(header2, node1);
+ }
+
+ //Adjust data in nodes to be swapped
+ //so that final link swap works as expected
+ if(node1 == NodeTraits::get_parent(node2)){
+ NodeTraits::set_parent(node2, node2);
+
+ if(node2 == NodeTraits::get_right(node1)){
+ NodeTraits::set_right(node1, node1);
+ }
+ else{
+ NodeTraits::set_left(node1, node1);
+ }
+ }
+ else if(node2 == NodeTraits::get_parent(node1)){
+ NodeTraits::set_parent(node1, node1);
+
+ if(node1 == NodeTraits::get_right(node2)){
+ NodeTraits::set_right(node2, node2);
+ }
+ else{
+ NodeTraits::set_left(node2, node2);
+ }
+ }
+ }
+
+ //Now swap all the links
+ node_ptr temp;
+ //swap left link
+ temp = NodeTraits::get_left(node1);
+ NodeTraits::set_left(node1, NodeTraits::get_left(node2));
+ NodeTraits::set_left(node2, temp);
+ //swap right link
+ temp = NodeTraits::get_right(node1);
+ NodeTraits::set_right(node1, NodeTraits::get_right(node2));
+ NodeTraits::set_right(node2, temp);
+ //swap parent link
+ temp = NodeTraits::get_parent(node1);
+ NodeTraits::set_parent(node1, NodeTraits::get_parent(node2));
+ NodeTraits::set_parent(node2, temp);
+
+ //Now adjust adjacent nodes for newly inserted node 1
+ if((temp = NodeTraits::get_left(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_right(node1))){
+ NodeTraits::set_parent(temp, node1);
+ }
+ if((temp = NodeTraits::get_parent(node1)) &&
+ //The header has been already updated so avoid it
+ temp != header2){
+ if(NodeTraits::get_left(temp) == node2){
+ NodeTraits::set_left(temp, node1);
+ }
+ if(NodeTraits::get_right(temp) == node2){
+ NodeTraits::set_right(temp, node1);
+ }
+ }
+ //Now adjust adjacent nodes for newly inserted node 2
+ if((temp = NodeTraits::get_left(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_right(node2))){
+ NodeTraits::set_parent(temp, node2);
+ }
+ if((temp = NodeTraits::get_parent(node2)) &&
+ //The header has been already updated so avoid it
+ temp != header1){
+ if(NodeTraits::get_left(temp) == node1){
+ NodeTraits::set_left(temp, node2);
+ }
+ if(NodeTraits::get_right(temp) == node1){
+ NodeTraits::set_right(temp, node2);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+ replace_node(node_to_be_replaced, get_header(node_to_be_replaced), new_node);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+
+ //Update header if necessary
+ if(node_to_be_replaced == NodeTraits::get_left(header)){
+ NodeTraits::set_left(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_right(header)){
+ NodeTraits::set_right(header, new_node);
+ }
+
+ if(node_to_be_replaced == NodeTraits::get_parent(header)){
+ NodeTraits::set_parent(header, new_node);
+ }
+
+ //Now set data from the original node
+ node_ptr temp;
+ NodeTraits::set_left(new_node, NodeTraits::get_left(node_to_be_replaced));
+ NodeTraits::set_right(new_node, NodeTraits::get_right(node_to_be_replaced));
+ NodeTraits::set_parent(new_node, NodeTraits::get_parent(node_to_be_replaced));
+
+ //Now adjust adjacent nodes for newly inserted node
+ if((temp = NodeTraits::get_left(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_right(new_node))){
+ NodeTraits::set_parent(temp, new_node);
+ }
+ if((temp = NodeTraits::get_parent(new_node)) &&
+ //The header has been already updated so avoid it
+ temp != header){
+ if(NodeTraits::get_left(temp) == node_to_be_replaced){
+ NodeTraits::set_left(temp, new_node);
+ }
+ if(NodeTraits::get_right(temp) == node_to_be_replaced){
+ NodeTraits::set_right(temp, new_node);
+ }
+ }
+ }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ {
+ node_ptr p_right(NodeTraits::get_right(p));
+ if(p_right){
+ return minimum(p_right);
+ }
+ else {
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_right(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return NodeTraits::get_right(p) != x ? x : uncast(p);
+ }
+ }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ {
+ if(is_header(p)){
+ return maximum(NodeTraits::get_parent(p));
+ }
+ else if(NodeTraits::get_left(p)){
+ return maximum(NodeTraits::get_left(p));
+ }
+ else {
+ node_ptr x = NodeTraits::get_parent(p);
+ while(p == NodeTraits::get_left(x)){
+ p = x;
+ x = NodeTraits::get_parent(x);
+ }
+ return x;
+ }
+ }
+
+ //! <b>Requires</b>: p is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the minimum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr minimum (node_ptr p)
+ {
+ for(node_ptr p_left = NodeTraits::get_left(p)
+ ;p_left
+ ;p_left = NodeTraits::get_left(p)){
+ p = p_left;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: p is a node of a tree but not the header.
+ //!
+ //! <b>Effects</b>: Returns the maximum node of the subtree starting at p.
+ //!
+ //! <b>Complexity</b>: Logarithmic to the size of the subtree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr maximum(node_ptr p)
+ {
+ for(node_ptr p_right = NodeTraits::get_right(p)
+ ;p_right
+ ;p_right = NodeTraits::get_right(p)){
+ p = p_right;
+ }
+ return p;
+ }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ {
+ NodeTraits::set_parent(node, 0);
+ NodeTraits::set_left(node, 0);
+ NodeTraits::set_right(node, 0);
+ };
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ {
+ NodeTraits::set_parent(header, 0);
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+
+ //! <b>Requires</b>: "disposer" must be an object function
+ //! taking a node_ptr parameter and shouldn't throw.
+ //!
+ //! <b>Effects</b>: Empties the target tree calling
+ //! <tt>void disposer::operator()(node_ptr)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ {
+ node_ptr source_root = NodeTraits::get_parent(header);
+ if(!source_root)
+ return;
+ dispose_subtree(source_root, disposer);
+ init_header(header);
+ }
+
+ //! <b>Requires</b>: header is the header of a tree.
+ //!
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree, and
+ //! updates the header link to the new leftmost node.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ static node_ptr unlink_leftmost_without_rebalance(node_ptr header)
+ {
+ node_ptr leftmost = NodeTraits::get_left(header);
+ if (leftmost == header)
+ return 0;
+ node_ptr leftmost_parent(NodeTraits::get_parent(leftmost));
+ node_ptr leftmost_right (NodeTraits::get_right(leftmost));
+ bool is_root = leftmost_parent == header;
+
+ if (leftmost_right){
+ NodeTraits::set_parent(leftmost_right, leftmost_parent);
+ NodeTraits::set_left(header, tree_algorithms::minimum(leftmost_right));
+
+ if (is_root)
+ NodeTraits::set_parent(header, leftmost_right);
+ else
+ NodeTraits::set_left(NodeTraits::get_parent(header), leftmost_right);
+ }
+ else if (is_root){
+ NodeTraits::set_parent(header, 0);
+ NodeTraits::set_left(header, header);
+ NodeTraits::set_right(header, header);
+ }
+ else{
+ NodeTraits::set_left(leftmost_parent, 0);
+ NodeTraits::set_left(header, leftmost_parent);
+ }
+ return leftmost;
+ }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ {
+ std::size_t result = 1;
+ if(NodeTraits::get_left(node))
+ result += count(NodeTraits::get_left(node));
+ if(NodeTraits::get_right(node))
+ result += count(NodeTraits::get_right(node));
+ return result;
+ }
+
+ //! <b>Requires</b>: header1 and header2 must be the header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two trees. After the function header1 will contain
+ //! links to the second tree and header2 will have links to the first tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static void swap_tree(node_ptr header1, node_ptr header2)
+ {
+ if(header1 == header2)
+ return;
+
+ node_ptr tmp;
+
+ //Parent swap
+ tmp = NodeTraits::get_parent(header1);
+ NodeTraits::set_parent(header1, NodeTraits::get_parent(header2));
+ NodeTraits::set_parent(header2, tmp);
+ //Left swap
+ tmp = NodeTraits::get_left(header1);
+ NodeTraits::set_left(header1, NodeTraits::get_left(header2));
+ NodeTraits::set_left(header2, tmp);
+ //Right swap
+ tmp = NodeTraits::get_right(header1);
+ NodeTraits::set_right(header1, NodeTraits::get_right(header2));
+ NodeTraits::set_right(header2, tmp);
+
+ //Now test parent
+ node_ptr h1_parent(NodeTraits::get_parent(header1));
+ if(h1_parent){
+ NodeTraits::set_parent(h1_parent, header1);
+ }
+ else{
+ NodeTraits::set_left(header1, header1);
+ NodeTraits::set_right(header1, header1);
+ }
+
+ node_ptr h2_parent(NodeTraits::get_parent(header2));
+ if(h2_parent){
+ NodeTraits::set_parent(h2_parent, header2);
+ }
+ else{
+ NodeTraits::set_left(header2, header2);
+ NodeTraits::set_right(header2, header2);
+ }
+ }
+
+ static bool is_header(const_node_ptr p)
+ {
+ bool is_header = false;
+ if(NodeTraits::get_parent(p) == p){
+ is_header = true;
+ }
+ else if(NodeTraits::get_parent(NodeTraits::get_parent(p)) == p){
+ if(NodeTraits::get_left(p) != 0){
+ if(NodeTraits::get_parent(NodeTraits::get_left(p)) != p){
+ is_header = true;
+ }
+ if(NodeTraits::get_parent(p) == NodeTraits::get_left(p)){
+ is_header = true;
+ }
+ }
+ }
+ return is_header;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the element that is equivalent to
+ //! "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr find
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr end = uncast(header);
+ node_ptr y = lower_bound(header, key, comp);
+ 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)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else{
+ node_ptr xu(x), yu(y);
+ y = x, x = NodeTraits::get_left(x);
+ xu = NodeTraits::get_right(xu);
+
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+
+ while(xu){
+ if(comp(key, xu)){
+ yu = xu;
+ xu = NodeTraits::get_left(xu);
+ }
+ else {
+ xu = NodeTraits::get_right(xu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, yu);
+ }
+ }
+ return std::pair<node_ptr,node_ptr> (y, y);
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is
+ //! not less than "key" according to "comp" or "header" if that element does
+ //! not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr lower_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(x, key)){
+ x = NodeTraits::get_right(x);
+ }
+ else {
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs.
+ //!
+ //! <b>Effects</b>: Returns an node_ptr to the first element that is greater
+ //! than "key" according to "comp" or "header" if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr upper_bound
+ (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
+ {
+ node_ptr y = uncast(header);
+ node_ptr x = NodeTraits::get_parent(header);
+ while(x){
+ if(comp(key, x)){
+ y = x;
+ x = NodeTraits::get_left(x);
+ }
+ else {
+ x = NodeTraits::get_right(x);
+ }
+ }
+ return y;
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! "commit_data" must have been obtained from a previous call to
+ //! "insert_unique_check". No objects should have been inserted or erased
+ //! from the set between the "insert_unique_check" that filled "commit_data"
+ //! and the call to "insert_commit".
+ //!
+ //!
+ //! <b>Effects</b>: Inserts new_node in the set using the information obtained
+ //! from the "commit_data" that a previous "insert_check" filled.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function has only sense if a "insert_unique_check" has been
+ //! previously executed to fill "commit_data". No value should be inserted or
+ //! erased between the "insert_check" and "insert_commit" calls.
+ static void insert_unique_commit
+ (node_ptr header, node_ptr new_value, const insert_commit_data &commit_data)
+ {
+ //Check if commit_data has not been initialized by a insert_unique_check call.
+ BOOST_INTRUSIVE_INVARIANT_ASSERT(commit_data.node != 0);
+ link(header, new_value, commit_data.node, commit_data.link_left);
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! KeyNodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares KeyType with a node_ptr.
+ //!
+ //! <b>Effects</b>: Checks if there is an equivalent node to "key" in the
+ //! tree according to "comp" and obtains the needed information to realize
+ //! a constant-time node insertion if there is no equivalent node.
+ //!
+ //! <b>Returns</b>: If there is an equivalent value
+ //! returns a pair containing a node_ptr to the already present node
+ //! and false. If there is not equivalent key can be inserted returns true
+ //! in the returned pair's boolean and fills "commit_data" that is meant to
+ //! be used with the "insert_commit" function to achieve a constant-time
+ //! insertion function.
+ //!
+ //! <b>Complexity</b>: Average complexity is at most logarithmic.
+ //!
+ //! <b>Throws</b>: If "comp" throws.
+ //!
+ //! <b>Notes</b>: This function is used to improve performance when constructing
+ //! a node is expensive and the user does not want to have two equivalent nodes
+ //! in the tree: if there is an equivalent value
+ //! the constructed object must be discarded. Many times, the part of the
+ //! node that is used to impose the order is much cheaper to construct
+ //! than the node and this function offers the possibility to use that part
+ //! to check if the insertion will be successful.
+ //!
+ //! If the check is successful, the user can construct the node and use
+ //! "insert_commit" to insert the node in constant-time. This gives a total
+ //! logarithmic complexity to the insertion: check(O(log(N)) + commit(O(1)).
+ //!
+ //! "commit_data" remains valid for a subsequent "insert_unique_commit" only
+ //! if no more objects are inserted or erased from the set.
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ node_ptr h(uncast(header));
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+ node_ptr prev(0);
+
+ //Find the upper bound, cache the previous value and if we should
+ //store it in the left or right node
+ bool left_child = true;
+ while(x){
+ y = x;
+ x = (left_child = comp(key, x)) ?
+ NodeTraits::get_left(x) : (prev = y, NodeTraits::get_right(x));
+ }
+
+ //Since we've found the upper bound there is no other value with the same key if:
+ // - There is no previous node
+ // - The previous node is less than the key
+ if(!prev || comp(prev, key)){
+ commit_data.link_left = left_child;
+ commit_data.node = y;
+ return std::pair<node_ptr, bool>(node_ptr(), true);
+ }
+ //If the previous value was not less than key, it means that it's equal
+ //(because we've checked the upper bound)
+ else{
+ return std::pair<node_ptr, bool>(prev, false);
+ }
+ }
+
+ template<class KeyType, class KeyNodePtrCompare>
+ static std::pair<node_ptr, bool> insert_unique_check
+ (const_node_ptr header, node_ptr hint, const KeyType &key
+ ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
+ {
+ //hint must be bigger than the key
+ if(hint == header || comp(key, hint)){
+ node_ptr prev = hint;
+ //The previous value should be less than the key
+ if(prev == NodeTraits::get_left(header) || comp((prev = prev_node(hint)), key)){
+ commit_data.link_left = unique(header) || !NodeTraits::get_left(hint);
+ commit_data.node = commit_data.link_left ? hint : prev;
+ return std::pair<node_ptr, bool>(node_ptr(), true);
+ }
+ else{
+ return insert_unique_check(header, key, comp, commit_data);
+ }
+ }
+ //The hint was wrong, use hintless insert
+ else{
+ return insert_unique_check(header, key, comp, commit_data);
+ }
+ }
+
+ //! <b>Requires</b>: "header" must be the header node of a tree.
+ //! NodePtrCompare is a function object that induces a strict weak
+ //! ordering compatible with the strict weak ordering used to create the
+ //! the tree. NodePtrCompare compares two node_ptrs. "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)
+ {
+ if(hint == header || !comp(hint, new_node)){
+ node_ptr prev(hint);
+ if(hint == NodeTraits::get_left(header) ||
+ !comp(new_node, (prev = prev_node(hint)))){
+ bool link_left = unique(header) || !NodeTraits::get_left(hint);
+ link(header, new_node, link_left ? hint : prev, link_left);
+ return new_node;
+ }
+ else{
+ return insert_equal_upper_bound(header, new_node, comp);
+ }
+ }
+ else{
+ return insert_equal_lower_bound(header, new_node, comp);
+ }
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp)
+ {
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+
+ while(x){
+ y = x;
+ x = comp(new_node, x) ?
+ NodeTraits::get_left(x) : NodeTraits::get_right(x);
+ }
+
+ bool link_left = (y == h) || comp(new_node, y);
+ link(h, new_node, y, link_left);
+ return new_node;
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr h, node_ptr new_node, NodePtrCompare comp)
+ {
+ node_ptr y(h);
+ node_ptr x(NodeTraits::get_parent(y));
+
+ while(x){
+ y = x;
+ x = !comp(x, new_node) ?
+ NodeTraits::get_left(x) : NodeTraits::get_right(x);
+ }
+
+ bool link_left = (y == h) || !comp(y, new_node);
+ link(h, new_node, y, link_left);
+ return new_node;
+ }
+
+ //! <b>Requires</b>: "cloner" must be a function
+ //! object taking a node_ptr and returning a new cloned node of it. "disposer" must
+ //! take a node_ptr and shouldn't throw.
+ //!
+ //! <b>Effects</b>: First empties target tree calling
+ //! <tt>void disposer::operator()(node_ptr)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! Then, duplicates the entire tree pointed by "source_header" cloning each
+ //! source node with <tt>node_ptr Cloner::operator()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ {
+ if(!unique(target_header)){
+ clear_and_dispose(target_header, disposer);
+ }
+
+ node_ptr leftmost, rightmost;
+ node_ptr new_root = clone_subtree
+ (source_header, target_header, cloner, disposer, leftmost, rightmost);
+
+ //Now update header node
+ NodeTraits::set_parent(target_header, new_root);
+ NodeTraits::set_left (target_header, leftmost);
+ NodeTraits::set_right (target_header, rightmost);
+ }
+
+ template <class Cloner, class Disposer>
+ static node_ptr clone_subtree
+ ( const_node_ptr source_parent, node_ptr target_parent
+ , Cloner cloner, Disposer disposer
+ , node_ptr &leftmost_out, node_ptr &rightmost_out
+ )
+ {
+ node_ptr target_sub_root = target_parent;
+ node_ptr source_root = NodeTraits::get_parent(source_parent);
+ if(!source_root){
+ leftmost_out = rightmost_out = source_root;
+ }
+ else{
+ //We'll calculate leftmost and rightmost nodes while iterating
+ node_ptr current = source_root;
+ node_ptr insertion_point = target_sub_root = cloner(current);
+
+ //We'll calculate leftmost and rightmost nodes while iterating
+ node_ptr leftmost = target_sub_root;
+ node_ptr rightmost = target_sub_root;
+
+ //First set the subroot
+ NodeTraits::set_left(target_sub_root, 0);
+ NodeTraits::set_right(target_sub_root, 0);
+ NodeTraits::set_parent(target_sub_root, target_parent);
+
+ try {
+ while(true) {
+ //First clone left nodes
+ if( NodeTraits::get_left(current) &&
+ !NodeTraits::get_left(insertion_point)) {
+ current = NodeTraits::get_left(current);
+ node_ptr temp = insertion_point;
+ //Clone and mark as leaf
+ insertion_point = cloner(current);
+ NodeTraits::set_left (insertion_point, 0);
+ NodeTraits::set_right (insertion_point, 0);
+ //Insert left
+ NodeTraits::set_parent(insertion_point, temp);
+ NodeTraits::set_left (temp, insertion_point);
+ //Update leftmost
+ if(rightmost == target_sub_root)
+ leftmost = insertion_point;
+ }
+ //Then clone right nodes
+ else if( NodeTraits::get_right(current) &&
+ !NodeTraits::get_right(insertion_point)){
+ current = NodeTraits::get_right(current);
+ node_ptr temp = insertion_point;
+ //Clone and mark as leaf
+ insertion_point = cloner(current);
+ NodeTraits::set_left (insertion_point, 0);
+ NodeTraits::set_right (insertion_point, 0);
+ //Insert right
+ NodeTraits::set_parent(insertion_point, temp);
+ NodeTraits::set_right (temp, insertion_point);
+ //Update rightmost
+ rightmost = insertion_point;
+ }
+ //If not, go up
+ else if(current == source_root){
+ break;
+ }
+ else{
+ //Branch completed, go up searching more nodes to clone
+ current = NodeTraits::get_parent(current);
+ insertion_point = NodeTraits::get_parent(insertion_point);
+ }
+ }
+ }
+ catch(...) {
+ dispose_subtree(target_sub_root, disposer);
+ throw;
+ }
+ leftmost_out = leftmost;
+ rightmost_out = rightmost;
+ }
+ return target_sub_root;
+ }
+
+ template<class Disposer>
+ static void dispose_subtree(node_ptr x, Disposer disposer)
+ {
+ node_ptr save;
+ while (x){
+ save = NodeTraits::get_left(x);
+ if (save) {
+ // Right rotation
+ NodeTraits::set_left(x, NodeTraits::get_right(save));
+ NodeTraits::set_right(save, x);
+ }
+ else {
+ save = NodeTraits::get_right(x);
+ init(x);
+ disposer(x);
+ }
+ x = save;
+ }
+ }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a left child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_left_child(node_ptr p)
+ { return NodeTraits::get_left(NodeTraits::get_parent(p)) == p; }
+
+ //! <b>Requires</b>: p is a node of a tree.
+ //!
+ //! <b>Effects</b>: Returns true if p is a right child.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool is_right_child (node_ptr p)
+ { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; }
+
+ static void replace_own (node_ptr own, node_ptr x, node_ptr header)
+ {
+ if(NodeTraits::get_parent(header) == own)
+ NodeTraits::set_parent(header, x);
+ else if(is_left_child(own))
+ NodeTraits::set_left(NodeTraits::get_parent(own), x);
+ else
+ NodeTraits::set_right(NodeTraits::get_parent(own), x);
+ }
+
+ static void rotate_left(node_ptr p, node_ptr header)
+ {
+ node_ptr x = NodeTraits::get_right(p);
+ NodeTraits::set_right(p, NodeTraits::get_left(x));
+ if(NodeTraits::get_left(x) != 0)
+ NodeTraits::set_parent(NodeTraits::get_left(x), p);
+ NodeTraits::set_parent(x, NodeTraits::get_parent(p));
+ replace_own (p, x, header);
+ NodeTraits::set_left(x, p);
+ NodeTraits::set_parent(p, x);
+ }
+
+ static void rotate_right(node_ptr p, node_ptr header)
+ {
+ node_ptr x(NodeTraits::get_left(p));
+ node_ptr x_right(NodeTraits::get_right(x));
+ NodeTraits::set_left(p, x_right);
+ if(x_right)
+ NodeTraits::set_parent(x_right, p);
+ NodeTraits::set_parent(x, NodeTraits::get_parent(p));
+ replace_own (p, x, header);
+ NodeTraits::set_right(x, p);
+ NodeTraits::set_parent(p, x);
+ }
+
+ // rotate node t with left child | complexity : constant | exception : nothrow
+ static node_ptr rotate_left(node_ptr t)
+ {
+ node_ptr x = NodeTraits::get_right(t);
+ NodeTraits::set_right(t, NodeTraits::get_left(x));
+
+ if( NodeTraits::get_right(t) != 0 ){
+ NodeTraits::set_parent(NodeTraits::get_right(t), t );
+ }
+ NodeTraits::set_left(x, t);
+ NodeTraits::set_parent(t, x);
+ return x;
+ }
+
+ // rotate node t with right child | complexity : constant | exception : nothrow
+ static node_ptr rotate_right(node_ptr t)
+ {
+ node_ptr x = NodeTraits::get_left(t);
+ NodeTraits::set_left(t, NodeTraits::get_right(x));
+ if( NodeTraits::get_left(t) != 0 ){
+ NodeTraits::set_parent(NodeTraits::get_left(t), t);
+ }
+ NodeTraits::set_right(x, t);
+ NodeTraits::set_parent(t, x);
+ return x;
+ }
+
+ static void link(node_ptr header, node_ptr z, node_ptr par, bool left)
+ {
+ if(par == header){
+ NodeTraits::set_parent(header, z);
+ NodeTraits::set_right(header, z);
+ NodeTraits::set_left(header, z);
+ }
+ else if(left){
+ NodeTraits::set_left(par, z);
+ if(par == NodeTraits::get_left(header))
+ NodeTraits::set_left(header, z);
+ }
+ else{
+ NodeTraits::set_right(par, z);
+ if(par == NodeTraits::get_right(header))
+ NodeTraits::set_right(header, z);
+ }
+ NodeTraits::set_parent(z, par);
+ NodeTraits::set_right(z, 0);
+ NodeTraits::set_left(z, 0);
+ }
+
+ // delete node | complexity : constant | exception : nothrow
+ static void erase(node_ptr header, node_ptr z)
+ { erase(header, z, nop_erase_fixup()); }
+
+ struct data_for_rebalance
+ {
+ node_ptr x;
+ node_ptr x_parent;
+ };
+
+ template<class F>
+ static void erase(node_ptr header, node_ptr z, F z_and_successor_fixup, data_for_rebalance * info = 0)
+ {
+ node_ptr y(z);
+ node_ptr x;
+ node_ptr x_parent(0);
+ node_ptr z_left(NodeTraits::get_left(z));
+ node_ptr z_right(NodeTraits::get_right(z));
+ if(!z_left){
+ x = z_right; // x might be null.
+ }
+ else if(!z_right){ // z has exactly one non-null child. y == z.
+ x = z_left; // x is not null.
+ }
+ else{
+ // find z's successor
+ y = tree_algorithms::minimum (z_right);
+ x = NodeTraits::get_right(y); // x might be null.
+ }
+
+ if(y != z){
+ // relink y in place of z. y is z's successor
+ NodeTraits::set_parent(NodeTraits::get_left(z), y);
+ NodeTraits::set_left(y, NodeTraits::get_left(z));
+ if(y != NodeTraits::get_right(z)){
+ x_parent = NodeTraits::get_parent(y);
+ if(x)
+ NodeTraits::set_parent(x, x_parent);
+ NodeTraits::set_left(x_parent, x); // y must be a child of left_
+ NodeTraits::set_right(y, NodeTraits::get_right(z));
+ NodeTraits::set_parent(NodeTraits::get_right(z), y);
+ }
+ else
+ x_parent = y;
+ tree_algorithms::replace_own (z, y, header);
+ NodeTraits::set_parent(y, NodeTraits::get_parent(z));
+ z_and_successor_fixup(z, y);
+ }
+ else { // y == z --> z has only one child, or none
+ x_parent = NodeTraits::get_parent(z);
+ if(x)
+ NodeTraits::set_parent(x, x_parent);
+ tree_algorithms::replace_own (z, x, header);
+ if(NodeTraits::get_left(header) == z){
+ NodeTraits::set_left(header, NodeTraits::get_right(z) == 0 ? // z->get_left() must be null also
+ NodeTraits::get_parent(z) : // makes leftmost == header if z == root
+ tree_algorithms::minimum (x));
+ }
+ if(NodeTraits::get_right(header) == z){
+ NodeTraits::set_right(header, NodeTraits::get_left(z) == 0 ? // z->get_right() must be null also
+ NodeTraits::get_parent(z) : // makes rightmost == header if z == root
+ tree_algorithms::maximum(x));
+ }
+ }
+
+ if(info){
+ info->x = x;
+ info->x_parent = x_parent;
+ }
+ }
+
+ 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);
+ }
+ }
+};
+
+} //namespace detail {
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_TREE_ALGORITHMS_HPP

Added: trunk/boost/intrusive/detail/tree_node.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/intrusive/detail/tree_node.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -0,0 +1,192 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTRUSIVE_TREE_NODE_HPP
+#define BOOST_INTRUSIVE_TREE_NODE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <iterator>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/detail/mpl.hpp>
+
+namespace boost {
+namespace intrusive {
+
+template<class VoidPointer>
+struct tree_node
+{
+ typedef typename pointer_to_other
+ <VoidPointer
+ ,tree_node<VoidPointer> >::type node_ptr;
+
+ node_ptr parent_, left_, right_;
+};
+
+template<class VoidPointer>
+struct tree_node_traits
+{
+ typedef tree_node<VoidPointer> node;
+
+ typedef typename boost::pointer_to_other
+ <VoidPointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <VoidPointer, const node>::type const_node_ptr;
+
+ static node_ptr get_parent(const_node_ptr n)
+ { return n->parent_; }
+
+ static void set_parent(node_ptr n, node_ptr p)
+ { n->parent_ = p; }
+
+ static node_ptr get_left(const_node_ptr n)
+ { return n->left_; }
+
+ static void set_left(node_ptr n, node_ptr l)
+ { n->left_ = l; }
+
+ static node_ptr get_right(const_node_ptr n)
+ { return n->right_; }
+
+ static void set_right(node_ptr n, node_ptr r)
+ { n->right_ = r; }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// //
+// Implementation of the tree iterator //
+// //
+/////////////////////////////////////////////////////////////////////////////
+
+// tree_iterator provides some basic functions for a
+// node oriented bidirectional iterator:
+template<class Container, bool IsConst>
+class tree_iterator
+ : public std::iterator
+ < std::bidirectional_iterator_tag
+ , typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>::type
+ >
+{
+ protected:
+ typedef typename Container::real_value_traits real_value_traits;
+ typedef typename Container::node_algorithms node_algorithms;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename node_traits::node_ptr node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, void>::type void_pointer;
+ static const bool store_container_ptr =
+ detail::store_cont_ptr_on_it<Container>::value;
+
+ public:
+ public:
+ typedef typename detail::add_const_if_c
+ <typename Container::value_type, IsConst>
+ ::type value_type;
+ typedef value_type & reference;
+ typedef value_type * pointer;
+
+ tree_iterator()
+ : members_ (0, 0)
+ {}
+
+ explicit tree_iterator(node_ptr node, const Container *cont_ptr)
+ : members_ (node, cont_ptr)
+ {}
+
+ tree_iterator(tree_iterator<Container, false> const& other)
+ : members_(other.pointed_node(), other.get_container())
+ {}
+
+ const node_ptr &pointed_node() const
+ { return members_.nodeptr_; }
+
+ tree_iterator &operator=(const node_ptr &node)
+ { members_.nodeptr_ = node; return static_cast<tree_iterator&>(*this); }
+
+ public:
+ tree_iterator& operator++()
+ {
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator++(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::next_node(members_.nodeptr_);
+ return result;
+ }
+
+ tree_iterator& operator--()
+ {
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return static_cast<tree_iterator&> (*this);
+ }
+
+ tree_iterator operator--(int)
+ {
+ tree_iterator result (*this);
+ members_.nodeptr_ = node_algorithms::prev_node(members_.nodeptr_);
+ return result;
+ }
+
+ bool operator== (const tree_iterator& i) const
+ { return members_.nodeptr_ == i.pointed_node(); }
+
+ bool operator!= (const tree_iterator& i) const
+ { return !operator== (i); }
+
+ value_type& operator*() const
+ { return *operator->(); }
+
+ pointer operator->() const
+ { return detail::get_pointer(this->get_real_value_traits()->to_value_ptr(members_.nodeptr_)); }
+
+ const Container *get_container() const
+ {
+ if(store_container_ptr)
+ return static_cast<const Container*>(members_.get_ptr());
+ else
+ return 0;
+ }
+
+ const real_value_traits *get_real_value_traits() const
+ {
+ if(store_container_ptr)
+ return &this->get_container()->get_real_value_traits();
+ else
+ return 0;
+ }
+
+ 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

Modified: trunk/boost/intrusive/detail/utilities.hpp
==============================================================================
--- trunk/boost/intrusive/detail/utilities.hpp (original)
+++ trunk/boost/intrusive/detail/utilities.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -42,13 +42,13 @@
    template <class U> static one test(...);
    template <class U> static two_or_three<U::boost_intrusive_tags::is_base_hook>
       test (detail::bool_<U::boost_intrusive_tags::is_base_hook>* = 0);
- static const int value = sizeof(test<T>(0));
+ static const std::size_t value = sizeof(test<T>(0));
 };
 
 template <class T>
 struct internal_base_hook_bool_is_true
 {
- static const bool value = internal_base_hook_bool<T>::value == 3;
+ static const bool value = internal_base_hook_bool<T>::value > sizeof(one)*2;
 };
 
 template <class T>
@@ -59,7 +59,7 @@
    template <class U> static one test(...);
    template <class U> static two_or_three<U::external_value_traits>
       test (detail::bool_<U::external_value_traits>* = 0);
- static const int value = sizeof(test<T>(0));
+ static const std::size_t value = sizeof(test<T>(0));
 };
 
 template <class T>
@@ -70,13 +70,13 @@
    template <class U> static one test(...);
    template <class U> static two_or_three<U::external_bucket_traits>
       test (detail::bool_<U::external_bucket_traits>* = 0);
- static const int value = sizeof(test<T>(0));
+ static const std::size_t value = sizeof(test<T>(0));
 };
 
 template <class T>
 struct external_value_traits_is_true
 {
- static const bool value = external_value_traits_bool<T>::value == 3;
+ static const bool value = external_value_traits_bool<T>::value > sizeof(one)*2;
 };
 
 template<class Node, class Tag, link_mode_type LinkMode, int>

Modified: trunk/boost/intrusive/intrusive_fwd.hpp
==============================================================================
--- trunk/boost/intrusive/intrusive_fwd.hpp (original)
+++ trunk/boost/intrusive/intrusive_fwd.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -141,6 +141,7 @@
    < class O1 = none
    , class O2 = none
    , class O3 = none
+ , class O4 = none
>
 class set_base_hook;
 
@@ -148,9 +149,52 @@
    < class O1 = none
    , class O2 = none
    , class O3 = none
+ , class O4 = none
>
 class set_member_hook;
 
+//splaytree/splay_set/splay_multiset
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+class splaytree;
+
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+class splay_set;
+
+template
+ < class T
+ , class O1 = none
+ , class O2 = none
+ , class O3 = none
+ , class O4 = none
+ >
+class splay_multiset;
+
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+class splay_set_base_hook;
+
+template
+ < class O1 = none
+ , class O2 = none
+ , class O3 = none
+ >
+class splay_set_member_hook;
+
 //hash/unordered
 //rbtree/set/multiset
 template

Modified: trunk/boost/intrusive/options.hpp
==============================================================================
--- trunk/boost/intrusive/options.hpp (original)
+++ trunk/boost/intrusive/options.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -282,14 +282,14 @@
 //!the tag of a base hook. A type can not 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 BaseTag>
+template<class Tag>
 struct tag
 {
 /// @cond
    template<class Base>
    struct pack : Base
    {
- typedef BaseTag tag;
+ typedef Tag tag;
    };
 /// @endcond
 };
@@ -310,6 +310,22 @@
 /// @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<bool Enabled>
+struct optimize_size
+{
+/// @cond
+ template<class Base>
+ struct pack : Base
+ {
+ static const bool optimize_size = 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
@@ -416,6 +432,7 @@
       , void_pointer<void*>
       , link_mode<safe_link>
       , tag<default_tag>
+ , optimize_size<false>
>::type
 {};
 

Modified: trunk/boost/intrusive/pointer_plus_bit.hpp
==============================================================================
--- trunk/boost/intrusive/pointer_plus_bit.hpp (original)
+++ trunk/boost/intrusive/pointer_plus_bit.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -44,7 +44,10 @@
 //!has_pointer_plus_bit<>::value is non-zero can make use of these
 //!operations to embed the bit in the pointer.
 template<class Pointer>
-struct pointer_plus_bit;
+struct pointer_plus_bit
+{
+ static const bool value = false;
+};
 
 //!This is the specialization to embed an extra bit of information
 //!in a raw pointer. The extra bit is stored in the lower bit of the pointer.

Modified: trunk/boost/intrusive/rbtree.hpp
==============================================================================
--- trunk/boost/intrusive/rbtree.hpp (original)
+++ trunk/boost/intrusive/rbtree.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -13,22 +13,23 @@
 #define BOOST_INTRUSIVE_RBTREE_HPP
 
 #include <boost/intrusive/detail/config_begin.hpp>
+#include <algorithm>
+#include <cstddef>
 #include <functional>
 #include <iterator>
 #include <utility>
+
 #include <boost/intrusive/detail/assert.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/intrusive/intrusive_fwd.hpp>
-#include <boost/intrusive/detail/pointer_to_other.hpp>
 #include <boost/intrusive/set_hook.hpp>
 #include <boost/intrusive/detail/rbtree_node.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
 #include <boost/intrusive/options.hpp>
 #include <boost/intrusive/rbtree_algorithms.hpp>
 #include <boost/intrusive/link_mode.hpp>
-#include <cstddef>
-#include <iterator>
-#include <algorithm>
 
 namespace boost {
 namespace intrusive {
@@ -78,7 +79,7 @@
 /// @endcond
 
 //! The class template rbtree is an intrusive red-black tree container, that
-//! is used to construct intrusive set and tree containers. The no-throw
+//! is used to construct intrusive set and multiset containers. The no-throw
 //! guarantee holds only, if the value_compare object
 //! doesn't throw.
 //!
@@ -118,11 +119,11 @@
    typedef typename Config::size_type size_type;
    typedef typename Config::compare value_compare;
    typedef value_compare key_compare;
- typedef rbtree_iterator<rbtree_impl, false> iterator;
- typedef rbtree_iterator<rbtree_impl, true> const_iterator;
+ typedef tree_iterator<rbtree_impl, false> iterator;
+ typedef tree_iterator<rbtree_impl, true> const_iterator;
    typedef std::reverse_iterator<iterator> reverse_iterator;
    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
- typedef typename real_value_traits::node_traits node_traits;
+ typedef typename real_value_traits::node_traits node_traits;
    typedef typename node_traits::node node;
    typedef typename boost::pointer_to_other
       <pointer, node>::type node_ptr;
@@ -235,7 +236,7 @@
    //! [b, e).
    //!
    //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
- //! comp and otherwise N * log N, where N is last ­ first.
+ //! comp and otherwise N * log N, where N is the distance between first and last.
    //!
    //! <b>Throws</b>: Nothing unless the copy constructor of the value_compare object throws.
    template<class Iterator>
@@ -411,8 +412,12 @@
    {
       if(constant_time_size)
          return this->priv_size_traits().get_size();
- else
- return empty() ? 0 : node_algorithms::count(node_traits::get_parent(const_node_ptr(&priv_header())));
+ else{
+ const_iterator beg(this->cbegin()), end(this->cend());
+ size_type i = 0;
+ for(;beg != end; ++beg) ++i;
+ return i;
+ }
    }
 
    //! <b>Effects</b>: Swaps the contents of two multisets.
@@ -445,7 +450,7 @@
    //!
    //! <b>Note</b>: Does not affect the validity of iterators and references.
    //! No copy-constructors are called.
- iterator insert_equal_upper_bound(reference value)
+ iterator insert_equal(reference value)
    {
       detail::key_nodeptr_comp<value_compare, rbtree_impl>
          key_node_comp(priv_comp(), this);
@@ -457,29 +462,6 @@
          (node_ptr(&priv_header()), to_insert, key_node_comp), this);
    }
 
- //! <b>Requires</b>: value must be an lvalue
- //!
- //! <b>Effects</b>: Inserts value into the tree before the lower bound.
- //!
- //! <b>Complexity</b>: Average complexity for insert element is at
- //! most logarithmic.
- //!
- //! <b>Throws</b>: Nothing.
- //!
- //! <b>Note</b>: Does not affect the validity of iterators and references.
- //! No copy-constructors are called.
- iterator insert_equal_lower_bound(reference value)
- {
- detail::key_nodeptr_comp<value_compare, rbtree_impl>
- key_node_comp(priv_comp(), this);
- node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
- if(safemode_or_autounlink)
- BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
- this->priv_size_traits().increment();
- return iterator(node_algorithms::insert_equal_lower_bound
- (node_ptr(&priv_header()), to_insert, key_node_comp), this);
- }
-
    //! <b>Requires</b>: value must be an lvalue, and "hint" must be
    //! a valid iterator.
    //!
@@ -523,15 +505,9 @@
    template<class Iterator>
    void insert_equal(Iterator b, Iterator e)
    {
- if(this->empty()){
- iterator end(this->end());
- for (; b != e; ++b)
- this->insert_equal(end, *b);
- }
- else{
- for (; b != e; ++b)
- this->insert_equal_upper_bound(*b);
- }
+ iterator end(this->end());
+ for (; b != e; ++b)
+ this->insert_equal(end, *b);
    }
 
    //! <b>Requires</b>: value must be an lvalue
@@ -1059,6 +1035,19 @@
       return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this));
    }
 
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws.
    template <class Cloner, class Disposer>
    void clone_from(const rbtree_impl &src, Cloner cloner, Disposer disposer)
    {
@@ -1073,6 +1062,16 @@
       }
    }
 
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
    pointer unlink_leftmost_without_rebalance()
    {
       node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
@@ -1132,7 +1131,7 @@
    //!
    //! <b>Complexity</b>: Constant.
    //!
- //! <b>Throws</b>: Nothing.ç
+ //! <b>Throws</b>: Nothing.
    //!
    //! <b>Note</b>: This static function is available only if the <i>value traits</i>
    //! is stateless.
@@ -1266,14 +1265,14 @@
 {
    typedef rbtree_impl<Config> tree_type;
    typedef typename tree_type::const_iterator const_iterator;
- const bool CS = tree_type::constant_time_size;
- if(CS && x.size() != y.size()){
+
+ if(tree_type::constant_time_size && x.size() != y.size()){
       return false;
    }
    const_iterator end1 = x.end();
    const_iterator i1 = x.begin();
    const_iterator i2 = y.begin();
- if(CS){
+ if(tree_type::constant_time_size){
       while (i1 != end1 && *i1 == *i2) {
          ++i1;
          ++i2;

Modified: trunk/boost/intrusive/rbtree_algorithms.hpp
==============================================================================
--- trunk/boost/intrusive/rbtree_algorithms.hpp (original)
+++ trunk/boost/intrusive/rbtree_algorithms.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -49,11 +49,14 @@
 #define BOOST_INTRUSIVE_RBTREE_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/intrusive_fwd.hpp>
+
+#include <boost/intrusive/detail/assert.hpp>
 #include <boost/intrusive/detail/no_exceptions_support.hpp>
 #include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/tree_algorithms.hpp>
 
 
 namespace boost {
@@ -112,11 +115,6 @@
 template<class NodeTraits>
 class rbtree_algorithms
 {
- /// @cond
- private:
- typedef typename NodeTraits::node node;
- /// @endcond
-
    public:
    typedef NodeTraits node_traits;
    typedef typename NodeTraits::node_ptr node_ptr;
@@ -125,45 +123,55 @@
 
    /// @cond
    private:
- static node_ptr uncast(const_node_ptr ptr)
+
+ typedef typename NodeTraits::node node;
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+
+ template<class F>
+ struct rbtree_node_cloner
+ : private detail::ebo_functor_holder<F>
    {
- return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
- }
+ typedef detail::ebo_functor_holder<F> base_t;
 
- static void swap_left(node_ptr this_node, node_ptr other_node)
- {
- node_ptr temp(NodeTraits::get_left(this_node));
- NodeTraits::set_left(this_node, NodeTraits::get_left(other_node));
- NodeTraits::set_left(other_node, temp);
- }
+ 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;
+ }
+ };
 
- static void swap_right(node_ptr this_node, node_ptr other_node)
- {
- node_ptr temp(NodeTraits::get_right(this_node));
- NodeTraits::set_right(this_node, NodeTraits::get_right(other_node));
- NodeTraits::set_right(other_node, temp);
- }
+ 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 void swap_parent(node_ptr this_node, node_ptr other_node)
- {
- node_ptr temp(NodeTraits::get_parent(this_node));
- NodeTraits::set_parent(this_node, NodeTraits::get_parent(other_node));
- NodeTraits::set_parent(other_node, temp);
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
    }
    /// @endcond
 
    public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
 
- //! This type is the information that will be filled by insert_unique_check
- struct insert_commit_data
- {
- insert_commit_data()
- : link_left(false)
- , node(0)
- {}
- bool link_left;
- node_ptr node;
- };
+ 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.
@@ -175,62 +183,7 @@
    //!
    //! <b>Throws</b>: Nothing.
    static void swap_tree(node_ptr header1, node_ptr header2)
- {/*
- if(NodeTraits::get_parent(header1)){
- NodeTraits::node n1;
- node_ptr n2(NodeTraits::get_parent(header1));
- init(&n1);
- swap_nodes(&n1, n2);
- swap_nodes(&n1, n2);
- }*/
- if(header1 == header2)
- return;
-
- node_ptr tmp;
-
- //Parent swap
- tmp = NodeTraits::get_parent(header1);
- NodeTraits::set_parent(header1, NodeTraits::get_parent(header2));
- NodeTraits::set_parent(header2, tmp);
- //Left swap
- tmp = NodeTraits::get_left(header1);
- NodeTraits::set_left(header1, NodeTraits::get_left(header2));
- NodeTraits::set_left(header2, tmp);
- //Right swap
- tmp = NodeTraits::get_right(header1);
- NodeTraits::set_right(header1, NodeTraits::get_right(header2));
- NodeTraits::set_right(header2, tmp);
-
- //Now test parent
- node_ptr h1_parent(NodeTraits::get_parent(header1));
- if(h1_parent){
- NodeTraits::set_parent(h1_parent, header1);
- }
- else{
- NodeTraits::set_left(header1, header1);
- NodeTraits::set_right(header1, header1);
- }
-
- node_ptr h2_parent(NodeTraits::get_parent(header2));
- if(NodeTraits::get_parent(header2)){
- NodeTraits::set_parent(h2_parent, header2);
- }
- else{
- NodeTraits::set_left(header2, header2);
- NodeTraits::set_right(header2, header2);
- }
- }
-
- static node_ptr get_header(const_node_ptr node)
- {
- node_ptr h = uncast(node);
- if(NodeTraits::get_parent(node)){
- h = NodeTraits::get_parent(node);
- while(!is_header(h))
- h = NodeTraits::get_parent(h);
- }
- return h;
- }
+ { return tree_algorithms::swap_tree(header1, header2); }
 
    //! <b>Requires</b>: node1 and node2 can't be header nodes
    //! of two trees.
@@ -252,7 +205,7 @@
       if(node1 == node2)
          return;
    
- node_ptr header1(get_header(node1)), header2(get_header(node2));
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2));
       swap_nodes(node1, header1, node2, header2);
    }
 
@@ -273,139 +226,13 @@
    //!Experimental function
    static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
    {
- if(node1 == node2)
- return;
-
- //node1 and node2 must not be header nodes
- //BOOST_INTRUSIVE_INVARIANT_ASSERT((header1 != node1 && header2 != node2));
- if(header1 != header2){
- //Update header1 if necessary
- if(node1 == NodeTraits::get_left(header1)){
- NodeTraits::set_left(header1, node2);
- }
-
- if(node1 == NodeTraits::get_right(header1)){
- NodeTraits::set_right(header1, node2);
- }
-
- if(node1 == NodeTraits::get_parent(header1)){
- NodeTraits::set_parent(header1, node2);
- }
-
- //Update header2 if necessary
- if(node2 == NodeTraits::get_left(header2)){
- NodeTraits::set_left(header2, node1);
- }
-
- if(node2 == NodeTraits::get_right(header2)){
- NodeTraits::set_right(header2, node1);
- }
+ if(node1 == node2) return;
 
- if(node2 == NodeTraits::get_parent(header2)){
- NodeTraits::set_parent(header2, node1);
- }
- }
- else{
- //If both nodes are from the same tree
- //Update header if necessary
- if(node1 == NodeTraits::get_left(header1)){
- NodeTraits::set_left(header1, node2);
- }
- else if(node2 == NodeTraits::get_left(header2)){
- NodeTraits::set_left(header2, node1);
- }
-
- if(node1 == NodeTraits::get_right(header1)){
- NodeTraits::set_right(header1, node2);
- }
- else if(node2 == NodeTraits::get_right(header2)){
- NodeTraits::set_right(header2, node1);
- }
-
- if(node1 == NodeTraits::get_parent(header1)){
- NodeTraits::set_parent(header1, node2);
- }
- else if(node2 == NodeTraits::get_parent(header2)){
- NodeTraits::set_parent(header2, node1);
- }
-
- //Adjust data in nodes to be swapped
- //so that final link swap works as expected
- if(node1 == NodeTraits::get_parent(node2)){
- NodeTraits::set_parent(node2, node2);
-
- if(node2 == NodeTraits::get_right(node1)){
- NodeTraits::set_right(node1, node1);
- }
- else{
- NodeTraits::set_left(node1, node1);
- }
- }
- else if(node2 == NodeTraits::get_parent(node1)){
- NodeTraits::set_parent(node1, node1);
-
- if(node1 == NodeTraits::get_right(node2)){
- NodeTraits::set_right(node2, node2);
- }
- else{
- NodeTraits::set_left(node2, node2);
- }
- }
- }
-
- //Now swap all the links
- node_ptr temp;
- //swap left link
- temp = NodeTraits::get_left(node1);
- NodeTraits::set_left(node1, NodeTraits::get_left(node2));
- NodeTraits::set_left(node2, temp);
- //swap right link
- temp = NodeTraits::get_right(node1);
- NodeTraits::set_right(node1, NodeTraits::get_right(node2));
- NodeTraits::set_right(node2, temp);
- //swap parent link
- temp = NodeTraits::get_parent(node1);
- NodeTraits::set_parent(node1, NodeTraits::get_parent(node2));
- NodeTraits::set_parent(node2, temp);
+ 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);
-
- //Now adjust adjacent nodes for newly inserted node 1
- if((temp = NodeTraits::get_left(node1))){
- NodeTraits::set_parent(temp, node1);
- }
- if((temp = NodeTraits::get_right(node1))){
- NodeTraits::set_parent(temp, node1);
- }
- if((temp = NodeTraits::get_parent(node1)) &&
- //The header has been already updated so avoid it
- temp != header2){
- if(NodeTraits::get_left(temp) == node2){
- NodeTraits::set_left(temp, node1);
- }
- if(NodeTraits::get_right(temp) == node2){
- NodeTraits::set_right(temp, node1);
- }
- }
- //Now adjust adjacent nodes for newly inserted node 2
- if((temp = NodeTraits::get_left(node2))){
- NodeTraits::set_parent(temp, node2);
- }
- if((temp = NodeTraits::get_right(node2))){
- NodeTraits::set_parent(temp, node2);
- }
- if((temp = NodeTraits::get_parent(node2)) &&
- //The header has been already updated so avoid it
- temp != header1){
- if(NodeTraits::get_left(temp) == node1){
- NodeTraits::set_left(temp, node2);
- }
- if(NodeTraits::get_right(temp) == node1){
- NodeTraits::set_right(temp, node2);
- }
- }
    }
 
    //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
@@ -428,7 +255,7 @@
    {
       if(node_to_be_replaced == new_node)
          return;
- replace_node(node_to_be_replaced, get_header(node_to_be_replaced), new_node);
+ 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
@@ -449,46 +276,8 @@
    //!Experimental function
    static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
    {
- if(node_to_be_replaced == new_node)
- return;
-
- //Update header if necessary
- if(node_to_be_replaced == NodeTraits::get_left(header)){
- NodeTraits::set_left(header, new_node);
- }
-
- if(node_to_be_replaced == NodeTraits::get_right(header)){
- NodeTraits::set_right(header, new_node);
- }
-
- if(node_to_be_replaced == NodeTraits::get_parent(header)){
- NodeTraits::set_parent(header, new_node);
- }
-
- //Now set data from the original node
- node_ptr temp;
- NodeTraits::set_left(new_node, NodeTraits::get_left(node_to_be_replaced));
- NodeTraits::set_right(new_node, NodeTraits::get_right(node_to_be_replaced));
- NodeTraits::set_parent(new_node, NodeTraits::get_parent(node_to_be_replaced));
+ tree_algorithms::replace_node(node_to_be_replaced, header, new_node);
       NodeTraits::set_color(new_node, NodeTraits::get_color(node_to_be_replaced));
-
- //Now adjust adjacent nodes for newly inserted node
- if((temp = NodeTraits::get_left(new_node))){
- NodeTraits::set_parent(temp, new_node);
- }
- if((temp = NodeTraits::get_right(new_node))){
- NodeTraits::set_parent(temp, new_node);
- }
- if((temp = NodeTraits::get_parent(new_node)) &&
- //The header has been already updated so avoid it
- temp != header){
- if(NodeTraits::get_left(temp) == node_to_be_replaced){
- NodeTraits::set_left(temp, new_node);
- }
- if(NodeTraits::get_right(temp) == node_to_be_replaced){
- NodeTraits::set_right(temp, new_node);
- }
- }
    }
 
    //! <b>Requires</b>: node is a tree node but not the header.
@@ -498,20 +287,16 @@
    //! <b>Complexity</b>: Average complexity is constant time.
    //!
    //! <b>Throws</b>: Nothing.
- static void unlink_and_rebalance(node_ptr node)
+ static void unlink(node_ptr node)
    {
- if(NodeTraits::get_parent(node)){
- node_ptr x = NodeTraits::get_parent(node);
+ node_ptr x = NodeTraits::get_parent(node);
+ if(x){
          while(!is_header(x))
             x = NodeTraits::get_parent(x);
          erase(x, node);
       }
    }
 
- static void unlink(node_ptr node)
- { unlink_and_rebalance(node); }
-
-
    //! <b>Requires</b>: header is the header of a tree.
    //!
    //! <b>Effects</b>: Unlinks the leftmost node from the tree, and
@@ -526,34 +311,7 @@
    //! This function is normally used to achieve a step by step
    //! controlled destruction of the tree.
    static node_ptr unlink_leftmost_without_rebalance(node_ptr header)
- {
- node_ptr leftmost = NodeTraits::get_left(header);
- if (leftmost == header)
- return 0;
- node_ptr leftmost_parent(NodeTraits::get_parent(leftmost));
- node_ptr leftmost_right (NodeTraits::get_right(leftmost));
- bool is_root = leftmost_parent == header;
-
- if (leftmost_right){
- NodeTraits::set_parent(leftmost_right, leftmost_parent);
- NodeTraits::set_left(header, minimum(leftmost_right));
-
- if (is_root)
- NodeTraits::set_parent(header, leftmost_right);
- else
- NodeTraits::set_left(NodeTraits::get_parent(header), leftmost_right);
- }
- else if (is_root){
- NodeTraits::set_parent(header, 0);
- NodeTraits::set_left(header, header);
- NodeTraits::set_right(header, header);
- }
- else{
- NodeTraits::set_left(leftmost_parent, 0);
- NodeTraits::set_left(header, leftmost_parent);
- }
- return leftmost;
- }
+ { return tree_algorithms::unlink_leftmost_without_rebalance(header); }
 
    //! <b>Requires</b>: node is a node of the tree or an node initialized
    //! by init(...).
@@ -564,24 +322,17 @@
    //!
    //! <b>Throws</b>: Nothing.
    static bool unique(const_node_ptr node)
- { return NodeTraits::get_parent(node) == 0; }
+ { 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>: Constant time.
+ //! <b>Complexity</b>: Linear time.
    //!
    //! <b>Throws</b>: Nothing.
    static std::size_t count(const_node_ptr node)
- {
- std::size_t result = 1;
- if(NodeTraits::get_left(node))
- result += count(NodeTraits::get_left(node));
- if(NodeTraits::get_right(node))
- result += count(NodeTraits::get_right(node));
- return result;
- }
+ { return tree_algorithms::count(node); }
 
    //! <b>Requires</b>: p is a node from the tree except the header.
    //!
@@ -591,20 +342,7 @@
    //!
    //! <b>Throws</b>: Nothing.
    static node_ptr next_node(node_ptr p)
- {
- node_ptr p_right(NodeTraits::get_right(p));
- if(p_right){
- return minimum(p_right);
- }
- else {
- node_ptr x = NodeTraits::get_parent(p);
- while(p == NodeTraits::get_right(x)){
- p = x;
- x = NodeTraits::get_parent(x);
- }
- return NodeTraits::get_right(p) != x ? x : uncast(p);
- }
- }
+ { return tree_algorithms::next_node(p); }
 
    //! <b>Requires</b>: p is a node from the tree except the leftmost node.
    //!
@@ -614,22 +352,7 @@
    //!
    //! <b>Throws</b>: Nothing.
    static node_ptr prev_node(node_ptr p)
- {
- if(is_header(p)){
- return NodeTraits::get_right(p); // p is header, return rightmost
- }
- else if(NodeTraits::get_left(p)){
- return maximum(NodeTraits::get_left(p));
- }
- else {
- node_ptr x = NodeTraits::get_parent(p);
- while(p == NodeTraits::get_left(x)){
- p = x;
- x = NodeTraits::get_parent(x);
- }
- return x;
- }
- }
+ { return tree_algorithms::prev_node(p); }
 
    //! <b>Requires</b>: node must not be part of any tree.
    //!
@@ -641,12 +364,7 @@
    //!
    //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
    static void init(node_ptr node)
- {
- NodeTraits::set_parent(node, 0);
- NodeTraits::set_left(node, 0);
- NodeTraits::set_right(node, 0);
- NodeTraits::set_color(node, NodeTraits::black());
- };
+ { tree_algorithms::init(node); }
 
    //! <b>Requires</b>: node must not be part of any tree.
    //!
@@ -660,11 +378,9 @@
    //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
    static void init_header(node_ptr header)
    {
- NodeTraits::set_parent(header, 0);
- NodeTraits::set_left(header, header);
- NodeTraits::set_right(header, 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.
@@ -676,128 +392,16 @@
    //! <b>Throws</b>: Nothing.
    static node_ptr erase(node_ptr header, node_ptr z)
    {
- node_ptr y(z);
- node_ptr x(0);
- node_ptr x_parent(0);
- node_ptr y_left(NodeTraits::get_left(y));
- node_ptr y_right(NodeTraits::get_right(y));
- if(!y_left){
- x = y_right; // x might be null.
- }
- else if(!y_right){ // z has exactly one non-null child. y == z.
- x = y_left; // x is not null.
- }
- else{
- y = minimum (y_right);
- x = NodeTraits::get_right(y); // x might be null.
- }
-
- if(y != z){
- // relink y in place of z. y is z's successor
- NodeTraits::set_parent(NodeTraits::get_left(z), y);
- NodeTraits::set_left(y, NodeTraits::get_left(z));
- if(y != NodeTraits::get_right(z)){
- x_parent = NodeTraits::get_parent(y);
- if(x)
- NodeTraits::set_parent(x, NodeTraits::get_parent(y));
- NodeTraits::set_left(NodeTraits::get_parent(y), x); // y must be a child of left_
- NodeTraits::set_right(y, NodeTraits::get_right(z));
- NodeTraits::set_parent(NodeTraits::get_right(z), y);
- }
- else
- x_parent = y;
- replace_own (z, y, header);
- NodeTraits::set_parent(y, NodeTraits::get_parent(z));
- color tmp(NodeTraits::get_color(y));
- tmp = NodeTraits::get_color(y);
- NodeTraits::set_color(y, NodeTraits::get_color(z));
- NodeTraits::set_color(z, tmp);
-// std::swap(NodeTraits::get_color(y), NodeTraits::get_color(z));
- y = z;
- // y now points to node to be actually deleted
- }
- else { // y == z
- x_parent = NodeTraits::get_parent(y);
- if(x)
- NodeTraits::set_parent(x, NodeTraits::get_parent(y));
- replace_own (z, x, header);
- if(NodeTraits::get_left(header) == z){
- NodeTraits::set_left(header, NodeTraits::get_right(z) == 0 ? // z->get_left() must be null also
- NodeTraits::get_parent(z) : // makes leftmost == header if z == root
- minimum (x));
- }
- if(NodeTraits::get_right(header) == z){
- NodeTraits::set_right(header, NodeTraits::get_left(z) == 0 ? // z->get_right() must be null also
- NodeTraits::get_parent(z) : // makes rightmost == header if z == root
- maximum(x));
- }
+ 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);
       }
- if(NodeTraits::get_color(y) != NodeTraits::red()){
- 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());
- 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());
- 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());
- 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());
- 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());
- 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());
- rotate_right(x_parent, header);
- break;
- }
- }
- }
- if(x)
- NodeTraits::set_color(x, NodeTraits::black());
- }
- return y;
+ return z;
    }
 
    //! <b>Requires</b>: "cloner" must be a function
@@ -821,18 +425,8 @@
    static void clone
       (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
    {
- if(!unique(target_header)){
- clear_and_dispose(target_header, disposer);
- }
-
- node_ptr leftmost, rightmost;
- node_ptr new_root = clone_subtree
- (source_header, target_header, cloner, disposer, leftmost, rightmost);
-
- //Now update header node
- NodeTraits::set_parent(target_header, new_root);
- NodeTraits::set_left (target_header, leftmost);
- NodeTraits::set_right (target_header, rightmost);
+ 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
@@ -848,13 +442,7 @@
    //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
    template<class Disposer>
    static void clear_and_dispose(node_ptr header, Disposer disposer)
- {
- node_ptr source_root = NodeTraits::get_parent(header);
- if(!source_root)
- return;
- dispose_subtree(source_root, disposer);
- init_header(header);
- }
+ { 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
@@ -871,20 +459,7 @@
    template<class KeyType, class KeyNodePtrCompare>
    static node_ptr lower_bound
       (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
- {
- node_ptr y = uncast(header);
- node_ptr x = NodeTraits::get_parent(header);
- while(x){
- if(comp(x, key)){
- x = NodeTraits::get_right(x);
- }
- else {
- y = x;
- x = NodeTraits::get_left(x);
- }
- }
- return y;
- }
+ { 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
@@ -900,20 +475,7 @@
    template<class KeyType, class KeyNodePtrCompare>
    static node_ptr upper_bound
       (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
- {
- node_ptr y = uncast(header);
- node_ptr x = NodeTraits::get_parent(header);
- while(x){
- if(comp(key, x)){
- y = x;
- x = NodeTraits::get_left(x);
- }
- else {
- x = NodeTraits::get_right(x);
- }
- }
- return y;
- }
+ { 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
@@ -929,11 +491,7 @@
    template<class KeyType, class KeyNodePtrCompare>
    static node_ptr find
       (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
- {
- node_ptr end = uncast(header);
- node_ptr y = lower_bound(header, key, comp);
- return (y == end || comp(key, y)) ? end : y;
- }
+ { 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
@@ -951,47 +509,7 @@
    template<class KeyType, class KeyNodePtrCompare>
    static std::pair<node_ptr, node_ptr> equal_range
       (const_node_ptr header, const KeyType &key, KeyNodePtrCompare comp)
- {
- node_ptr y = uncast(header);
- node_ptr x = NodeTraits::get_parent(header);
-
- while(x){
- if(comp(x, key)){
- x = NodeTraits::get_right(x);
- }
- else if(comp(key, x)){
- y = x;
- x = NodeTraits::get_left(x);
- }
- else{
- node_ptr xu(x), yu(y);
- y = x, x = NodeTraits::get_left(x);
- xu = NodeTraits::get_right(xu);
-
- while(x){
- if(comp(x, key)){
- x = NodeTraits::get_right(x);
- }
- else {
- y = x;
- x = NodeTraits::get_left(x);
- }
- }
-
- while(xu){
- if(comp(key, xu)){
- yu = xu;
- xu = NodeTraits::get_left(xu);
- }
- else {
- xu = NodeTraits::get_right(xu);
- }
- }
- return std::pair<node_ptr,node_ptr>(y, yu);
- }
- }
- return std::pair<node_ptr,node_ptr>(y, y);
- }
+ { 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
@@ -1009,29 +527,8 @@
    static node_ptr insert_equal_upper_bound
       (node_ptr h, node_ptr new_node, NodePtrCompare comp)
    {
- node_ptr y(h);
- node_ptr x(NodeTraits::get_parent(y));
-
- while(x){
- y = x;
- x = comp(new_node, x) ?
- NodeTraits::get_left(x) : NodeTraits::get_right(x);
- }
-
- bool link_left = (y == h) ||
- comp(new_node, y);
- link_and_balance(new_node, y, link_left, h);
-/*
- //erase me
- NodeTraits::node n;
- init(&n);
- if(y!=h)
- x = x;
- node_ptr n1(y!=h ? y : &n);
- node_ptr n2(new_node);
- swap_nodes(n2, n1);
- swap_nodes(n2, n1);
-*/
+ tree_algorithms::insert_equal_upper_bound(h, new_node, comp);
+ rebalance_after_insertion(h, new_node);
       return new_node;
    }
 
@@ -1051,29 +548,8 @@
    static node_ptr insert_equal_lower_bound
       (node_ptr h, node_ptr new_node, NodePtrCompare comp)
    {
- node_ptr y(h);
- node_ptr x(NodeTraits::get_parent(y));
-
- while(x){
- y = x;
- x = !comp(x, new_node) ?
- NodeTraits::get_left(x) : NodeTraits::get_right(x);
- }
-
- bool link_left = (y == h) ||
- !comp(y, new_node);
- link_and_balance(new_node, y, link_left, h);
-/*
- //erase me
- NodeTraits::node n;
- init(&n);
- if(y!=h)
- x = x;
- node_ptr n1(y!=h ? y : &n);
- node_ptr n2(new_node);
- swap_nodes(n2, n1);
- swap_nodes(n2, n1);
-*/
+ tree_algorithms::insert_equal_lower_bound(h, new_node, comp);
+ rebalance_after_insertion(h, new_node);
       return new_node;
    }
 
@@ -1095,29 +571,9 @@
    static node_ptr insert_equal
       (node_ptr header, node_ptr hint, node_ptr new_node, NodePtrCompare comp)
    {
- if(hint == header || !comp(hint, new_node)){
- node_ptr prev(hint);
- if(hint == NodeTraits::get_left(header) ||
- !comp(new_node, (prev = prev_node(hint)))){
- bool link_left = unique(header) || !NodeTraits::get_left(hint);
- link_and_balance(new_node, link_left ? hint : prev, link_left, header);
-/*
- //erase me
- NodeTraits::node n1;
- node_ptr n2(new_node);
- init(&n1);
- swap_nodes(n2, &n1);
- swap_nodes(&n1, n2);
-*/
- return new_node;
- }
- else{
- return insert_equal_upper_bound(header, new_node, comp);
- }
- }
- else{
- return insert_equal_lower_bound(header, new_node, 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.
@@ -1158,35 +614,7 @@
    static std::pair<node_ptr, bool> insert_unique_check
       (const_node_ptr header, const KeyType &key
       ,KeyNodePtrCompare comp, insert_commit_data &commit_data)
- {
- node_ptr h(uncast(header));
- node_ptr y(h);
- node_ptr x(NodeTraits::get_parent(y));
- node_ptr prev(0);
-
- //Find the upper bound, cache the previous value and if we should
- //store it in the left or right node
- bool left_child = true;
- while(x){
- y = x;
- x = (left_child = comp(key, x)) ?
- NodeTraits::get_left(x) : (prev = y, NodeTraits::get_right(x));
- }
-
- //Since we've found the upper bound there is no other value with the same key if:
- // - There is no previous node
- // - The previous node is less than the key
- if(!prev || comp(prev, key)){
- commit_data.link_left = left_child;
- commit_data.node = y;
- return std::pair<node_ptr, bool>(node_ptr(), true);
- }
- //If the previous value was not less than key, it means that it's equal
- //(because we've checked the upper bound)
- else{
- return std::pair<node_ptr, bool>(prev, false);
- }
- }
+ { 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
@@ -1231,26 +659,7 @@
    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)
- {
- //hint must be bigger than the key
- if(hint == header || comp(key, hint)){
- node_ptr prev = hint;
- //The previous value should be less than the key
- if(prev == NodeTraits::get_left(header) || comp((prev = prev_node(hint)), key)){
- commit_data.link_left = unique(header) || !NodeTraits::get_left(hint);
- commit_data.node = commit_data.link_left ? hint : prev;
- return std::pair<node_ptr, bool>(node_ptr(), true);
- }
- else{
- return insert_unique_check(header, key, comp, commit_data);
- //return std::pair<node_ptr, bool>(prev, false);
- }
- }
- //The hint was wrong, use hintless insert
- else{
- return insert_unique_check(header, key, comp, 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
@@ -1272,182 +681,12 @@
    static void insert_unique_commit
       (node_ptr header, node_ptr new_value, const insert_commit_data &commit_data)
    {
- //Check if commit_data has not been initialized by a insert_unique_check call.
- BOOST_INTRUSIVE_INVARIANT_ASSERT(commit_data.node != 0);
- link_and_balance(new_value, commit_data.node, commit_data.link_left, header);
+ tree_algorithms::insert_unique_commit(header, new_value, commit_data);
+ rebalance_after_insertion(header, new_value);
    }
 
    /// @cond
-
- template <class Cloner, class Disposer>
- static node_ptr clone_subtree
- ( const_node_ptr source_parent, node_ptr target_parent
- , Cloner cloner, Disposer disposer
- , node_ptr &leftmost_out, node_ptr &rightmost_out
- )
- {
- node_ptr target_sub_root = target_parent;
- node_ptr source_root = NodeTraits::get_parent(source_parent);
- if(!source_root){
- leftmost_out = rightmost_out = source_root;
- }
- else{
- //We'll calculate leftmost and rightmost nodes while iterating
- node_ptr current = source_root;
- node_ptr insertion_point = target_sub_root = cloner(current);
-
- //We'll calculate leftmost and rightmost nodes while iterating
- node_ptr leftmost = target_sub_root;
- node_ptr rightmost = target_sub_root;
-
- //First set the subroot
- NodeTraits::set_left(target_sub_root, 0);
- NodeTraits::set_right(target_sub_root, 0);
- NodeTraits::set_parent(target_sub_root, target_parent);
- NodeTraits::set_color(target_sub_root, NodeTraits::get_color(current));
-
- try {
- while(true) {
- //First clone left nodes
- if( NodeTraits::get_left(current) &&
- !NodeTraits::get_left(insertion_point)) {
- current = NodeTraits::get_left(current);
- node_ptr temp = insertion_point;
- //Clone and mark as leaf
- insertion_point = cloner(current);
- NodeTraits::set_left (insertion_point, 0);
- NodeTraits::set_right (insertion_point, 0);
- NodeTraits::set_color (insertion_point, NodeTraits::get_color(current));
- //Insert left
- NodeTraits::set_parent(insertion_point, temp);
- NodeTraits::set_left (temp, insertion_point);
- //Update leftmost
- if(rightmost == target_sub_root)
- leftmost = insertion_point;
- }
- //Then clone right nodes
- else if( NodeTraits::get_right(current) &&
- !NodeTraits::get_right(insertion_point)){
- current = NodeTraits::get_right(current);
- node_ptr temp = insertion_point;
- //Clone and mark as leaf
- insertion_point = cloner(current);
- NodeTraits::set_left (insertion_point, 0);
- NodeTraits::set_right (insertion_point, 0);
- NodeTraits::set_color (insertion_point, NodeTraits::get_color(current));
- //Insert right
- NodeTraits::set_parent(insertion_point, temp);
- NodeTraits::set_right (temp, insertion_point);
- //Update rightmost
- rightmost = insertion_point;
- }
- //If not, go up
- else if(current == source_root){
- break;
- }
- else{
- //Branch completed, go up searching more nodes to clone
- current = NodeTraits::get_parent(current);
- insertion_point = NodeTraits::get_parent(insertion_point);
- }
- }
- }
- catch(...) {
- dispose_subtree(target_sub_root, disposer);
- throw;
- }
- leftmost_out = leftmost;
- rightmost_out = rightmost;
- }
- return target_sub_root;
- }
-
- template<class Disposer>
- static void dispose_subtree(node_ptr x, Disposer disposer)
- {
- node_ptr save;
- while (x){
- save = NodeTraits::get_left(x);
- if (save) {
- // Right rotation
- NodeTraits::set_left(x, NodeTraits::get_right(save));
- NodeTraits::set_right(save, x);
- }
- else {
- save = NodeTraits::get_right(x);
- init(x);
- disposer(x);
- }
- x = save;
- }
- }
-
- //! <b>Requires</b>: z is the node to be inserted, par is its parent,
- //! left, indicates if z should be a left node of par and header is the header
- //! of the tree.
- //!
- //! <b>Effects</b>: If left is true links z as a left child of par or as a right
- //! child otherwise. After that rebalances the tree.
- //!
- //! <b>Complexity</b>: Average constant time.???
- //!
- //! <b>Throws</b>: Nothing.
- static void link_and_balance (node_ptr z, node_ptr par, bool left, node_ptr header)
- {
- if(par == header){
- NodeTraits::set_parent(header, z);
- NodeTraits::set_right(header, z);
- NodeTraits::set_left(header, z);
- }
- else if(left){
- NodeTraits::set_left(par, z);
- if(par == NodeTraits::get_left(header))
- NodeTraits::set_left(header, z);
- }
- else{
- NodeTraits::set_right(par, z);
- if(par == NodeTraits::get_right(header))
- NodeTraits::set_right(header, z);
- }
- NodeTraits::set_parent(z, par);
- NodeTraits::set_right(z, 0);
- NodeTraits::set_left(z, 0);
- rebalance(z, header);
- }
-
- //! <b>Requires</b>: p is a node of a tree but not the header.
- //!
- //! <b>Effects</b>: Returns the minimum node of the subtree starting at p.
- //!
- //! <b>Complexity</b>: Logarithmic to the size of the subtree.
- //!
- //! <b>Throws</b>: Nothing.
- static node_ptr minimum (node_ptr p)
- {
- for(node_ptr p_left = NodeTraits::get_left(p)
- ;p_left
- ;p_left = NodeTraits::get_left(p)){
- p = p_left;
- }
- return p;
- }
-
- //! <b>Requires</b>: p is a node of a tree but not the header.
- //!
- //! <b>Effects</b>: Returns the maximum node of the subtree starting at p.
- //!
- //! <b>Complexity</b>: Logarithmic to the size of the subtree.
- //!
- //! <b>Throws</b>: Nothing.
- static node_ptr maximum(node_ptr p)
- {
- for(node_ptr p_right = NodeTraits::get_right(p)
- ;p_right
- ;p_right = NodeTraits::get_right(p)){
- p = p_right;
- }
- return p;
- }
+ private:
 
    //! <b>Requires</b>: p is a node of a tree.
    //!
@@ -1458,72 +697,87 @@
    //! <b>Throws</b>: Nothing.
    static bool is_header(const_node_ptr p)
    {
- return NodeTraits::get_color(p) == NodeTraits::red() &&
- NodeTraits::get_parent(NodeTraits::get_parent(p)) == p;
- }
-
- //! <b>Requires</b>: p is a node of a tree.
- //!
- //! <b>Effects</b>: Returns true if p is a left child.
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Throws</b>: Nothing.
- static bool is_left_child(node_ptr p)
- { return NodeTraits::get_left(NodeTraits::get_parent(p)) == p; }
-
- //! <b>Requires</b>: p is a node of a tree.
- //!
- //! <b>Effects</b>: Returns true if p is a right child.
- //!
- //! <b>Complexity</b>: Constant.
- //!
- //! <b>Throws</b>: Nothing.
- static bool is_right_child (node_ptr p)
- { return NodeTraits::get_right(NodeTraits::get_parent(p)) == p; }
-
- static void replace_own (node_ptr own, node_ptr x, node_ptr header)
- {
- if(NodeTraits::get_parent(header) == own)
- NodeTraits::set_parent(header, x);
- else if(is_left_child(own))
- NodeTraits::set_left(NodeTraits::get_parent(own), x);
- else
- NodeTraits::set_right(NodeTraits::get_parent(own), x);
- }
-
- static void rotate_left(node_ptr p, node_ptr header)
- {
- node_ptr x = NodeTraits::get_right(p);
- NodeTraits::set_right(p, NodeTraits::get_left(x));
- if(NodeTraits::get_left(x) != 0)
- NodeTraits::set_parent(NodeTraits::get_left(x), p);
- NodeTraits::set_parent(x, NodeTraits::get_parent(p));
- replace_own (p, x, header);
- NodeTraits::set_left(x, p);
- NodeTraits::set_parent(p, x);
+ 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 rotate_right(node_ptr p, node_ptr header)
- {
- node_ptr x(NodeTraits::get_left(p));
- node_ptr x_right(NodeTraits::get_right(x));
- NodeTraits::set_left(p, x_right);
- if(x_right)
- NodeTraits::set_parent(x_right, p);
- NodeTraits::set_parent(x, NodeTraits::get_parent(p));
- replace_own (p, x, header);
- NodeTraits::set_right(x, p);
- NodeTraits::set_parent(p, x);
- }
 
- static void rebalance(node_ptr p, node_ptr header)
+ 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(is_left_child(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());
@@ -1532,15 +786,15 @@
                p = p_parent_parent;
             }
             else {
- if(!is_left_child(p)){
+ if(!tree_algorithms::is_left_child(p)){
                   p = p_parent;
- rotate_left(p, header);
+ 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());
- rotate_right(new_p_parent_parent, header);
+ tree_algorithms::rotate_right(new_p_parent_parent, header);
             }
          }
          else{
@@ -1552,15 +806,15 @@
                p = p_parent_parent;
             }
             else{
- if(is_left_child(p)){
+ if(tree_algorithms::is_left_child(p)){
                   p = p_parent;
- rotate_right(p, header);
+ 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());
- rotate_left(new_p_parent_parent, header);
+ tree_algorithms::rotate_left(new_p_parent_parent, header);
             }
          }
       }

Modified: trunk/boost/intrusive/set.hpp
==============================================================================
--- trunk/boost/intrusive/set.hpp (original)
+++ trunk/boost/intrusive/set.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -109,7 +109,7 @@
            , const value_compare &cmp = value_compare()
            , const value_traits &v_traits = value_traits())
       : tree_(true, b, e, cmp, v_traits)
- { insert(b, e); }
+ {}
 
    //! <b>Effects</b>: Detaches all elements from this. The objects in the set
    //! are not deleted (i.e. no destructors are called).
@@ -930,6 +930,19 @@
    static void init_node(reference value)
    { tree_type::init_node(value); }
 
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
    //! <b>Requires</b>: replace_this must be a valid iterator of *this
    //! and with_this must not be inserted in any tree.
    //!
@@ -1151,7 +1164,7 @@
    //! [b, e).
    //!
    //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
- //! comp and otherwise N * log N, where N is last ­ first.
+ //! comp and otherwise N * log N, where N is the distance between first and last
    //!
    //! <b>Throws</b>: If value_traits::node_traits::node
    //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
@@ -1379,7 +1392,7 @@
    //! <b>Note</b>: Does not affect the validity of iterators and references.
    //! No copy-constructors are called.
    iterator insert(reference value)
- { return tree_.insert_equal_upper_bound(value); }
+ { return tree_.insert_equal(value); }
 
    //! <b>Requires</b>: value must be an lvalue
    //!
@@ -1889,6 +1902,19 @@
    static void init_node(reference value)
    { tree_type::init_node(value); }
 
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ { return tree_.unlink_leftmost_without_rebalance(); }
+
    //! <b>Requires</b>: replace_this must be a valid iterator of *this
    //! and with_this must not be inserted in any tree.
    //!

Modified: trunk/boost/intrusive/set_hook.hpp
==============================================================================
--- trunk/boost/intrusive/set_hook.hpp (original)
+++ trunk/boost/intrusive/set_hook.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -26,10 +26,10 @@
 namespace intrusive {
 
 /// @cond
-template<class VoidPointer>
+template<class VoidPointer, bool OptimizeSize = false>
 struct get_set_node_algo
 {
- typedef rbtree_algorithms<rbtree_node_traits<VoidPointer> > type;
+ typedef rbtree_algorithms<rbtree_node_traits<VoidPointer, OptimizeSize> > type;
 };
 /// @endcond
 
@@ -38,16 +38,17 @@
 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
 template<class ...Options>
 #else
-template<class O1 = none, class O2 = none, class O3 = none>
+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, O1, O2, O3>::type packed_options;
+ < hook_defaults, O1, O2, O3, O4>::type packed_options;
 
    typedef detail::generic_hook
- < get_set_node_algo<typename packed_options::void_pointer>
+ < get_set_node_algo<typename packed_options::void_pointer
+ ,packed_options::optimize_size>
    , typename packed_options::tag
    , packed_options::link_mode
    , detail::SetBaseHook
@@ -72,10 +73,10 @@
 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
 template<class ...Options>
 #else
-template<class O1, class O2, class O3>
+template<class O1, class O2, class O3, class O4>
 #endif
 class set_base_hook
- : public make_set_base_hook<O1, O2, O3>::type
+ : public make_set_base_hook<O1, O2, O3, O4>::type
 {
    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
    //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
@@ -149,16 +150,17 @@
 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
 template<class ...Options>
 #else
-template<class O1 = none, class O2 = none, class O3 = none>
+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, O1, O2, O3>::type packed_options;
+ < hook_defaults, O1, O2, O3, O4>::type packed_options;
 
    typedef detail::generic_hook
- < get_set_node_algo<typename packed_options::void_pointer>
+ < get_set_node_algo<typename packed_options::void_pointer
+ ,packed_options::optimize_size>
    , member_tag
    , packed_options::link_mode
    , detail::NoBaseHook
@@ -178,10 +180,10 @@
 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
 template<class ...Options>
 #else
-template<class O1, class O2, class O3>
+template<class O1, class O2, class O3, class O4>
 #endif
 class set_member_hook
- : public make_set_member_hook<O1, O2, O3>::type
+ : public make_set_member_hook<O1, O2, O3, O4>::type
 {
    #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
    //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link

Modified: trunk/boost/intrusive/slist.hpp
==============================================================================
--- trunk/boost/intrusive/slist.hpp (original)
+++ trunk/boost/intrusive/slist.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -24,6 +24,7 @@
 #include <boost/intrusive/detail/pointer_to_other.hpp>
 #include <boost/intrusive/link_mode.hpp>
 #include <boost/intrusive/options.hpp>
+#include <iterator>
 #include <functional>
 #include <algorithm>
 #include <cstddef>
@@ -906,7 +907,7 @@
    void dispose_and_assign(Disposer disposer, Iterator b, Iterator e)
    {
       this->clear_and_dispose(disposer);
- this->insert_after(before_begin(), b, e, disposer);
+ this->insert_after(this->before_begin(), b, e, disposer);
    }
 
    //! <b>Requires</b>: prev is an iterator to an element or x.end()/x.before_begin() in x.

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

Added: trunk/boost/intrusive/splay_set_hook.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/intrusive/splay_set_hook.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -0,0 +1,257 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Olaf Krzikalla 2004-2006.
+// (C) Copyright Ion Gaztanaga 2006-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_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.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+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, O1, O2, O3>::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 an set/multiset. splay_set_base_hook holds the data necessary to maintain
+//! the set/multiset and provides an appropriate value_traits class for set/multiset.
+//!
+//! The first integer template argument 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 splay_set_base_hook, then each splay_set_base_hook needs its
+//! unique tag.
+//!
+//! The second boolean template parameter will specify the linking mode of the hook.
+//!
+//! The third argument is the pointer type that will be used internally in the hook
+//! and the set/multiset configured from this hook.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class splay_set_base_hook
+ : public make_splay_set_base_hook<O1, O2, O3>::type
+{
+ #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ splay_set_base_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_base_hook(const splay_set_base_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_base_hook& operator=(const splay_set_base_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an 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.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+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, O1, O2, O3>::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
+//! an set/multiset. splay_set_member_hook holds the data necessary for maintaining the
+//! set/multiset and provides an appropriate value_traits class for set/multiset.
+//!
+//! The first boolean template parameter will specify the linking mode of the hook.
+//!
+//! The second argument is the pointer type that will be used internally in the hook
+//! and the set/multiset configured from this hook.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class ...Options>
+#else
+template<class O1, class O2, class O3>
+#endif
+class splay_set_member_hook
+ : public make_splay_set_member_hook<O1, O2, O3>::type
+{
+ #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ splay_set_member_hook();
+
+ //! <b>Effects</b>: If link_mode is \c auto_unlink or \c safe_link
+ //! initializes the node to an unlinked state. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing a copy-constructor
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_member_hook(const splay_set_member_hook& );
+
+ //! <b>Effects</b>: Empty function. The argument is ignored.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Rationale</b>: Providing an assignment operator
+ //! makes classes using the hook STL-compliant without forcing the
+ //! user to do some additional work. \c swap can be used to emulate
+ //! move-semantics.
+ splay_set_member_hook& operator=(const splay_set_member_hook& );
+
+ //! <b>Effects</b>: If link_mode is \c normal_link, the destructor does
+ //! nothing (ie. no code is generated). If link_mode is \c safe_link and the
+ //! object is stored in an set an assertion is raised. If link_mode is
+ //! \c auto_unlink and \c is_linked() is true, the node is unlinked.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splay_set_member_hook();
+
+ //! <b>Effects</b>: Swapping two nodes swaps the position of the elements
+ //! related to those nodes in one or two containers. That is, if the node
+ //! this is part of the element e1, the node x is part of the element e2
+ //! and both elements are included in the containers s1 and s2, then after
+ //! the swap-operation e1 is in s2 at the position of e2 and e2 is in s1
+ //! at the position of e1. If one element is not in a container, then
+ //! after the swap-operation the other element is not in a container.
+ //! Iterators to e1 and e2 related to those nodes are invalidated.
+ //!
+ //! <b>Complexity</b>: Constant
+ //!
+ //! <b>Throws</b>: Nothing.
+ void swap_nodes(splay_set_member_hook &other);
+
+ //! <b>Precondition</b>: link_mode must be \c safe_link or \c auto_unlink.
+ //!
+ //! <b>Returns</b>: true, if the node belongs to a container, false
+ //! otherwise. This function can be used to test whether \c set::iterator_to
+ //! will return a valid iterator.
+ //!
+ //! <b>Complexity</b>: Constant
+ bool is_linked() const;
+
+ //! <b>Effects</b>: Removes the node if it's inserted in a container.
+ //! This function is only allowed if link_mode is \c auto_unlink.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void unlink();
+ #endif
+};
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAY_SET_HOOK_HPP

Added: trunk/boost/intrusive/splaytree.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/intrusive/splaytree.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -0,0 +1,1501 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (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_SPLAYTREE_HPP
+#define BOOST_INTRUSIVE_SPLAYTREE_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <functional>
+#include <iterator>
+#include <utility>
+#include <cstddef>
+#include <algorithm>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <boost/intrusive/detail/pointer_to_other.hpp>
+#include <boost/intrusive/splay_set_hook.hpp>
+#include <boost/intrusive/detail/tree_node.hpp>
+#include <boost/intrusive/detail/ebo_functor_holder.hpp>
+#include <boost/intrusive/options.hpp>
+#include <boost/intrusive/splaytree_algorithms.hpp>
+#include <boost/intrusive/link_mode.hpp>
+
+
+namespace boost {
+namespace intrusive {
+
+/// @cond
+
+template <class T>
+struct internal_default_splay_set_hook
+{
+ template <class U> static detail::one test(...);
+ template <class U> static detail::two test(typename U::default_splay_set_hook* = 0);
+ static const bool value = sizeof(test<T>(0)) == sizeof(detail::two);
+};
+
+template <class T>
+struct get_default_splay_set_hook
+{
+ typedef typename T::default_splay_set_hook type;
+};
+
+template <class ValueTraits, class Compare, class SizeType, bool ConstantTimeSize>
+struct splaysetopt
+{
+ typedef ValueTraits value_traits;
+ typedef Compare compare;
+ typedef SizeType size_type;
+ static const bool constant_time_size = ConstantTimeSize;
+};
+
+template <class T>
+struct splay_set_defaults
+ : pack_options
+ < none
+ , base_hook
+ < typename detail::eval_if_c
+ < internal_default_splay_set_hook<T>::value
+ , get_default_splay_set_hook<T>
+ , detail::identity<none>
+ >::type
+ >
+ , constant_time_size<true>
+ , size_type<std::size_t>
+ , compare<std::less<T> >
+ >::type
+{};
+
+/// @endcond
+
+//! The class template splaytree is an intrusive splay tree container that
+//! is used to construct intrusive splay_set and splay_multiset containers. The no-throw
+//! guarantee holds only, if the value_compare object
+//! doesn't throw.
+//!
+//! The template parameter \c T is the type to be managed by the container.
+//! The user can specify additional options and if no options are provided
+//! default options are used.
+//!
+//! The container supports the following options:
+//! \c base_hook<>/member_hook<>/value_traits<>,
+//! \c constant_time_size<>, \c size_type<> and
+//! \c compare<>.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+class splaytree_impl
+{
+ public:
+ typedef typename Config::value_traits value_traits;
+ /// @cond
+ static const bool external_value_traits =
+ detail::external_value_traits_is_true<value_traits>::value;
+ typedef typename detail::eval_if_c
+ < external_value_traits
+ , detail::eval_value_traits<value_traits>
+ , detail::identity<value_traits>
+ >::type real_value_traits;
+ /// @endcond
+ typedef typename real_value_traits::pointer pointer;
+ typedef typename real_value_traits::const_pointer const_pointer;
+ typedef typename std::iterator_traits<pointer>::value_type value_type;
+ typedef value_type key_type;
+ typedef typename std::iterator_traits<pointer>::reference reference;
+ typedef typename std::iterator_traits<const_pointer>::reference const_reference;
+ typedef typename std::iterator_traits<pointer>::difference_type difference_type;
+ typedef typename Config::size_type size_type;
+ typedef typename Config::compare value_compare;
+ typedef value_compare key_compare;
+ typedef tree_iterator<splaytree_impl, false> iterator;
+ typedef tree_iterator<splaytree_impl, true> const_iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+ typedef typename real_value_traits::node_traits node_traits;
+ typedef typename node_traits::node node;
+ typedef typename boost::pointer_to_other
+ <pointer, node>::type node_ptr;
+ typedef typename boost::pointer_to_other
+ <node_ptr, const node>::type const_node_ptr;
+ typedef splaytree_algorithms<node_traits> node_algorithms;
+
+ static const bool constant_time_size = Config::constant_time_size;
+ static const bool stateful_value_traits = detail::store_cont_ptr_on_it<splaytree_impl>::value;
+
+ /// @cond
+ private:
+ typedef detail::size_holder<constant_time_size, size_type> size_traits;
+
+ //noncopyable
+ splaytree_impl (const splaytree_impl&);
+ splaytree_impl operator =(const splaytree_impl&);
+
+ enum { safemode_or_autounlink =
+ (int)real_value_traits::link_mode == (int)auto_unlink ||
+ (int)real_value_traits::link_mode == (int)safe_link };
+
+ //Constant-time size is incompatible with auto-unlink hooks!
+ BOOST_STATIC_ASSERT(!(constant_time_size && ((int)real_value_traits::link_mode == (int)auto_unlink)));
+
+ struct header_plus_size : public size_traits
+ { node header_; };
+
+ struct node_plus_pred_t : public detail::ebo_functor_holder<value_compare>
+ {
+ node_plus_pred_t(const value_compare &comp)
+ : detail::ebo_functor_holder<value_compare>(comp)
+ {}
+ header_plus_size header_plus_size_;
+ };
+
+ struct data_t : public splaytree_impl::value_traits
+ {
+ typedef typename splaytree_impl::value_traits value_traits;
+ data_t(const value_compare & comp, const value_traits &val_traits)
+ : value_traits(val_traits), node_plus_pred_(comp)
+ {}
+ node_plus_pred_t node_plus_pred_;
+ } data_;
+
+ const value_compare &priv_comp() const
+ { return data_.node_plus_pred_.get(); }
+
+ value_compare &priv_comp()
+ { return data_.node_plus_pred_.get(); }
+
+ const node &priv_header() const
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ node &priv_header()
+ { return data_.node_plus_pred_.header_plus_size_.header_; }
+
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(detail::get_pointer(ptr)));
+ }
+
+ size_traits &priv_size_traits()
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const size_traits &priv_size_traits() const
+ { return data_.node_plus_pred_.header_plus_size_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<false>) const
+ { return data_; }
+
+ const real_value_traits &get_real_value_traits(detail::bool_<true>) const
+ { return data_.get_value_traits(*this); }
+
+ real_value_traits &get_real_value_traits(detail::bool_<false>)
+ { return data_; }
+
+ real_value_traits &get_real_value_traits(detail::bool_<true>)
+ { return data_.get_value_traits(*this); }
+
+ /// @endcond
+
+ public:
+
+ const real_value_traits &get_real_value_traits() const
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ real_value_traits &get_real_value_traits()
+ { return this->get_real_value_traits(detail::bool_<external_value_traits>()); }
+
+ typedef typename node_algorithms::insert_commit_data insert_commit_data;
+
+ //! <b>Effects</b>: Constructs an empty tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing unless the copy constructor of the value_compare object throws.
+ splaytree_impl( value_compare cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(size_type(0));
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue of type value_type.
+ //! cmp must be a comparison function that induces a strict weak ordering.
+ //!
+ //! <b>Effects</b>: Constructs an empty tree and inserts elements from
+ //! [b, e).
+ //!
+ //! <b>Complexity</b>: Linear in N if [b, e) is already sorted using
+ //! comp and otherwise N * log N, where N is the distance between first and last.
+ //!
+ //! <b>Throws</b>: Nothing unless the copy constructor of the value_compare object throws.
+ template<class Iterator>
+ splaytree_impl( bool unique, Iterator b, Iterator e
+ , value_compare cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : data_(cmp, v_traits)
+ {
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(size_type(0));
+ if(unique)
+ this->insert_unique(b, e);
+ else
+ this->insert_equal(b, e);
+ }
+
+ //! <b>Effects</b>: Detaches all elements from this. The objects in the set
+ //! are not deleted (i.e. no destructors are called), but the nodes according to
+ //! the value_traits template parameter are reinitialized and thus can be reused.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ ~splaytree_impl()
+ { this->clear(); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the beginning of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator begin()
+ { return iterator(node_algorithms::begin_node(&priv_header()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator begin() const
+ { return cbegin(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the beginning of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cbegin() const
+ { return const_iterator(node_algorithms::begin_node(&priv_header()), this); }
+
+ //! <b>Effects</b>: Returns an iterator pointing to the end of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator end()
+ { return iterator (node_ptr(&priv_header()), this); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator end() const
+ { return cend(); }
+
+ //! <b>Effects</b>: Returns a const_iterator pointing to the end of the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator cend() const
+ { return const_iterator (uncast(const_node_ptr(&priv_header())), this); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning of the
+ //! reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rbegin()
+ { return reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rbegin() const
+ { return const_reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crbegin() const
+ { return const_reverse_iterator(end()); }
+
+ //! <b>Effects</b>: Returns a reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ reverse_iterator rend()
+ { return reverse_iterator(begin()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator rend() const
+ { return const_reverse_iterator(begin()); }
+
+ //! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
+ //! of the reversed tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_reverse_iterator crend() const
+ { return const_reverse_iterator(begin()); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end iterator
+ //! of splaytree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static splaytree_impl &container_from_end_iterator(iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Precondition</b>: end_iterator must be a valid end const_iterator
+ //! of splaytree.
+ //!
+ //! <b>Effects</b>: Returns a const reference to the splaytree associated to the end iterator
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant.
+ static const splaytree_impl &container_from_end_iterator(const_iterator end_iterator)
+ { return priv_container_from_end_iterator(end_iterator); }
+
+ //! <b>Effects</b>: Returns the value_compare object used by the tree.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If value_compare copy-constructor throws.
+ value_compare value_comp() const
+ { return priv_comp(); }
+
+ //! <b>Effects</b>: Returns true is the container is empty.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ bool empty() const
+ { return this->cbegin() == this->cend(); }
+
+ //! <b>Effects</b>: Returns the number of elements stored in the tree.
+ //!
+ //! <b>Complexity</b>: Linear to elements contained in *this.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type size() const
+ {
+ if(constant_time_size){
+ return this->priv_size_traits().get_size();
+ }
+ else{
+ const_iterator beg(this->cbegin()), end(this->cend());
+ size_type i = 0;
+ for(;beg != end; ++beg) ++i;
+ return i;
+ }
+ }
+
+ //! <b>Effects</b>: Swaps the contents of two multisets.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: If the comparison functor's swap call throws.
+ void swap(splaytree_impl& other)
+ {
+ //This can throw
+ using std::swap;
+ swap(priv_comp(), priv_comp());
+ //These can't throw
+ node_algorithms::swap_tree(node_ptr(&priv_header()), node_ptr(&other.priv_header()));
+ if(constant_time_size){
+ size_type backup = this->priv_size_traits().get_size();
+ this->priv_size_traits().set_size(other.priv_size_traits().get_size());
+ other.priv_size_traits().set_size(backup);
+ }
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the tree before the lower bound.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, splaytree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal_lower_bound
+ (node_ptr(&priv_header()), to_insert, key_node_comp), this);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator.
+ //!
+ //! <b>Effects</b>: Inserts x into the tree, using "hint" as a hint to
+ //! where it will be inserted. If "hint" is the upper_bound
+ //! the insertion takes constant time (two comparisons in the worst case)
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_equal(const_iterator hint, reference value)
+ {
+ detail::key_nodeptr_comp<value_compare, splaytree_impl>
+ key_node_comp(priv_comp(), this);
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ return iterator(node_algorithms::insert_equal
+ (node_ptr(&priv_header()), hint.pointed_node(), to_insert, key_node_comp), this);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Inserts a each element of a range into the tree
+ //! before the upper bound of the key of each element.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert_equal(Iterator b, Iterator e)
+ {
+ if(this->empty()){
+ iterator end(this->end());
+ for (; b != e; ++b)
+ this->insert_equal(end, *b);
+ }
+ }
+
+ //! <b>Requires</b>: value must be an lvalue
+ //!
+ //! <b>Effects</b>: Inserts value into the tree if the value
+ //! is not already present.
+ //!
+ //! <b>Complexity</b>: Average complexity for insert element is at
+ //! most logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ std::pair<iterator, bool> insert_unique(reference value)
+ {
+ insert_commit_data commit_data;
+ std::pair<iterator, bool> ret = insert_unique_check(value, commit_data);
+ if(!ret.second)
+ return ret;
+ return std::pair<iterator, bool> (insert_unique_commit(value, commit_data), true);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue, and "hint" must be
+ //! a valid iterator
+ //!
+ //! <b>Effects</b>: Tries to insert x into the tree, using "hint" as a hint
+ //! to where it will be inserted.
+ //!
+ //! <b>Complexity</b>: Logarithmic in general, but it is amortized
+ //! constant time (two comparisons in the worst case)
+ //! if t is inserted immediately before hint.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ iterator insert_unique(const_iterator hint, reference value)
+ {
+ insert_commit_data commit_data;
+ std::pair<iterator, bool> ret = insert_unique_check(hint, value, commit_data);
+ if(!ret.second)
+ return ret.first;
+ return insert_unique_commit(value, commit_data);
+ }
+
+ //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
+ //! of type value_type.
+ //!
+ //! <b>Effects</b>: Tries to insert each element of a range into the tree.
+ //!
+ //! <b>Complexity</b>: Insert range is in general O(N * log(N)), where N is the
+ //! size of the range. However, it is linear in N if the range is already sorted
+ //! by value_comp().
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Does not affect the validity of iterators and references.
+ //! No copy-constructors are called.
+ template<class Iterator>
+ void insert_unique(Iterator b, Iterator e)
+ {
+ for (; b != e; ++b)
+ this->insert_unique(*b);
+ }
+
+ std::pair<iterator, bool> insert_unique_check
+ (const_reference value, insert_commit_data &commit_data)
+ { return insert_unique_check(value, priv_comp(), commit_data); }
+
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const KeyType &key, KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ (node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), key, comp, commit_data));
+ return std::pair<iterator, bool>(iterator(ret.first, this), ret.second);
+ }
+
+ std::pair<iterator, bool> insert_unique_check
+ (const_iterator hint, const_reference value, insert_commit_data &commit_data)
+ { return insert_unique_check(hint, value, priv_comp(), commit_data); }
+
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator, bool> insert_unique_check
+ (const_iterator hint, const KeyType &key
+ ,KeyValueCompare key_value_comp, insert_commit_data &commit_data)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ comp(key_value_comp, this);
+ std::pair<node_ptr, bool> ret =
+ node_algorithms::insert_unique_check
+ (node_ptr(&priv_header()), hint.pointed_node(), key, comp, commit_data);
+ return std::pair<iterator, bool>(iterator(ret.first, this), ret.second);
+ }
+
+ iterator insert_unique_commit(reference value, const insert_commit_data &commit_data)
+ {
+ node_ptr to_insert(get_real_value_traits().to_node_ptr(value));
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::unique(to_insert));
+ this->priv_size_traits().increment();
+ node_algorithms::insert_unique_commit
+ (node_ptr(&priv_header()), to_insert, commit_data);
+ return iterator(to_insert, this);
+ }
+
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase element is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(iterator i)
+ {
+ iterator ret(i);
+ ++ret;
+ node_ptr to_erase(i.pointed_node());
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(!node_algorithms::unique(to_erase));
+ node_algorithms::erase(&priv_header(), to_erase);
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_erase);
+ return ret;
+ }
+
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is at most
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ iterator erase(iterator b, iterator e)
+ { size_type n; return private_erase(b, e, n); }
+
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ size_type erase(const_reference value)
+ { return this->erase(value, priv_comp()); }
+
+ //! <b>Effects</b>: Erases all the elements with the given key.
+ //! according to the comparison functor "comp".
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class KeyType, class KeyValueCompare>
+ size_type erase(const KeyType& key, KeyValueCompare comp)
+ {
+ std::pair<iterator,iterator> p = this->equal_range(key, comp);
+ size_type n;
+ private_erase(p.first, p.second, n);
+ return n;
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the element pointed to by pos.
+ //! Disposer::operator()(pointer) is called for the removed element.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase element is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(iterator i, Disposer disposer)
+ {
+ node_ptr to_erase(i.pointed_node());
+ iterator ret(this->erase(i));
+ disposer(get_real_value_traits().to_value_ptr(to_erase));
+ return ret;
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases the range pointed to by b end e.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Complexity</b>: Average complexity for erase range is at most
+ //! O(log(size() + N)), where N is the number of elements in the range.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class Disposer>
+ iterator erase_and_dispose(iterator b, iterator e, Disposer disposer)
+ { size_type n; return private_erase(b, e, n, disposer); }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given value.
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ template<class Disposer>
+ size_type erase_and_dispose(const_reference value, Disposer disposer)
+ {
+ std::pair<iterator,iterator> p = this->equal_range(value);
+ size_type n;
+ private_erase(p.first, p.second, n, disposer);
+ return n;
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements with the given key.
+ //! according to the comparison functor "comp".
+ //! Disposer::operator()(pointer) is called for the removed elements.
+ //!
+ //! <b>Returns</b>: The number of erased elements.
+ //!
+ //! <b>Complexity</b>: O(log(size() + N).
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators
+ //! to the erased elements.
+ template<class KeyType, class KeyValueCompare, class Disposer>
+ size_type erase_and_dispose(const KeyType& key, KeyValueCompare comp, Disposer disposer)
+ {
+ std::pair<iterator,iterator> p = this->equal_range(key, comp);
+ size_type n;
+ private_erase(p.first, p.second, n, disposer);
+ return n;
+ }
+
+ //! <b>Effects</b>: Erases all of the elements.
+ //!
+ //! <b>Complexity</b>: Linear to the number of elements on the container.
+ //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. No destructors are called.
+ void clear()
+ {
+ if(safemode_or_autounlink){
+ this->clear_and_dispose(detail::null_disposer());
+ }
+ else{
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(0);
+ }
+ }
+
+ //! <b>Effects</b>: Erases all of the elements calling disposer(p) for
+ //! each node to be erased.
+ //! <b>Complexity</b>: Average complexity for is at most O(log(size() + N)),
+ //! where N is the number of elements in the container.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: Invalidates the iterators (but not the references)
+ //! to the erased elements. Calls N times to disposer functor.
+ template<class Disposer>
+ void clear_and_dispose(Disposer disposer)
+ {
+ node_algorithms::clear_and_dispose(node_ptr(&priv_header())
+ , detail::node_disposer<Disposer, splaytree_impl>(disposer, this));
+ node_algorithms::init_header(&priv_header());
+ this->priv_size_traits().set_size(0);
+ }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given value
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given value.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type count(const_reference value)
+ { return this->count(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ size_type count(const KeyType &key, KeyValueCompare comp)
+ {
+ std::pair<const_iterator, const_iterator> ret = this->equal_range(key, comp);
+ return std::distance(ret.first, ret.second);
+ }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given value
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given value.
+ //!
+ //! <b>Throws</b>: Nothing.
+ size_type count_dont_splay(const_reference value) const
+ { return this->count_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns the number of contained elements with the given key
+ //!
+ //! <b>Complexity</b>: Logarithmic to the number of elements contained plus lineal
+ //! to number of objects with the given key.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ size_type count_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ std::pair<const_iterator, const_iterator> ret = this->equal_range_dont_splay(key, comp);
+ return std::distance(ret.first, ret.second);
+ }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator lower_bound(const_reference value)
+ { return this->lower_bound(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator lower_bound_dont_splay(const_reference value) const
+ { return this->lower_bound_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ iterator lower_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), key, key_node_comp), this);
+ }
+
+ //! <b>Effects</b>: Returns a const iterator to the first element whose
+ //! key is not less than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator lower_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::lower_bound
+ (const_node_ptr(&priv_header()), key, key_node_comp, false), this);
+ }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator upper_bound(const_reference value)
+ { return this->upper_bound(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k according to comp or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ iterator upper_bound(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator(node_algorithms::upper_bound
+ (const_node_ptr(&priv_header()), key, key_node_comp), this);
+ }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator upper_bound_dont_splay(const_reference value) const
+ { return this->upper_bound_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Returns an iterator to the first element whose
+ //! key is greater than k according to comp or end() if that element
+ //! does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator upper_bound_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator(node_algorithms::upper_bound_dont_splay
+ (const_node_ptr(&priv_header()), key, key_node_comp, false), this);
+ }
+
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator find(const_reference value)
+ { return this->find(value, priv_comp()); }
+
+ //! <b>Effects</b>: Finds an iterator to the first element whose key is
+ //! k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ iterator find(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), key, key_node_comp), this);
+ }
+
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
+ //! k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator find_dont_splay(const_reference value) const
+ { return this->find_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
+ //! k or end() if that element does not exist.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ const_iterator find_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ return const_iterator
+ (node_algorithms::find(const_node_ptr(&priv_header()), key, key_node_comp, false), this);
+ }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ std::pair<iterator,iterator> equal_range(const_reference value)
+ { return this->equal_range(value, priv_comp()); }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<iterator,iterator> equal_range(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp));
+ return std::pair<iterator, iterator>(iterator(ret.first, this), iterator(ret.second, this));
+ }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ std::pair<const_iterator, const_iterator>
+ equal_range_dont_splay(const_reference value) const
+ { return this->equal_range_dont_splay(value, priv_comp()); }
+
+ //! <b>Effects</b>: Finds a range containing all elements whose key is k or
+ //! an empty range that indicates the position where those elements would be
+ //! if they there is no elements with key k.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ template<class KeyType, class KeyValueCompare>
+ std::pair<const_iterator, const_iterator>
+ equal_range_dont_splay(const KeyType &key, KeyValueCompare comp) const
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ std::pair<node_ptr, node_ptr> ret
+ (node_algorithms::equal_range(const_node_ptr(&priv_header()), key, key_node_comp, false));
+ return std::pair<const_iterator, const_iterator>(const_iterator(ret.first, this), const_iterator(ret.second, this));
+ }
+
+ //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
+ //!
+ //! <b>Effects</b>: Erases all the elements from *this
+ //! calling Disposer::operator()(pointer), clones all the
+ //! elements from src calling Cloner::operator()(const_reference )
+ //! and inserts them on *this.
+ //!
+ //! If cloner throws, all cloned elements are unlinked and disposed
+ //! calling Disposer::operator()(pointer).
+ //!
+ //! <b>Complexity</b>: Linear to erased plus inserted elements.
+ //!
+ //! <b>Throws</b>: If cloner throws.
+ template <class Cloner, class Disposer>
+ void clone_from(const splaytree_impl &src, Cloner cloner, Disposer disposer)
+ {
+ this->clear_and_dispose(disposer);
+ if(!src.empty()){
+ node_algorithms::clone
+ (const_node_ptr(&src.priv_header())
+ ,node_ptr(&this->priv_header())
+ ,detail::node_cloner<Cloner, splaytree_impl>(cloner, this)
+ ,detail::node_disposer<Disposer, splaytree_impl>(disposer, this));
+ this->priv_size_traits().set_size(src.priv_size_traits().get_size());
+ }
+ }
+
+ //! <b>Effects</b>: Unlinks the leftmost node from the tree.
+ //!
+ //! <b>Complexity</b>: Average complexity is constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Notes</b>: This function breaks the tree and the tree can
+ //! only be used for more unlink_leftmost_without_rebalance calls.
+ //! This function is normally used to achieve a step by step
+ //! controlled destruction of the tree.
+ pointer unlink_leftmost_without_rebalance()
+ {
+ node_ptr to_be_disposed(node_algorithms::unlink_leftmost_without_rebalance
+ (node_ptr(&priv_header())));
+ if(!to_be_disposed)
+ return 0;
+ this->priv_size_traits().decrement();
+ if(safemode_or_autounlink)//If this is commented does not work with normal_link
+ node_algorithms::init(to_be_disposed);
+ return get_real_value_traits().to_value_ptr(to_be_disposed);
+ }
+
+ //! <b>Requires</b>: i must be a valid iterator of *this.
+ //!
+ //! <b>Effects</b>: Rearranges the splay set so that the element pointed by i
+ //! is placed as the root of the tree, improving future searches of this value.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ void splay_up(iterator i)
+ { return node_algorithms::splay_up(i.pointed_node(), &priv_header()); }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree. If the element is not present returns the last node compared with the key.
+ //! If the tree is empty, end() is returned.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the comparison functor throws.
+ template<class KeyType, class KeyValueCompare>
+ iterator splay_down(const KeyType &key, KeyValueCompare comp)
+ {
+ detail::key_nodeptr_comp<KeyValueCompare, splaytree_impl>
+ key_node_comp(comp, this);
+ node_ptr r = node_algorithms::splay_down(&priv_header(), key, key_node_comp);
+ return iterator(r, this);
+ }
+
+ //! <b>Effects</b>: Rearranges the splay set so that if *this stores an element
+ //! with a key equivalent to value the element is placed as the root of the
+ //! tree.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Returns</b>: An iterator to the new root of the tree, end() if the tree is empty.
+ //!
+ //! <b>Throws</b>: If the predicate throws.
+ iterator splay_down(const value_type &value)
+ { return this->splay_down(value, priv_comp()); }
+
+ //! <b>Requires</b>: replace_this must be a valid iterator of *this
+ //! and with_this must not be inserted in any tree.
+ //!
+ //! <b>Effects</b>: Replaces replace_this in its position in the
+ //! tree with with_this. The tree does not need to be rebalanced.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! with_this is not equivalent to *replace_this according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ void replace_node(iterator replace_this, reference with_this)
+ {
+ node_algorithms::replace_node( get_real_value_traits().to_node_ptr(*replace_this)
+ , node_ptr(&priv_header())
+ , get_real_value_traits().to_node_ptr(with_this));
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static iterator s_iterator_to(reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ return iterator (value_traits::to_node_ptr(value), 0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This static function is available only if the <i>value traits</i>
+ //! is stateless.
+ static const_iterator s_iterator_to(const_reference value)
+ {
+ BOOST_STATIC_ASSERT((!stateful_value_traits));
+ return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), 0);
+ }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid iterator i belonging to the set
+ //! that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ iterator iterator_to(reference value)
+ { return iterator (value_traits::to_node_ptr(value), this); }
+
+ //! <b>Requires</b>: value must be an lvalue and shall be in a set of
+ //! appropriate type. Otherwise the behavior is undefined.
+ //!
+ //! <b>Effects</b>: Returns: a valid const_iterator i belonging to the
+ //! set that points to the value
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ const_iterator iterator_to(const_reference value) const
+ { return const_iterator (value_traits::to_node_ptr(const_cast<reference> (value)), this); }
+
+ //! <b>Requires</b>: value shall not be in a tree.
+ //!
+ //! <b>Effects</b>: init_node puts the hook of a value in a well-known default
+ //! state.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This function puts the hook in the well-known default state
+ //! used by auto_unlink and safe hooks.
+ static void init_node(reference value)
+ { node_algorithms::init(value_traits::to_node_ptr(value)); }
+
+/*
+ //! <b>Effects</b>: removes x from a tree of the appropriate type. It has no effect,
+ //! if x is not in such a tree.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Note</b>: This static function is only usable with the "safe mode"
+ //! hook and non-constant time size lists. Otherwise, the user must use
+ //! the non-static "erase(reference )" member. If the user calls
+ //! this function with a non "safe mode" or constant time size list
+ //! a compilation error will be issued.
+ template<class T>
+ static void remove_node(T& value)
+ {
+ //This function is only usable for safe mode hooks and non-constant
+ //time lists.
+ //BOOST_STATIC_ASSERT((!(safemode_or_autounlink && constant_time_size)));
+ BOOST_STATIC_ASSERT((!constant_time_size));
+ BOOST_STATIC_ASSERT((boost::is_convertible<T, value_type>::value));
+ node_ptr to_remove(value_traits::to_node_ptr(value));
+ node_algorithms::unlink_and_rebalance(to_remove);
+ if(safemode_or_autounlink)
+ node_algorithms::init(to_remove);
+ }
+*/
+
+ /// @cond
+ private:
+ template<class Disposer>
+ iterator private_erase(iterator b, iterator e, size_type &n, Disposer disposer)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase_and_dispose(b++, disposer);
+ return b;
+ }
+
+ iterator private_erase(iterator b, iterator e, size_type &n)
+ {
+ for(n = 0; b != e; ++n)
+ this->erase(b++);
+ return b;
+ }
+ /// @endcond
+
+ private:
+ static splaytree_impl &priv_container_from_end_iterator(const const_iterator &end_iterator)
+ {
+ header_plus_size *r = detail::parent_from_member<header_plus_size, node>
+ ( detail::get_pointer(end_iterator.pointed_node()), &header_plus_size::header_);
+ node_plus_pred_t *n = detail::parent_from_member
+ <node_plus_pred_t, header_plus_size>(r, &node_plus_pred_t::header_plus_size_);
+ data_t *d = detail::parent_from_member<data_t, node_plus_pred_t>(n, &data_t::node_plus_pred_);
+ splaytree_impl *rb = detail::parent_from_member<splaytree_impl, data_t>(d, &splaytree_impl::data_);
+ return *rb;
+ }
+};
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+bool operator==
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{
+ typedef splaytree_impl<Config> tree_type;
+ typedef typename tree_type::const_iterator const_iterator;
+
+ if(tree_type::constant_time_size && x.size() != y.size()){
+ return false;
+ }
+ const_iterator end1 = x.end();
+ const_iterator i1 = x.begin();
+ const_iterator i2 = y.begin();
+ if(tree_type::constant_time_size){
+ while (i1 != end1 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1;
+ }
+ else{
+ const_iterator end2 = y.end();
+ while (i1 != end1 && i2 != end2 && *i1 == *i2) {
+ ++i1;
+ ++i2;
+ }
+ return i1 == end1 && i2 == end2;
+ }
+}
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator!=
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(x == y); }
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return y < x; }
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator<=
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(y < x); }
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline bool operator>=
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(const splaytree_impl<T, Options...> &x, const splaytree_impl<T, Options...> &y)
+#else
+(const splaytree_impl<Config> &x, const splaytree_impl<Config> &y)
+#endif
+{ return !(x < y); }
+
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class Config>
+#endif
+inline void swap
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+(splaytree_impl<T, Options...> &x, splaytree_impl<T, Options...> &y)
+#else
+(splaytree_impl<Config> &x, splaytree_impl<Config> &y)
+#endif
+{ x.swap(y); }
+
+/// @cond
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none
+ , class O5 = none, class O6 = none
+ , class O7 = none
+ >
+struct make_splaytree_opt
+{
+ typedef typename pack_options
+ < splay_set_defaults<T>, O1, O2, O3, O4>::type packed_options;
+ typedef typename detail::get_value_traits
+ <T, typename packed_options::value_traits>::type value_traits;
+
+ typedef splaysetopt
+ < value_traits
+ , typename packed_options::compare
+ , typename packed_options::size_type
+ , packed_options::constant_time_size
+ > type;
+};
+/// @endcond
+
+//! Helper metafunction to define a \c splaytree that yields to the same type when the
+//! same options (either explicitly or implicitly) are used.
+#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class ...Options>
+#else
+template<class T, class O1 = none, class O2 = none
+ , class O3 = none, class O4 = none>
+#endif
+struct make_splaytree
+{
+ /// @cond
+ typedef splaytree_impl
+ < typename make_splaytree_opt<T, O1, O2, O3, O4>::type
+ > implementation_defined;
+ /// @endcond
+ typedef implementation_defined type;
+};
+
+#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
+template<class T, class O1, class O2, class O3, class O4>
+class splaytree
+ : public make_splaytree<T, O1, O2, O3, O4>::type
+{
+ typedef typename make_splaytree
+ <T, O1, O2, O3, O4>::type Base;
+
+ public:
+ typedef typename Base::value_compare value_compare;
+ typedef typename Base::value_traits value_traits;
+ typedef typename Base::real_value_traits real_value_traits;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+
+ //Assert if passed value traits are compatible with the type
+ BOOST_STATIC_ASSERT((detail::is_same<typename real_value_traits::value_type, T>::value));
+
+ splaytree( const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(cmp, v_traits)
+ {}
+
+ template<class Iterator>
+ splaytree( bool unique, Iterator b, Iterator e
+ , const value_compare &cmp = value_compare()
+ , const value_traits &v_traits = value_traits())
+ : Base(unique, b, e, cmp, v_traits)
+ {}
+
+ static splaytree &container_from_end_iterator(iterator end_iterator)
+ { return static_cast<splaytree &>(Base::container_from_end_iterator(end_iterator)); }
+
+ static const splaytree &container_from_end_iterator(const_iterator end_iterator)
+ { return static_cast<const splaytree &>(Base::container_from_end_iterator(end_iterator)); }
+};
+
+#endif
+
+
+} //namespace intrusive
+} //namespace boost
+
+#include <boost/intrusive/detail/config_end.hpp>
+
+#endif //BOOST_INTRUSIVE_SPLAYTREE_HPP

Added: trunk/boost/intrusive/splaytree_algorithms.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/intrusive/splaytree_algorithms.hpp 2007-10-24 14:59:26 EDT (Wed, 24 Oct 2007)
@@ -0,0 +1,828 @@
+/////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007.
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/intrusive for documentation.
+//
+/////////////////////////////////////////////////////////////////////////////
+// The implementation of splay trees is based on the article and code published
+// in C++ Users Journal "Implementing Splay Trees in C++" (September 1, 2005).
+//
+// The code has been modified and (supposely) improved by Ion Gaztanaga.
+// Here is the header of the file used as base code:
+//
+// splay_tree.h -- implementation of a STL complatible splay tree.
+//
+// Copyright (c) 2004 Ralf Mattethat
+//
+// Permission to copy, use, modify, sell and distribute this software
+// is granted provided this copyright notice appears in all copies.
+// This software is provided "as is" without express or implied
+// warranty, and with no claim as to its suitability for any purpose.
+//
+// Please send questions, comments, complaints, performance data, etc to
+// ralf.mattethat_at_[hidden]
+//
+// Requirements for element type
+// * must be copy-constructible
+// * destructor must not throw exception
+//
+// Methods marked with note A only throws an exception if the evaluation of the
+// predicate throws an exception. If an exception is thrown the call has no
+// effect on the containers state
+//
+// Methods marked with note B only throws an exception if the coppy constructor
+// or assignment operator of the predicate throws an exception. If an exception
+// is thrown the call has no effect on the containers state
+//
+// iterators are only invalidated, if the element pointed to by the iterator
+// is deleted. The same goes for element references
+//
+
+#ifndef BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
+#define BOOST_INTRUSIVE_SPLAYTREE_ALGORITHMS_HPP
+
+#include <boost/intrusive/detail/config_begin.hpp>
+#include <boost/intrusive/detail/assert.hpp>
+#include <boost/intrusive/intrusive_fwd.hpp>
+#include <cstddef>
+#include <boost/intrusive/detail/no_exceptions_support.hpp>
+#include <boost/intrusive/detail/utilities.hpp>
+#include <boost/intrusive/detail/tree_algorithms.hpp>
+
+namespace boost {
+namespace intrusive {
+
+//! 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 typename NodeTraits::node node;
+ typedef detail::tree_algorithms<NodeTraits> tree_algorithms;
+ /// @endcond
+
+ public:
+ typedef NodeTraits node_traits;
+ typedef typename NodeTraits::node_ptr node_ptr;
+ typedef typename NodeTraits::const_node_ptr const_node_ptr;
+
+ //! This type is the information that will be
+ //! filled by insert_unique_check
+ typedef typename tree_algorithms::insert_commit_data insert_commit_data;
+
+ /// @cond
+ private:
+ static node_ptr uncast(const_node_ptr ptr)
+ {
+ return node_ptr(const_cast<node*>(::boost::intrusive::detail::get_pointer(ptr)));
+ }
+ /// @endcond
+
+ public:
+ static node_ptr begin_node(const_node_ptr header)
+ { return tree_algorithms::begin_node(header); }
+
+ static node_ptr end_node(const_node_ptr header)
+ { return tree_algorithms::end_node(header); }
+
+ //! <b>Requires</b>: node is a node of the tree or an node initialized
+ //! by init(...).
+ //!
+ //! <b>Effects</b>: Returns true if the node is initialized by init().
+ //!
+ //! <b>Complexity</b>: Constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static bool unique(const_node_ptr node)
+ { return tree_algorithms::unique(node); }
+
+ static void unlink(node_ptr node)
+ { tree_algorithms::unlink(node); }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr node2)
+ {
+ if(node1 == node2)
+ return;
+
+ node_ptr header1(tree_algorithms::get_header(node1)), header2(tree_algorithms::get_header(node2));
+ swap_nodes(node1, header1, node2, header2);
+ }
+
+ //! <b>Requires</b>: node1 and node2 can't be header nodes
+ //! of two trees with header header1 and header2.
+ //!
+ //! <b>Effects</b>: Swaps two nodes. After the function node1 will be inserted
+ //! in the position node2 before the function. node2 will be inserted in the
+ //! position node1 had before the function.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! node1 and node2 are not equivalent according to the ordering rules.
+ //!
+ //!Experimental function
+ static void swap_nodes(node_ptr node1, node_ptr header1, node_ptr node2, node_ptr header2)
+ { tree_algorithms::swap_nodes(node1, header1, node2, header2); }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Logarithmic.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing and comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr new_node)
+ {
+ if(node_to_be_replaced == new_node)
+ return;
+ replace_node(node_to_be_replaced, tree_algorithms::get_header(node_to_be_replaced), new_node);
+ }
+
+ //! <b>Requires</b>: node_to_be_replaced must be inserted in a tree
+ //! with header "header" and new_node must not be inserted in a tree.
+ //!
+ //! <b>Effects</b>: Replaces node_to_be_replaced in its position in the
+ //! tree with new_node. The tree does not need to be rebalanced
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Note</b>: This function will break container ordering invariants if
+ //! new_node is not equivalent to node_to_be_replaced according to the
+ //! ordering rules. This function is faster than erasing and inserting
+ //! the node, since no rebalancing or comparison is needed.
+ //!
+ //!Experimental function
+ static void replace_node(node_ptr node_to_be_replaced, node_ptr header, node_ptr new_node)
+ { tree_algorithms::replace_node(node_to_be_replaced, header, new_node); }
+
+ //! <b>Requires</b>: p is a node from the tree except the header.
+ //!
+ //! <b>Effects</b>: Returns the next node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr next_node(node_ptr p)
+ { return tree_algorithms::next_node(p); }
+
+ //! <b>Requires</b>: p is a node from the tree except the leftmost node.
+ //!
+ //! <b>Effects</b>: Returns the previous node of the tree.
+ //!
+ //! <b>Complexity</b>: Average constant time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static node_ptr prev_node(node_ptr p)
+ { return tree_algorithms::prev_node(p); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: After the function unique(node) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init(node_ptr node)
+ { tree_algorithms::init(node); }
+
+ //! <b>Requires</b>: node must not be part of any tree.
+ //!
+ //! <b>Effects</b>: Initializes the header to represent an empty tree.
+ //! unique(header) == true.
+ //!
+ //! <b>Complexity</b>: Constant.
+ //!
+ //! <b>Throws</b>: Nothing.
+ //!
+ //! <b>Nodes</b>: If node is inserted in a tree, this function corrupts the tree.
+ static void init_header(node_ptr header)
+ { tree_algorithms::init_header(header); }
+
+ //! <b>Requires</b>: "disposer" must be an object function
+ //! taking a node_ptr parameter and shouldn't throw.
+ //!
+ //! <b>Effects</b>: Empties the target tree calling
+ //! <tt>void disposer::operator()(node_ptr)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template<class Disposer>
+ static void clear_and_dispose(node_ptr header, Disposer disposer)
+ { tree_algorithms::clear_and_dispose(header, disposer); }
+
+ //! <b>Requires</b>: node is a node of the tree but it's not the header.
+ //!
+ //! <b>Effects</b>: Returns the number of nodes of the subtree.
+ //!
+ //! <b>Complexity</b>: Linear time.
+ //!
+ //! <b>Throws</b>: Nothing.
+ static std::size_t count(const_node_ptr node)
+ { return tree_algorithms::count(node); }
+
+ //! <b>Requires</b>: 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, bool splay = true)
+ {
+ if(splay)
+ 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, bool splay = true)
+ {
+ if(splay)
+ 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, bool splay = true)
+ {
+ if(splay)
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal(header, hint, new_node, comp);
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_upper_bound
+ (node_ptr header, node_ptr new_node, NodePtrCompare comp, bool splay = true)
+ {
+ if(splay)
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal_upper_bound(header, new_node, comp);
+ }
+
+ template<class NodePtrCompare>
+ static node_ptr insert_equal_lower_bound
+ (node_ptr header, node_ptr new_node, NodePtrCompare comp, bool splay = true)
+ {
+ if(splay)
+ splay_down(header, new_node, comp);
+ return tree_algorithms::insert_equal_lower_bound(header, new_node, comp);
+ }
+
+ //! <b>Requires</b>: "cloner" must be a function
+ //! object taking a node_ptr and returning a new cloned node of it. "disposer" must
+ //! take a node_ptr and shouldn't throw.
+ //!
+ //! <b>Effects</b>: First empties target tree calling
+ //! <tt>void disposer::operator()(node_ptr)</tt> for every node of the tree
+ //! except the header.
+ //!
+ //! Then, duplicates the entire tree pointed by "source_header" cloning each
+ //! source node with <tt>node_ptr Cloner::operator()(node_ptr)</tt> to obtain
+ //! the nodes of the target tree. If "cloner" throws, the cloned target nodes
+ //! are disposed using <tt>void disposer(node_ptr)</tt>.
+ //!
+ //! <b>Complexity</b>: Linear to the number of element of the source tree plus the.
+ //! number of elements of tree target tree when calling this function.
+ //!
+ //! <b>Throws</b>: If cloner functor throws. If this happens target nodes are disposed.
+ template <class Cloner, class Disposer>
+ static void clone
+ (const_node_ptr source_header, node_ptr target_header, Cloner cloner, Disposer disposer)
+ { tree_algorithms::clone(source_header, target_header, cloner, disposer); }
+
+ // delete node | complexity : constant | exception : nothrow
+ static void erase(node_ptr header, node_ptr z, bool splay = true)
+ {
+// node_base* n = t->right;
+// if( t->left != 0 ){
+// node_base* l = t->previous();
+// splay_up( l , t );
+// n = t->left;
+// n->right = t->right;
+// if( n->right != 0 )
+// n->right->parent = n;
+// }
+//
+// if( n != 0 )
+// n->parent = t->parent;
+//
+// if( t->parent->left == t )
+// t->parent->left = n;
+// else // must be ( t->parent->right == t )
+// t->parent->right = n;
+//
+// if( data_->parent == t )
+// data_->parent = find_leftmost();
+ //posibility 1
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = prev_node(z);
+ splay_up(l, header);
+ }
+ /*
+ //possibility 2
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = NodeTraits::get_left(z);
+ splay_up(l, header);
+ }*//*
+ if(splay && NodeTraits::get_left(z) != 0 ){
+ node_ptr l = prev_node(z);
+ splay_up_impl(l, z);
+ }*/
+ /*
+ //possibility 4
+ if(splay){
+ splay_up(z, header);
+ }*/
+
+ //if(splay)
+ //splay_up(z, header);
+ tree_algorithms::erase(header, z);
+ }
+
+ // bottom-up splay, use data_ as parent for n | complexity : logarithmic | exception : nothrow
+ static void splay_up(node_ptr n, node_ptr header)
+ {
+ if(n == header){ // do a splay for the right most node instead
+ // this is to boost performance of equal_range/count on equivalent containers in the case
+ // where there are many equal elements at the end
+ n = NodeTraits::get_right(header);
+ }
+
+ node_ptr t = header;
+
+ if( n == t ) return;
+
+ for( ;; ){
+ node_ptr p = NodeTraits::get_parent(n);
+ node_ptr g = NodeTraits::get_parent(p);
+
+ if( p == t ) break;
+
+ if( g == t ){
+ // zig
+ rotate(n);
+ }
+ else if ((NodeTraits::get_left(p) == n && NodeTraits::get_left(g) == p) ||
+ (NodeTraits::get_right(p) == n && NodeTraits::get_right(g) == p) ){
+ // zig-zig
+ rotate(p);
+ rotate(n);
+ }
+ else{
+ // zig-zag
+ rotate(n);
+ rotate(n);
+ }
+ }
+ }
+
+ // top-down splay | complexity : logarithmic | exception : strong, note A
+ template<class KeyType, class KeyNodePtrCompare>
+ static node_ptr splay_down(node_ptr header, const KeyType &key, KeyNodePtrCompare comp, bool splay = true)
+ {
+ 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);
+
+ try{
+ 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);
+ }
+ catch(...){
+ //Exception can only be thrown by comp, but
+ //tree invariants still hold. t is the current root
+ //so link it to the header.
+ NodeTraits::set_parent(t, header);
+ NodeTraits::set_parent(header, t);
+ //Recover leftmost/rightmost pointers
+ NodeTraits::set_left (header, leftmost);
+ NodeTraits::set_right(header, rightmost);
+ throw;
+ }
+ //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;
+ }
+
+ 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 )
+ 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


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