Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template splaytree_algorithms

boost::intrusive::splaytree_algorithms

Synopsis

// In header: <boost/intrusive/splaytree_algorithms.hpp>

template<typename NodeTraits> 
class splaytree_algorithms {
public:
  // types
  typedef                 ;              
  typedef                       ;       
  typedef             ;          
  typedef       ;    
  typedef  ;

  // public static functions
   () ;
   () ;
   () ;
   (, );
   (, ) ;
   (, , , ) ;
   (, ) ;
   (, , ) ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   (, ) ;
  template<typename NodePtrCompare> 
     (, , , );
  template<typename NodePtrCompare> 
     (, , , );
  template<typename Cloner, typename Disposer> 
     (, , , );
  template<typename Disposer> 
     (, ) ;
  template<typename KeyType, typename KeyNodePtrCompare> 
     (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , , 
                  , , );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , , 
                  , , );
  template<typename NodePtrCompare> 
     
    (, , );
  template<typename NodePtrCompare> 
     
    (, , );
  template<typename NodePtrCompare> 
     (, , , );
   (, , ) ;
   (, ) ;
   (, ) ;
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , , 
                        );
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , , 
                        , );
   (, , 
                                   ) ;
   () ;
   () ;
   () ;
   (, ) ;
  template<typename KeyType, typename KeyNodePtrCompare> 
     
    (, , ,  = );
};

Description

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:

Typedefs:

node: The type of the node that forms the binary search tree

node_ptr: A pointer to a node

const_node_ptr: A pointer to a const node

Static functions:

static node_ptr get_parent(const_node_ptr n);

static void set_parent(node_ptr n, node_ptr parent);

static node_ptr get_left(const_node_ptr n);

static void set_left(node_ptr n, node_ptr left);

static node_ptr get_right(const_node_ptr n);

static void set_right(node_ptr n, node_ptr right);

splaytree_algorithms public types

  1. typedef ;

    This type is the information that will be filled by insert_unique_check

splaytree_algorithms public static functions

  1.  ( n) ;

    Requires: 'n' is a node of the tree or a header node.

    Effects: Returns the header of the tree.

    Complexity: Logarithmic.

    Throws: Nothing.

  2.  ( header) ;

    Requires: 'header' is the header node of a tree.

    Effects: Returns the first node of the tree, the header if the tree is empty.

    Complexity: Constant time.

    Throws: Nothing.

  3.  ( header) ;

    Requires: 'header' is the header node of a tree.

    Effects: Returns the header of the tree.

    Complexity: Constant time.

    Throws: Nothing.

  4.  ( header1,  header2);

    Requires: header1 and header2 must be the header nodes of two trees.

    Effects: Swaps two trees. After the function header1 will contain links to the second tree and header2 will have links to the first tree.

    Complexity: Constant.

    Throws: Nothing.

  5.  ( node1,  node2) ;

    Requires: node1 and node2 can't be header nodes of two trees.

    Effects: 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.

    Complexity: Logarithmic.

    Throws: Nothing.

    Note: This function will break container ordering invariants if node1 and node2 are not equivalent according to the ordering rules.

    Experimental function

  6.  ( node1,  header1,  node2, 
                            header2) ;

    Requires: node1 and node2 can't be header nodes of two trees with header header1 and header2.

    Effects: 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.

    Complexity: Constant.

    Throws: Nothing.

    Note: This function will break container ordering invariants if node1 and node2 are not equivalent according to the ordering rules.

    Experimental function

  7.  ( node_to_be_replaced,  new_node) ;

    Requires: node_to_be_replaced must be inserted in a tree and new_node must not be inserted in a tree.

    Effects: Replaces node_to_be_replaced in its position in the tree with new_node. The tree does not need to be rebalanced

    Complexity: Logarithmic.

    Throws: Nothing.

    Note: 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

  8.  ( node_to_be_replaced,  header, 
                              new_node) ;

    Requires: node_to_be_replaced must be inserted in a tree with header "header" and new_node must not be inserted in a tree.

    Effects: Replaces node_to_be_replaced in its position in the tree with new_node. The tree does not need to be rebalanced

    Complexity: Constant.

    Throws: Nothing.

    Note: 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

  9.  ( n) ;

    Requires: 'n' is a tree node but not the header.

    Effects: Unlinks the node and rebalances the tree.

    Complexity: Average complexity is constant time.

    Throws: Nothing.

  10.  ( header) ;

    Requires: header is the header of a tree.

    Effects: Unlinks the leftmost node from the tree, and updates the header link to the new leftmost node.

    Complexity: Average complexity is constant time.

    Throws: Nothing.

    Notes: 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.

  11.  ( n) ;

    Requires: 'n' is a node of the tree or a node initialized by init(...) or init_node.

    Effects: Returns true if the node is initialized by init() or init_node().

    Complexity: Constant time.

    Throws: Nothing.

  12.  ( header) ;

    Requires: 'header' the header of the tree.

    Effects: Returns the number of nodes of the tree.

    Complexity: Linear time.

    Throws: Nothing.

  13.  ( n) ;

    Requires: 'n' is a node from the tree except the header.

    Effects: Returns the next node of the tree.

    Complexity: Average constant time.

    Throws: Nothing.

  14.  ( n) ;

    Requires: 'n' is a node from the tree except the leftmost node.

    Effects: Returns the previous node of the tree.

    Complexity: Average constant time.

    Throws: Nothing.

  15.  ( n) ;

    Requires: 'n' must not be part of any tree.

    Effects: After the function unique(node) == true.

    Complexity: Constant.

    Throws: Nothing.

    Nodes: If node is inserted in a tree, this function corrupts the tree.

  16.  ( header) ;

    Requires: header must not be part of any tree.

    Effects: Initializes the header to represent an empty tree. unique(header) == true.

    Complexity: Constant.

    Throws: Nothing.

    Nodes: If header is inserted in a tree, this function corrupts the tree.

  17.  ( header,  z) ;

    Requires: header must be the header of a tree, z a node of that tree and z != header.

    Effects: Erases node "z" from the tree with header "header".

    Complexity: Amortized constant time.

    Throws: Nothing. Additional notes: the previous node of z is splayed to speed up range deletions.

  18. template<typename NodePtrCompare> 
       ( header1,  comp, 
                                   header2,  z);

    Requires: header1 and header2 must be the headers of trees tree1 and tree2 respectively, z a non-header node of tree1. NodePtrCompare is the comparison function of tree1..

    Effects: Transfers node "z" from tree1 to tree2 if tree1 does not contain a node that is equivalent to z.

    Returns: True if the node was trasferred, false otherwise.

    Complexity: Logarithmic.

    Throws: If the comparison throws.

  19. template<typename NodePtrCompare> 
       ( header1,  comp, 
                                  header2,  z);

    Requires: header1 and header2 must be the headers of trees tree1 and tree2 respectively, z a non-header node of tree1. NodePtrCompare is the comparison function of tree1..

    Effects: Transfers node "z" from tree1 to tree2.

    Complexity: Logarithmic.

    Throws: If the comparison throws.

  20. template<typename Cloner, typename Disposer> 
       ( source_header,  target_header, 
                         cloner,  disposer);

    Requires: "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.

    Effects: First empties target tree calling void disposer::operator()(node_ptr) for every node of the tree except the header.

    Then, duplicates the entire tree pointed by "source_header" cloning each source node with node_ptr Cloner::operator()(node_ptr) to obtain the nodes of the target tree. If "cloner" throws, the cloned target nodes are disposed using void disposer(node_ptr ).

    Complexity: Linear to the number of element of the source tree plus the number of elements of tree target tree when calling this function.

    Throws: If cloner functor throws. If this happens target nodes are disposed.

  21. template<typename Disposer> 
       ( header,  disposer) ;

    Requires: "disposer" must be an object function taking a node_ptr parameter and shouldn't throw.

    Effects: Empties the target tree calling void disposer::operator()(node_ptr) for every node of the tree except the header.

    Complexity: Linear to the number of element of the source tree plus the. number of elements of tree target tree when calling this function.

    Throws: Nothing.

  22. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns the number of elements with a key equivalent to "key" according to "comp".

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: an element with key key is splayed.

  23. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns the number of elements with a key equivalent to "key" according to "comp".

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  24. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is not less than "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: the first node of the range is splayed.

  25. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                   comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is not less than "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  26. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is greater than "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: the first node of the range is splayed.

  27. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                   comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is greater than "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  28. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is equivalent to "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: the found node of the lower bound is splayed.

  29. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: Returns a node_ptr to the first element that is equivalent to "key" according to "comp" or "header" if that element does not exist.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  30. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp);

    Requires: "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.

    Effects: 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 there are no equivalent elements.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: the first node of the range is splayed.

  31. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                   comp);

    Requires: "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.

    Effects: 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 there are no equivalent elements.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  32. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                         comp);

    Requires: "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.

    Effects: Returns an a pair of node_ptr delimiting a range containing the first element that is equivalent to "key" according to "comp" or an empty range that indicates the position where that element would be if there are no equivalent elements.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional notes: the first node of the range is splayed.

  33. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                         comp);

    Requires: "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.

    Effects: Returns an a pair of node_ptr delimiting a range containing the first element that is equivalent to "key" according to "comp" or an empty range that indicates the position where that element would be if there are no equivalent elements.

    Complexity: Logarithmic.

    Throws: If "comp" throws. Additional note: no splaying is performed

  34. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  lower_key, 
                     upper_key,  comp, 
                     left_closed,  right_closed);

    Requires: "header" must be the header node of a tree. KeyNodePtrCompare is a function object that induces a strict weak ordering compatible with the strict weak ordering used to create the the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. 'lower_key' must not be greater than 'upper_key' according to 'comp'. If 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be true.

    Effects: Returns an a pair with the following criteria:

    first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise

    second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise

    Complexity: Logarithmic.

    Throws: If "comp" throws.

    Note: This function can be more efficient than calling upper_bound and lower_bound for lower_key and upper_key.

    Note: Experimental function, the interface might change. Additional notes: the first node of the range is splayed.

  35. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  lower_key, 
                     upper_key,  comp, 
                     left_closed,  right_closed);

    Requires: "header" must be the header node of a tree. KeyNodePtrCompare is a function object that induces a strict weak ordering compatible with the strict weak ordering used to create the the tree. KeyNodePtrCompare can compare KeyType with tree's node_ptrs. 'lower_key' must not be greater than 'upper_key' according to 'comp'. If 'lower_key' == 'upper_key', ('left_closed' || 'right_closed') must be true.

    Effects: Returns an a pair with the following criteria:

    first = lower_bound(lower_key) if left_closed, upper_bound(lower_key) otherwise

    second = upper_bound(upper_key) if right_closed, lower_bound(upper_key) otherwise

    Complexity: Logarithmic.

    Throws: If "comp" throws.

    Note: This function can be more efficient than calling upper_bound and lower_bound for lower_key and upper_key.

    Note: Experimental function, the interface might change. Additional note: no splaying is performed

  36. template<typename NodePtrCompare> 
       
      ( header,  new_node, 
                                comp);

    Requires: "h" must be the header node of a tree. NodePtrCompare is a function object that induces a strict weak ordering compatible with the strict weak ordering used to create the the tree. NodePtrCompare compares two node_ptrs.

    Effects: Inserts new_node into the tree before the upper bound according to "comp".

    Complexity: Average complexity for insert element is at most logarithmic.

    Throws: If "comp" throws. Additional note: the inserted node is splayed

  37. template<typename NodePtrCompare> 
       
      ( header,  new_node, 
                                comp);

    Requires: "h" must be the header node of a tree. NodePtrCompare is a function object that induces a strict weak ordering compatible with the strict weak ordering used to create the the tree. NodePtrCompare compares two node_ptrs.

    Effects: Inserts new_node into the tree before the lower bound according to "comp".

    Complexity: Average complexity for insert element is at most logarithmic.

    Throws: If "comp" throws. Additional note: the inserted node is splayed

  38. template<typename NodePtrCompare> 
       
      ( header,  hint,  new_node, 
                    comp);

    Requires: "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.

    Effects: 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).

    Complexity: Logarithmic in general, but it is amortized constant time if new_node is inserted immediately before "hint".

    Throws: If "comp" throws. Additional note: the inserted node is splayed

  39.  
    ( header,  pos,  new_node) ;

    Requires: "header" must be the header node of a tree. "pos" must be a valid iterator or header (end) node. "pos" must be an iterator pointing to the successor to "new_node" once inserted according to the order of already inserted nodes. This function does not check "pos" and this precondition must be guaranteed by the caller.

    Effects: Inserts new_node into the tree before "pos".

    Complexity: Constant-time.

    Throws: Nothing.

    Note: If "pos" is not the successor of the newly inserted "new_node" tree invariants might be broken. Additional note: the inserted node is splayed

  40.  ( header,  new_node) ;

    Requires: "header" must be the header node of a tree. "new_node" must be, according to the used ordering no less than the greatest inserted key.

    Effects: Inserts new_node into the tree before "pos".

    Complexity: Constant-time.

    Throws: Nothing.

    Note: If "new_node" is less than the greatest inserted key tree invariants are broken. This function is slightly faster than using "insert_before". Additional note: the inserted node is splayed

  41.  ( header,  new_node) ;

    Requires: "header" must be the header node of a tree. "new_node" must be, according to the used ordering, no greater than the lowest inserted key.

    Effects: Inserts new_node into the tree before "pos".

    Complexity: Constant-time.

    Throws: Nothing.

    Note: If "new_node" is greater than the lowest inserted key tree invariants are broken. This function is slightly faster than using "insert_before". Additional note: the inserted node is splayed

  42. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key, 
                           comp, 
                           commit_data);

    Additional note: nodes with the given key are splayed

  43. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  hint,  key, 
                           comp, 
                           commit_data);

    Additional note: nodes with the given key are splayed

  44.  ( header,  new_value, 
                                      commit_data) ;
  45.  ( p) ;

    Requires: p is a node of a tree.

    Effects: Returns true if p is the header of the tree.

    Complexity: Constant.

    Throws: Nothing.

  46.  ( header) ;

    Requires: header must be the header of a tree.

    Effects: Rebalances the tree.

    Throws: Nothing.

    Complexity: Linear.

  47.  ( old_root) ;

    Requires: old_root is a node of a tree. It shall not be null.

    Effects: Rebalances the subtree rooted at old_root.

    Returns: The new root of the subtree.

    Throws: Nothing.

    Complexity: Linear.

  48.  ( n,  header) ;
  49. template<typename KeyType, typename KeyNodePtrCompare> 
       
      ( header,  key,  comp, 
                  pfound = );

PrevUpHomeNext