From: Wei Yang <weiyang@linux.vnet.ibm.com>
To: walken@google.com
Cc: linux-kernel@vger.kernel.org, Wei Yang <weiyang@linux.vnet.ibm.com>
Subject: [PATCH] rbtree: increase readability of __rb_erase_augmented()
Date: Sun, 23 Aug 2015 20:14:56 +0800 [thread overview]
Message-ID: <1440332096-7850-1-git-send-email-weiyang@linux.vnet.ibm.com> (raw)
__rb_erase_augmented() is the fundamental part of erase a node from rbtree,
while to some extend it is hard to understand.
This patch replaces some code with macro to make it more easy to
understand for audience.
1. rb_parent(node) replaces __rb_parent(pc)
2. rb_set_parent_color() replaces direct assignment of __rb_parent_color
3. rb_is_black(node) replaces __rb_is_black(pc)
4. merges the successor's parent/color change together after every thing is
set down.
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
---
include/linux/rbtree_augmented.h | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
index 14d7b83..f25a786 100644
--- a/include/linux/rbtree_augmented.h
+++ b/include/linux/rbtree_augmented.h
@@ -140,7 +140,6 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
struct rb_node *child = node->rb_right;
struct rb_node *tmp = node->rb_left;
struct rb_node *parent, *rebalance;
- unsigned long pc;
if (!tmp) {
/*
@@ -150,20 +149,19 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
* and node must be black due to 4). We adjust colors locally
* so as to bypass __rb_erase_color() later on.
*/
- pc = node->__rb_parent_color;
- parent = __rb_parent(pc);
+ parent = rb_parent(node);
__rb_change_child(node, child, parent, root);
if (child) {
- child->__rb_parent_color = pc;
+ rb_set_parent_color(child, parent, rb_color(node));
rebalance = NULL;
} else
- rebalance = __rb_is_black(pc) ? parent : NULL;
+ rebalance = rb_is_black(node) ? parent : NULL;
tmp = parent;
} else if (!child) {
/* Still case 1, but this time the child is node->rb_left */
- tmp->__rb_parent_color = pc = node->__rb_parent_color;
- parent = __rb_parent(pc);
+ parent = rb_parent(node);
__rb_change_child(node, tmp, parent, root);
+ rb_set_parent_color(tmp, parent, rb_color(node));
rebalance = NULL;
tmp = parent;
} else {
@@ -217,19 +215,15 @@ __rb_erase_augmented(struct rb_node *node, struct rb_root *root,
WRITE_ONCE(successor->rb_left, tmp);
rb_set_parent(tmp, successor);
- pc = node->__rb_parent_color;
- tmp = __rb_parent(pc);
+ tmp = rb_parent(node);
__rb_change_child(node, successor, tmp, root);
if (child2) {
- successor->__rb_parent_color = pc;
rb_set_parent_color(child2, parent, RB_BLACK);
rebalance = NULL;
- } else {
- unsigned long pc2 = successor->__rb_parent_color;
- successor->__rb_parent_color = pc;
- rebalance = __rb_is_black(pc2) ? parent : NULL;
- }
+ } else
+ rebalance = rb_is_black(successor) ? parent : NULL;
+ rb_set_parent_color(successor, tmp, rb_color(node));
tmp = successor;
}
--
2.5.0
reply other threads:[~2015-08-23 12:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440332096-7850-1-git-send-email-weiyang@linux.vnet.ibm.com \
--to=weiyang@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®