diff options
author | Jie Chen <fykcee1@gmail.com> | 2016-12-12 19:46:17 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-12 21:55:09 -0500 |
commit | ce093a04543c403d52c1a5788d8cb92e47453aba (patch) | |
tree | 4f0dbd7ab08c3110cc45f2ce94662ea3e561c00c | |
parent | 6b2a65c7ff612035deb1012388738b54e08ab2a6 (diff) |
lib/rbtree.c: fix typo in comment of ____rb_erase_color
In Case 3 of `sibling == parent->rb_right':
Right rotation will not change color of sl and S in the diagram
(i.e. should not change "sl" to "Sl", "S" to "s")
In Case 3 of `sibling == parent->rb_left':
(p) (p)
/ \ / \
S N --> sr N
/ \ /
Sl sr S
/
Sl
This is actually left rotation at "S", not right rotation.
In Case 4 of `sibling == parent->rb_left':
(p) (s)
/ \ / \
S N --> Sl P
/ \ / \
sl (sr) (sr) N
This is actually right rotation at "(p)" + color flips, not left
rotation + color flips.
Link: http://lkml.kernel.org/r/1472391115-3702-1-git-send-email-fykcee1@gmail.com
Signed-off-by: Jie Chen <fykcee1@gmail.com>
Cc: Wei Yang <weiyang@linux.vnet.ibm.com>
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/rbtree.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c index eb8a19fee110..1f8b112a7c35 100644 --- a/lib/rbtree.c +++ b/lib/rbtree.c | |||
@@ -296,11 +296,26 @@ ____rb_erase_color(struct rb_node *parent, struct rb_root *root, | |||
296 | * | 296 | * |
297 | * (p) (p) | 297 | * (p) (p) |
298 | * / \ / \ | 298 | * / \ / \ |
299 | * N S --> N Sl | 299 | * N S --> N sl |
300 | * / \ \ | 300 | * / \ \ |
301 | * sl Sr s | 301 | * sl Sr S |
302 | * \ | 302 | * \ |
303 | * Sr | 303 | * Sr |
304 | * | ||
305 | * Note: p might be red, and then both | ||
306 | * p and sl are red after rotation(which | ||
307 | * breaks property 4). This is fixed in | ||
308 | * Case 4 (in __rb_rotate_set_parents() | ||
309 | * which set sl the color of p | ||
310 | * and set p RB_BLACK) | ||
311 | * | ||
312 | * (p) (sl) | ||
313 | * / \ / \ | ||
314 | * N sl --> P S | ||
315 | * \ / \ | ||
316 | * S N Sr | ||
317 | * \ | ||
318 | * Sr | ||
304 | */ | 319 | */ |
305 | tmp1 = tmp2->rb_right; | 320 | tmp1 = tmp2->rb_right; |
306 | WRITE_ONCE(sibling->rb_left, tmp1); | 321 | WRITE_ONCE(sibling->rb_left, tmp1); |
@@ -365,7 +380,7 @@ ____rb_erase_color(struct rb_node *parent, struct rb_root *root, | |||
365 | } | 380 | } |
366 | break; | 381 | break; |
367 | } | 382 | } |
368 | /* Case 3 - right rotate at sibling */ | 383 | /* Case 3 - left rotate at sibling */ |
369 | tmp1 = tmp2->rb_left; | 384 | tmp1 = tmp2->rb_left; |
370 | WRITE_ONCE(sibling->rb_right, tmp1); | 385 | WRITE_ONCE(sibling->rb_right, tmp1); |
371 | WRITE_ONCE(tmp2->rb_left, sibling); | 386 | WRITE_ONCE(tmp2->rb_left, sibling); |
@@ -377,7 +392,7 @@ ____rb_erase_color(struct rb_node *parent, struct rb_root *root, | |||
377 | tmp1 = sibling; | 392 | tmp1 = sibling; |
378 | sibling = tmp2; | 393 | sibling = tmp2; |
379 | } | 394 | } |
380 | /* Case 4 - left rotate at parent + color flips */ | 395 | /* Case 4 - right rotate at parent + color flips */ |
381 | tmp2 = sibling->rb_right; | 396 | tmp2 = sibling->rb_right; |
382 | WRITE_ONCE(parent->rb_left, tmp2); | 397 | WRITE_ONCE(parent->rb_left, tmp2); |
383 | WRITE_ONCE(sibling->rb_right, parent); | 398 | WRITE_ONCE(sibling->rb_right, parent); |