aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMichel Lespinasse <walken@google.com>2012-10-08 19:30:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-09 03:22:32 -0400
commitbf7ad8eeab995710c766df49c9c69a8592ca0216 (patch)
tree737988d677b8ea408a44a58a949cc0e8eda02440 /lib
parentea5272f5c94fb2ee62f4f15a5b88eef6184cd506 (diff)
rbtree: move some implementation details from rbtree.h to rbtree.c
rbtree users must use the documented APIs to manipulate the tree structure. Low-level helpers to manipulate node colors and parenthood are not part of that API, so move them to lib/rbtree.c [dwmw2@infradead.org: fix jffs2 build issue due to renamed __rb_parent_color field] Signed-off-by: Michel Lespinasse <walken@google.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Acked-by: David Woodhouse <David.Woodhouse@intel.com> Cc: Rik van Riel <riel@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Daniel Santos <daniel.santos@pobox.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/rbtree.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/rbtree.c b/lib/rbtree.c
index fe43c8c5f527..ccada9abe6f5 100644
--- a/lib/rbtree.c
+++ b/lib/rbtree.c
@@ -23,6 +23,24 @@
23#include <linux/rbtree.h> 23#include <linux/rbtree.h>
24#include <linux/export.h> 24#include <linux/export.h>
25 25
26#define RB_RED 0
27#define RB_BLACK 1
28
29#define rb_color(r) ((r)->__rb_parent_color & 1)
30#define rb_is_red(r) (!rb_color(r))
31#define rb_is_black(r) rb_color(r)
32#define rb_set_red(r) do { (r)->__rb_parent_color &= ~1; } while (0)
33#define rb_set_black(r) do { (r)->__rb_parent_color |= 1; } while (0)
34
35static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
36{
37 rb->__rb_parent_color = rb_color(rb) | (unsigned long)p;
38}
39static inline void rb_set_color(struct rb_node *rb, int color)
40{
41 rb->__rb_parent_color = (rb->__rb_parent_color & ~1) | color;
42}
43
26static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) 44static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
27{ 45{
28 struct rb_node *right = node->rb_right; 46 struct rb_node *right = node->rb_right;
@@ -255,7 +273,7 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
255 rb_set_parent(old->rb_right, node); 273 rb_set_parent(old->rb_right, node);
256 } 274 }
257 275
258 node->rb_parent_color = old->rb_parent_color; 276 node->__rb_parent_color = old->__rb_parent_color;
259 node->rb_left = old->rb_left; 277 node->rb_left = old->rb_left;
260 rb_set_parent(old->rb_left, node); 278 rb_set_parent(old->rb_left, node);
261 279