Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 332399
b: refs/heads/master
c: 60670b8
h: refs/heads/master
i:
  332397: 3bdadc2
  332395: a810d5a
  332391: 7966a2f
  332383: 2a9de6c
v: v3
  • Loading branch information
Michel Lespinasse authored and Linus Torvalds committed Oct 9, 2012
1 parent 7608469 commit e98962a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7abc704ae399fcb9c51ca200b0456f8a975a8011
refs/heads/master: 60670b8034d6e2ba860af79c9379b7788d09db73
35 changes: 18 additions & 17 deletions trunk/lib/rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,17 +368,28 @@ static void __rb_erase_color(struct rb_node *node, struct rb_node *parent,

void rb_erase(struct rb_node *node, struct rb_root *root)
{
struct rb_node *child, *parent;
struct rb_node *child = node->rb_right, *tmp = node->rb_left;
struct rb_node *parent;
int color;

if (!node->rb_left)
child = node->rb_right;
else if (!node->rb_right)
child = node->rb_left;
else {
if (!tmp) {
case1:
/* Case 1: node to erase has no more than 1 child (easy!) */

parent = rb_parent(node);
color = rb_color(node);

if (child)
rb_set_parent(child, parent);
__rb_change_child(node, child, parent, root);
} else if (!child) {
/* Still case 1, but this time the child is node->rb_left */
child = tmp;
goto case1;
} else {
struct rb_node *old = node, *left;

node = node->rb_right;
node = child;
while ((left = node->rb_left) != NULL)
node = left;

Expand All @@ -402,18 +413,8 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
node->__rb_parent_color = old->__rb_parent_color;
node->rb_left = old->rb_left;
rb_set_parent(old->rb_left, node);

goto color;
}

parent = rb_parent(node);
color = rb_color(node);

if (child)
rb_set_parent(child, parent);
__rb_change_child(node, child, parent, root);

color:
if (color == RB_BLACK)
__rb_erase_color(child, parent, root);
}
Expand Down

0 comments on commit e98962a

Please sign in to comment.