linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RB tree
@ 2010-03-10 11:07 Alberich de megres
  2010-03-10 18:06 ` Wendy Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Alberich de megres @ 2010-03-10 11:07 UTC (permalink / raw)
  To: linux-fsdevel

Hi!

I know this could be a stupid question, but taking a look at rbtree
kernel imprelantacion used in ext3 fs, I understand what lines do, but
i could not see what the use it (i'm not telling it is pointless, only
that i didn't understand why its doing what its doing)

I can see it's zeroing last 2 bits on the rb_parent_color:
#define rb_parent(r)   ((struct rb_node *)((r)->rb_parent_color & ~3))

We are getting only last bit:
#define rb_color(r)   ((r)->rb_parent_color & 1)

Setting or clearing the last bit:
#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)


And here, comes my trouble:
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;
}
we are aligning the pointer address??


Thanks for the patience!!

Alberich

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-10 18:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-10 11:07 RB tree Alberich de megres
2010-03-10 18:06 ` Wendy Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).