void rb_tree_insert_case4(RBTree *tree, RBTreeNode *node) { RBTreeNode *next_node; RBTreeNodeSide side; /* Note that at this point, by implication from case 3, we know * that the parent is red, but the uncle is black. We therefore * only need to examine what side the node is on relative * to its parent, and the side the parent is on relative to * the grandparent. */ side = rb_tree_node_side(node); if (side != rb_tree_node_side(node->parent)) { /* After the rotation, we will continue to case 5, but * the parent node will be at the bottom. */ next_node = node->parent; /* Rotate around the parent in the opposite direction * to side. */ rb_tree_rotate(tree, node->parent, 1-side); } else { next_node = node; } rb_tree_insert_case5(tree, next_node); }
static void rb_tree_insert_case4(rb_node_t *node) { rb_node_t *g = grandparent(node); /* LOG_DBG("inserting case 4 parent_c=%d uncle_c=%d\n", node->parent->color, uncle(node) ? uncle(node)->color : 0); */ if (node->parent->right == node && node->parent == g->left) { rb_tree_rotate_left_side_left(node->parent); node = node->left; } else if (node->parent->left == node && node->parent == g->right) { rb_tree_rotate_right_side_right(node->parent); node = node->right; } if (node) rb_tree_insert_case5(node); }