Example #1
0
void rb_delete(rbt *T, rbn *z)
{
	rbn *x, *y = z;
	COLOR y_original_color = y->color;
	if (z->left == T->nil) {
		x = z->right;
		rb_transplant(T, z, z->right);
	} else if (z->right == T->nil) {
		x = z->left;
		rb_transplant(T, z, z->left);
	} else {
		y = rb_minimum(T, z->right);
		y_original_color = y->color;
		x = y->right;
		if (y->p == z)
			x->p = y;
		else {
			rb_transplant(T, y, y->right);
			y->right = z->right;
			y->right->p = y;
		}
		rb_transplant(T, z, y);
		y->left = z->left;
		y->left->p = y;
		y->color = z->color;
	}
	if (y_original_color == BLACK)
		rb_delete_fixup(T, x);
}
Example #2
0
static rb_node_t *rb_successor(rb_tree *tree,rb_node_t *x) {
    rb_node_t *y;
    if (x->right != tree->nil) {
        return rb_minimum(tree, x->right);
    }
    y = x->parent;
    while (y != tree->nil && x == y->right) {
        x = y;
        y = y->parent;
    }
    return y;
}
Example #3
0
RBTree::Node *RBTree::rb_successor(Node *nd)
{
	if(nd == NIL)
		return NIL;

	if(nd->right!=NIL)
		return rb_minimum(nd->right);

	while(nd->parent!=NIL && nd!=nd->parent->left)
		nd = nd->parent;
	return nd->parent;
}
Example #4
0
rb_node_t* rb_successor(rb_node_t* nodex)
{
	rb_node_t* nodey;

	if(nodex->rchild != &nil)
	{
		return rb_minimum(nodex->rchild);
	}

	nodey = nodex->parent;
	while (nodey != &nil && nodex == nodey->rchild)
	{
		nodex = nodey;
		nodey = nodey->parent;
	}
	return nodey;
}
Example #5
0
void
k_rbtree_delete(k_rbtree_t* t,k_rbnode_t* z)
{
        /*  y's postion is the really to be delete,
         *   move y to z's position  and move x to y's postion
         */
        k_rbnode_t* y = z;
        k_rbnode_t* x = t->nil_node;

        enum k_color_type_t y_old_color = y->color;

        if(z->left == t->nil_node){//if one of z's child is nil move the other child to z;
                x = z->right;
                rb_transplant(t,z,z->right);
        }else if(z->right == t->nil_node){
                x = z->left;
                rb_transplant(t,z,z->left);
        }else{// y to be z's successor
                y = rb_minimum(t,z->right);
                y_old_color = y->color;
                x = y->right;

                //since y has no left child then move y's right to be y
                if(y->parent == z){//move x to y's postion
                        x->parent = z;
                }else{
                        rb_transplant(t,y,x);
                        y->right = z->right;
                        y->right->parent = y;
                }
                // move y to z's postion
                rb_transplant(t,z,y);
                y->left = z->left;
                y->left->parent = y;
                y->color = z->color;

        }

        if(y_old_color == k_color_black){
                k_rbtree_delete_fixup(t,x);
        }

}