Re: RB tree

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Wendy Cheng
Subject: Re: RB tree
Date: Wednesday, March 10, 2010 - 11:06 am

I don't have kernel source code handy but iirc ...

Linux RB tree uses the same field (rb_parent_color in your example) to 
store two information: the pointer to the parent node AND the color of 
the node. The purpose (my guess) is to reduce the memory requirement (so 
you only need one word, instead of two, in a 32-bit platform).

This implies if you want the color, you take the last bit. If you want 
to work on parent address, you have to wipe out the last bit. The "~3" 
in the rb_parent() macro is just to make the code more readable (again, 
my guess) since this structure is normally aligned. Check its header 
file (or http://en.wikipedia.org/wiki/Red-black_tree) for details.

Hopefully I interpret your question right.

-- Wendy


Alberich de megres wrote:


--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
RB tree, Alberich de megres, (Wed Mar 10, 4:07 am)
Re: RB tree, Wendy Cheng, (Wed Mar 10, 11:06 am)