lkml.org 
[lkml]   [2012]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 04/13] rbtree: move some implementation details from rbtree.h to rbtree.c
Date
From
On Tue, 10 Jul 2012 01:35:14 +0200, Michel Lespinasse <walken@google.com> wrote:

> 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
>
> Signed-off-by: Michel Lespinasse <walken@google.com>
> ---
> include/linux/rbtree.h | 16 ----------------
> lib/rbtree.c | 18 ++++++++++++++++++
> 2 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
> index 2049087..a06c044 100644
> --- a/include/linux/rbtree.h
> +++ b/include/linux/rbtree.h
> @@ -35,8 +35,6 @@
> struct rb_node
> {
> unsigned long rb_parent_color;
> -#define RB_RED 0
> -#define RB_BLACK 1
> struct rb_node *rb_right;
> struct rb_node *rb_left;
> } __attribute__((aligned(sizeof(long))));
> @@ -49,20 +47,6 @@ struct rb_root
> #define rb_parent(r) ((struct rb_node *)((r)->rb_parent_color & ~3))
> -#define rb_color(r) ((r)->rb_parent_color & 1)
> -#define rb_is_red(r) (!rb_color(r))
> -#define rb_is_black(r) rb_color(r)
> -#define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0)
> -#define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0)
> -
> -static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
> -{
> - rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
> -}
> -static inline void rb_set_color(struct rb_node *rb, int color)
> -{
> - rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
> -}
> #define RB_ROOT (struct rb_root) { NULL, }
> #define rb_entry(ptr, type, member) container_of(ptr, type, member)
> diff --git a/lib/rbtree.c b/lib/rbtree.c
> index fe43c8c..d0ec339 100644
> --- a/lib/rbtree.c
> +++ b/lib/rbtree.c
> @@ -23,6 +23,24 @@
> #include <linux/rbtree.h>
> #include <linux/export.h>
>+#define RB_RED 0
> +#define RB_BLACK 1

Interestingly, those are almost never used. RB_BLACK is used only once.
Should we get rid of those instead? Or change the code (like rb_is_red())
to use them?

> +
> +#define rb_color(r) ((r)->rb_parent_color & 1)
> +#define rb_is_red(r) (!rb_color(r))
> +#define rb_is_black(r) rb_color(r)
> +#define rb_set_red(r) do { (r)->rb_parent_color &= ~1; } while (0)
> +#define rb_set_black(r) do { (r)->rb_parent_color |= 1; } while (0)
> +
> +static inline void rb_set_parent(struct rb_node *rb, struct rb_node *p)
> +{
> + rb->rb_parent_color = (rb->rb_parent_color & 3) | (unsigned long)p;
> +}
> +static inline void rb_set_color(struct rb_node *rb, int color)
> +{
> + rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
> +}
> +
> static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
> {
> struct rb_node *right = node->rb_right;


--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2012-07-10 15:01    [W:0.289 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site