Ejemplo n.º 1
0
static void rb_tree_insert_case3(RBTree *tree, RBTreeNode *node)
{
	RBTreeNode *grandparent;
	RBTreeNode *uncle;

	/* Note that the node must have a grandparent, as the parent
	 * is red, and the root node is always black. */

	grandparent = node->parent->parent;
	uncle = rb_tree_node_uncle(node);

	if (uncle != NULL && uncle->color == RB_TREE_NODE_RED) {

		node->parent->color = RB_TREE_NODE_BLACK;
		uncle->color = RB_TREE_NODE_BLACK;
		grandparent->color = RB_TREE_NODE_RED;

		/* Recurse to grandparent */

		rb_tree_insert_case1(tree, grandparent);

	} else {
		rb_tree_insert_case4(tree, node);
	}
}
Ejemplo n.º 2
0
static void rb_tree_insert_case3(rb_node_t *node)
{
    rb_node_t *u = uncle(node);

    //LOG_DBG("inserting case 3\n");

    if (u && u->color == RB_COLOR_RED) {
        rb_node_t *g;
        node->parent->color = RB_COLOR_BLACK;
        u->color = RB_COLOR_BLACK;
        g = grandparent(node);
        g->color = RB_COLOR_RED;
        rb_tree_insert_case1(g);
    } else {
        rb_tree_insert_case4(node);
    }
}