diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2017-09-08 19:14:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:48 -0400 |
commit | 35dc67d7d922b2c9a1adb006c7a0f370eeb5c114 (patch) | |
tree | 5f9f7154581152b4557d7cf7e64179fccbc02209 /lib/rbtree.c | |
parent | 2aadf7fc7df9e70c99786ffb8452ccdd83d49e59 (diff) |
rbtree: add some additional comments for rebalancing cases
While overall the code is very nicely commented, it might not be
immediately obvious from the diagrams what is going on. Add a very
brief summary of each case. Opposite cases where the node is the left
child are left untouched.
Link: http://lkml.kernel.org/r/20170719014603.19029-4-dave@stgolabs.net
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/rbtree.c')
-rw-r--r-- | lib/rbtree.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c index e7cce12f404f..ba4a9d165f1b 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -132,7 +132,7 @@ __rb_insert(struct rb_node *node, struct rb_root *root, | |||
132 | if (parent != tmp) { /* parent == gparent->rb_left */ | 132 | if (parent != tmp) { /* parent == gparent->rb_left */ |
133 | if (tmp && rb_is_red(tmp)) { | 133 | if (tmp && rb_is_red(tmp)) { |
134 | /* | 134 | /* |
135 | * Case 1 - color flips | 135 | * Case 1 - node's uncle is red (color flips). |
136 | * | 136 | * |
137 | * G g | 137 | * G g |
138 | * / \ / \ | 138 | * / \ / \ |
@@ -155,7 +155,8 @@ __rb_insert(struct rb_node *node, struct rb_root *root, | |||
155 | tmp = parent->rb_right; | 155 | tmp = parent->rb_right; |
156 | if (node == tmp) { | 156 | if (node == tmp) { |
157 | /* | 157 | /* |
158 | * Case 2 - left rotate at parent | 158 | * Case 2 - node's uncle is black and node is |
159 | * the parent's right child (left rotate at parent). | ||
159 | * | 160 | * |
160 | * G G | 161 | * G G |
161 | * / \ / \ | 162 | * / \ / \ |
@@ -179,7 +180,8 @@ __rb_insert(struct rb_node *node, struct rb_root *root, | |||
179 | } | 180 | } |
180 | 181 | ||
181 | /* | 182 | /* |
182 | * Case 3 - right rotate at gparent | 183 | * Case 3 - node's uncle is black and node is |
184 | * the parent's left child (right rotate at gparent). | ||
183 | * | 185 | * |
184 | * G P | 186 | * G P |
185 | * / \ / \ | 187 | * / \ / \ |