mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-03 14:34:44 +02:00
Applied pass by value to save copy constructors for pointers with non-trivial copy constructor and const node_ptr & to avoid creating temporaries.
[SVN r80575]
This commit is contained in:
@@ -172,18 +172,17 @@ class circular_slist_algorithms
|
||||
static node_ptr get_previous_previous_node(const node_ptr & this_node)
|
||||
{ return get_previous_previous_node(this_node, this_node); }
|
||||
|
||||
//! <b>Requires</b>: this_node and prev_prev_init_node must be in the same circular list.
|
||||
//! <b>Requires</b>: this_node and p must be in the same circular list.
|
||||
//!
|
||||
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the
|
||||
//! circular list starting. the search from prev_init_node. The first node checked
|
||||
//! for equality is NodeTraits::get_next((NodeTraits::get_next(prev_prev_init_node)).
|
||||
//! circular list starting. the search from p. The first node checked
|
||||
//! for equality is NodeTraits::get_next((NodeTraits::get_next(p)).
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
static node_ptr get_previous_previous_node(const node_ptr & prev_prev_init_node, const node_ptr & this_node)
|
||||
static node_ptr get_previous_previous_node(node_ptr p, const node_ptr & this_node)
|
||||
{
|
||||
node_ptr p = prev_prev_init_node;
|
||||
node_ptr p_next = NodeTraits::get_next(p);
|
||||
node_ptr p_next_next = NodeTraits::get_next(p_next);
|
||||
while (this_node != p_next_next){
|
||||
|
@@ -71,24 +71,36 @@ struct default_avltree_node_traits_impl
|
||||
static node_ptr get_parent(const const_node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static node_ptr get_parent(const node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static void set_parent(const node_ptr & n, const node_ptr & p)
|
||||
{ n->parent_ = p; }
|
||||
|
||||
static node_ptr get_left(const const_node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static node_ptr get_left(const node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static void set_left(const node_ptr & n, const node_ptr & l)
|
||||
{ n->left_ = l; }
|
||||
|
||||
static node_ptr get_right(const const_node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static node_ptr get_right(const node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static void set_right(const node_ptr & n, const node_ptr & r)
|
||||
{ n->right_ = r; }
|
||||
|
||||
static balance get_balance(const const_node_ptr & n)
|
||||
{ return n->balance_; }
|
||||
|
||||
static balance get_balance(const node_ptr & n)
|
||||
{ return n->balance_; }
|
||||
|
||||
static void set_balance(const node_ptr & n, balance b)
|
||||
{ n->balance_ = b; }
|
||||
|
||||
|
@@ -31,9 +31,8 @@ class common_slist_algorithms
|
||||
typedef typename NodeTraits::const_node_ptr const_node_ptr;
|
||||
typedef NodeTraits node_traits;
|
||||
|
||||
static node_ptr get_previous_node(const node_ptr & prev_init_node, const node_ptr & this_node)
|
||||
static node_ptr get_previous_node(node_ptr p, const node_ptr & this_node)
|
||||
{
|
||||
node_ptr p = prev_init_node;
|
||||
for( node_ptr p_next
|
||||
; this_node != (p_next = NodeTraits::get_next(p))
|
||||
; p = p_next){
|
||||
|
@@ -47,12 +47,18 @@ struct list_node_traits
|
||||
static node_ptr get_previous(const const_node_ptr & n)
|
||||
{ return n->prev_; }
|
||||
|
||||
static node_ptr get_previous(const node_ptr & n)
|
||||
{ return n->prev_; }
|
||||
|
||||
static void set_previous(const node_ptr & n, const node_ptr & prev)
|
||||
{ n->prev_ = prev; }
|
||||
|
||||
static node_ptr get_next(const const_node_ptr & n)
|
||||
{ return n->next_; }
|
||||
|
||||
static node_ptr get_next(const node_ptr & n)
|
||||
{ return n->next_; }
|
||||
|
||||
static void set_next(const node_ptr & n, const node_ptr & next)
|
||||
{ n->next_ = next; }
|
||||
};
|
||||
|
@@ -71,24 +71,36 @@ struct default_rbtree_node_traits_impl
|
||||
static node_ptr get_parent(const const_node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static node_ptr get_parent(const node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static void set_parent(const node_ptr & n, const node_ptr & p)
|
||||
{ n->parent_ = p; }
|
||||
|
||||
static node_ptr get_left(const const_node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static node_ptr get_left(const node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static void set_left(const node_ptr & n, const node_ptr & l)
|
||||
{ n->left_ = l; }
|
||||
|
||||
static node_ptr get_right(const const_node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static node_ptr get_right(const node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static void set_right(const node_ptr & n, const node_ptr & r)
|
||||
{ n->right_ = r; }
|
||||
|
||||
static color get_color(const const_node_ptr & n)
|
||||
{ return n->color_; }
|
||||
|
||||
static color get_color(const node_ptr & n)
|
||||
{ return n->color_; }
|
||||
|
||||
static void set_color(const node_ptr & n, color c)
|
||||
{ n->color_ = c; }
|
||||
|
||||
@@ -117,24 +129,36 @@ struct compact_rbtree_node_traits_impl
|
||||
static node_ptr get_parent(const const_node_ptr & n)
|
||||
{ return ptr_bit::get_pointer(n->parent_); }
|
||||
|
||||
static node_ptr get_parent(const node_ptr & n)
|
||||
{ return ptr_bit::get_pointer(n->parent_); }
|
||||
|
||||
static void set_parent(const node_ptr & n, const node_ptr & p)
|
||||
{ ptr_bit::set_pointer(n->parent_, p); }
|
||||
|
||||
static node_ptr get_left(const const_node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static node_ptr get_left(const node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static void set_left(const node_ptr & n, const node_ptr & l)
|
||||
{ n->left_ = l; }
|
||||
|
||||
static node_ptr get_right(const const_node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static node_ptr get_right(const node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static void set_right(const node_ptr & n, const node_ptr & r)
|
||||
{ n->right_ = r; }
|
||||
|
||||
static color get_color(const const_node_ptr & n)
|
||||
{ return (color)ptr_bit::get_bits(n->parent_); }
|
||||
|
||||
static color get_color(const node_ptr & n)
|
||||
{ return (color)ptr_bit::get_bits(n->parent_); }
|
||||
|
||||
static void set_color(const node_ptr & n, color c)
|
||||
{ ptr_bit::set_bits(n->parent_, c != 0); }
|
||||
|
||||
|
@@ -45,6 +45,9 @@ struct slist_node_traits
|
||||
static node_ptr get_next(const const_node_ptr & n)
|
||||
{ return n->next_; }
|
||||
|
||||
static node_ptr get_next(const node_ptr & n)
|
||||
{ return n->next_; }
|
||||
|
||||
static void set_next(const node_ptr & n, const node_ptr & next)
|
||||
{ n->next_ = next; }
|
||||
};
|
||||
|
@@ -485,15 +485,14 @@ class tree_algorithms
|
||||
//! <b>Complexity</b>: Logarithmic to the size of the subtree.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
static node_ptr minimum (const node_ptr & node)
|
||||
static node_ptr minimum (node_ptr node)
|
||||
{
|
||||
node_ptr p(node);
|
||||
for(node_ptr p_left = NodeTraits::get_left(p)
|
||||
for(node_ptr p_left = NodeTraits::get_left(node)
|
||||
;p_left
|
||||
;p_left = NodeTraits::get_left(p)){
|
||||
p = p_left;
|
||||
;p_left = NodeTraits::get_left(node)){
|
||||
node = p_left;
|
||||
}
|
||||
return p;
|
||||
return node;
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: 'node' is a node of a tree but not the header.
|
||||
@@ -503,15 +502,14 @@ class tree_algorithms
|
||||
//! <b>Complexity</b>: Logarithmic to the size of the subtree.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
static node_ptr maximum(const node_ptr & node)
|
||||
static node_ptr maximum(node_ptr node)
|
||||
{
|
||||
node_ptr p(node);
|
||||
for(node_ptr p_right = NodeTraits::get_right(p)
|
||||
for(node_ptr p_right = NodeTraits::get_right(node)
|
||||
;p_right
|
||||
;p_right = NodeTraits::get_right(p)){
|
||||
p = p_right;
|
||||
;p_right = NodeTraits::get_right(node)){
|
||||
node = p_right;
|
||||
}
|
||||
return p;
|
||||
return node;
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: 'node' must not be part of any tree.
|
||||
@@ -1171,14 +1169,13 @@ class tree_algorithms
|
||||
//! <b>Complexity</b>: Logarithmic to the number of nodes in the tree.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
static std::size_t depth(const const_node_ptr & node)
|
||||
static std::size_t depth(const_node_ptr node)
|
||||
{
|
||||
const_node_ptr p(node);
|
||||
std::size_t depth = 0;
|
||||
node_ptr p_parent;
|
||||
while(p != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(p))){
|
||||
while(node != NodeTraits::get_parent(p_parent = NodeTraits::get_parent(node))){
|
||||
++depth;
|
||||
p = p_parent;
|
||||
node = p_parent;
|
||||
}
|
||||
return depth;
|
||||
}
|
||||
@@ -1295,12 +1292,10 @@ class tree_algorithms
|
||||
}
|
||||
|
||||
template<class Disposer>
|
||||
static void dispose_subtree(const node_ptr & node, Disposer disposer)
|
||||
static void dispose_subtree(node_ptr x, Disposer disposer)
|
||||
{
|
||||
node_ptr save;
|
||||
node_ptr x(node);
|
||||
while (x){
|
||||
save = NodeTraits::get_left(x);
|
||||
node_ptr save(NodeTraits::get_left(x));
|
||||
if (save) {
|
||||
// Right rotation
|
||||
NodeTraits::set_left(x, NodeTraits::get_right(save));
|
||||
|
@@ -44,18 +44,27 @@ struct tree_node_traits
|
||||
static node_ptr get_parent(const const_node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static node_ptr get_parent(const node_ptr & n)
|
||||
{ return n->parent_; }
|
||||
|
||||
static void set_parent(const node_ptr & n, const node_ptr & p)
|
||||
{ n->parent_ = p; }
|
||||
|
||||
static node_ptr get_left(const const_node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static node_ptr get_left(const node_ptr & n)
|
||||
{ return n->left_; }
|
||||
|
||||
static void set_left(const node_ptr & n, const node_ptr & l)
|
||||
{ n->left_ = l; }
|
||||
|
||||
static node_ptr get_right(const const_node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static node_ptr get_right(const node_ptr & n)
|
||||
{ return n->right_; }
|
||||
|
||||
static void set_right(const node_ptr & n, const node_ptr & r)
|
||||
{ n->right_ = r; }
|
||||
};
|
||||
|
@@ -805,26 +805,26 @@ class rbtree_algorithms
|
||||
// NodeTraits::get_parent(NodeTraits::get_parent(p)) == p;
|
||||
}
|
||||
|
||||
static void rebalance_after_erasure(const node_ptr & header, const node_ptr &xnode, const node_ptr &xnode_parent)
|
||||
static void rebalance_after_erasure(const node_ptr & header, node_ptr x, node_ptr x_parent)
|
||||
{
|
||||
node_ptr x(xnode), x_parent(xnode_parent);
|
||||
while(x != NodeTraits::get_parent(header) && (x == node_ptr() || NodeTraits::get_color(x) == NodeTraits::black())){
|
||||
while(x != NodeTraits::get_parent(header) && (!x || NodeTraits::get_color(x) == NodeTraits::black())){
|
||||
if(x == NodeTraits::get_left(x_parent)){
|
||||
node_ptr w = NodeTraits::get_right(x_parent);
|
||||
BOOST_ASSERT(w);
|
||||
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) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()) &&
|
||||
(NodeTraits::get_right(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black())){
|
||||
if((!NodeTraits::get_left(w) || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()) &&
|
||||
(!NodeTraits::get_right(w) || 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) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()){
|
||||
if(!NodeTraits::get_right(w) || 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);
|
||||
@@ -847,14 +847,14 @@ class rbtree_algorithms
|
||||
tree_algorithms::rotate_right(x_parent, header);
|
||||
w = NodeTraits::get_left(x_parent);
|
||||
}
|
||||
if((NodeTraits::get_right(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()) &&
|
||||
(NodeTraits::get_left(w) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black())){
|
||||
if((!NodeTraits::get_right(w) || NodeTraits::get_color(NodeTraits::get_right(w)) == NodeTraits::black()) &&
|
||||
(!NodeTraits::get_left(w) || 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) == node_ptr() || NodeTraits::get_color(NodeTraits::get_left(w)) == NodeTraits::black()){
|
||||
if(!NodeTraits::get_left(w) || 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);
|
||||
@@ -874,9 +874,8 @@ class rbtree_algorithms
|
||||
}
|
||||
|
||||
|
||||
static void rebalance_after_insertion(const node_ptr & header, const node_ptr &pnode)
|
||||
static void rebalance_after_insertion(const node_ptr & header, node_ptr p)
|
||||
{
|
||||
node_ptr p(pnode);
|
||||
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));
|
||||
|
Reference in New Issue
Block a user