Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 332390
b: refs/heads/master
c: 6d58452
h: refs/heads/master
v: v3
  • Loading branch information
Michel Lespinasse authored and Linus Torvalds committed Oct 9, 2012
1 parent ed8601c commit f8b9c14
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 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: 1f0528653e41ec230c60f5738820e8a544731399
refs/heads/master: 6d58452dc066db61acdff7b84671db1b11a3de1c
19 changes: 15 additions & 4 deletions trunk/lib/rbtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,21 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
{
struct rb_node *parent, *gparent;

while ((parent = rb_parent(node)) && rb_is_red(parent))
{
while (true) {
/*
* Loop invariant: node is red
*
* If there is a black parent, we are done.
* Otherwise, take some corrective action as we don't
* want a red root or two consecutive red nodes.
*/
parent = rb_parent(node);
if (!parent) {
rb_set_black(node);
break;
} else if (rb_is_black(parent))
break;

gparent = rb_parent(parent);

if (parent == gparent->rb_left)
Expand Down Expand Up @@ -142,8 +155,6 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root)
break;
}
}

rb_set_black(root->rb_node);
}
EXPORT_SYMBOL(rb_insert_color);

Expand Down

0 comments on commit f8b9c14

Please sign in to comment.