LWN: Comments on "Trees II: red-black trees" https://lwn.net/Articles/184495/ This is a special feed containing comments posted to the individual LWN article titled "Trees II: red-black trees". en-us Thu, 02 Oct 2025 07:54:26 +0000 Thu, 02 Oct 2025 07:54:26 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Trees II: red-black trees https://lwn.net/Articles/411900/ https://lwn.net/Articles/411900/ jlayton <div class="FormattedComment"> This is an older article, but it seems there are some mistakes. It says:<br> <p> void rb_link_node(struct rb_node *new_node,<br> struct rb_node *parent,<br> struct rb_node **link);<br> <p> ...which is all rb_node pointers (or pointers to pointers). But it declares this function:<br> <p> void my_rb_insert(struct rb_root *root, struct my_stuff *new)<br> <p> ...which has "new" as a struct my_stuff pointer. That function then calls:<br> <p> rb_link_node(new, parent, link);<br> rb_insert_color(new, root);<br> <p> ...shouldn't "new" in latter two calls be a pointer to the embedded rb_node?<br> <p> </div> Tue, 26 Oct 2010 18:18:20 +0000 Trees II: red-black trees https://lwn.net/Articles/360969/ https://lwn.net/Articles/360969/ acolin <div class="FormattedComment"> Thank you for the article!<br> <p> Note that in my_rb_insert parent must be initialized, otherwise it doesn't work. This can also be seen in example in rbtree.h. So,<br> <font class="QuotedText">&gt; struct rb_node **link = &amp;root-&gt;rb_node, *parent;</font><br> should be<br> <font class="QuotedText">&gt; struct rb_node **link = &amp;root-&gt;rb_node, *parent = NULL;</font><br> </div> Sat, 07 Nov 2009 23:55:32 +0000 Trees II: red-black trees https://lwn.net/Articles/284494/ https://lwn.net/Articles/284494/ bigt23 <div class="FormattedComment"><pre> nice article! thanks! </pre></div> Fri, 30 May 2008 06:20:10 +0000 Request clue-bat https://lwn.net/Articles/230034/ https://lwn.net/Articles/230034/ jengelh Bad form or not, it is also allowed in C++.<br> Wed, 11 Apr 2007 19:33:10 +0000 Binary trees considered harmful https://lwn.net/Articles/190348/ https://lwn.net/Articles/190348/ i3839 Well, who knows, maybe it has something to do with this: <pre>$ size Judy-1.0.3/src/obj/.libs/libJudy.so.1.0.3 text data bss dec hex filename 114515 760 160 115435 1c2eb Judy-1.0.3/src/obj/.libs/libJudy.so.1.0.3 $ size linux/lib/*tree*.o text data bss dec hex filename 1823 0 128 1951 79f linux/lib/prio_tree.o 2934 28 36 2998 bb6 linux/lib/radix-tree.o 1544 0 0 1544 608 linux/lib/rbtree.o</pre> For something which is avoiding cache misses as much as possible it seems a bit strange to be so bloated that the code to avoid all those cache misses causes so awfully lot cache misses itself. Of course, this isn't something you'll see when benchmarking the code...<br /><br /> Furthermore, whatever memory saving might be achieved by using Judy arrays, it has a long to go way before it made up for that 100K extra usage.<br /><br /> And to rub it in, hashes are almost as good as Judy arrays but are much simpler and smaller to implement. Only icky thing is their (re-)size problem, but that's less icky than a 100K footprint. Good b-tree (not a binary tree) implementations are also not significant worse.<br /><br /> I'm not trying to prove that Judy arrays are bad, they have their usages, but I do think that the kernel isn't the right place for them. Thu, 06 Jul 2006 16:49:27 +0000 Trees II: red-black trees https://lwn.net/Articles/189875/ https://lwn.net/Articles/189875/ wingo Thanks, nice article.<br> Mon, 03 Jul 2006 08:41:04 +0000 Binary trees considered harmful https://lwn.net/Articles/189742/ https://lwn.net/Articles/189742/ nix Yeah. It's a shame that the accessor macros and the code are so horribly named/unreadable. It's almost obfuscated-yet-heavily-commented...<br> Fri, 30 Jun 2006 15:56:09 +0000 Binary trees considered harmful https://lwn.net/Articles/189649/ https://lwn.net/Articles/189649/ cventers True, but so is RCU. I wonder if HP would give an explicit license to GPL <br> code (since they released the Judy library on Sourceforge as LGPL, along <br> with some "confidential" internal paper about Judy).<br> Thu, 29 Jun 2006 17:21:47 +0000 Request clue-bat https://lwn.net/Articles/189643/ https://lwn.net/Articles/189643/ ncm No, it's just defining two variables, and leaving one uninitialized. In C++ code this would be bad form, but in C89 you have to define variables at the top of the block, often before you're ready to initialize them to anything useful. The kernel isn't coded in C89, though; it requires Gcc. With recent releases of Gcc, if run with C99 support turned on, variables can be defined in the middle of a block. It's really only inertia supporting this unfortunate practice.<br> Thu, 29 Jun 2006 17:16:53 +0000 Binary trees considered harmful https://lwn.net/Articles/189639/ https://lwn.net/Articles/189639/ nix What a baroque and lovely data structure. Alas it seems it's tied up in software patents...<br> Thu, 29 Jun 2006 16:23:59 +0000 Request clue-bat https://lwn.net/Articles/189610/ https://lwn.net/Articles/189610/ smitty_one_each <font class="QuotedText">&gt;struct rb_node **link = &amp;root-&gt;rb_node, *parent;</font><br> <p> What is the effect of the comma? At first blush, we appear to be trying to assign two values to **link.<br> <p> Thu, 29 Jun 2006 11:58:36 +0000 Binary trees considered harmful https://lwn.net/Articles/189572/ https://lwn.net/Articles/189572/ ncm The author/designer of Judy Trees <a href="http://judy.sourceforge.net/doc/10minutes.htm">remarks</a> that, having measured them in comparison with other methods, "<i>It is truly remarkable to me how much research has been done on binary trees and [that they are] still being taught.</i>" Red-black trees are quaint, at best, nowadays. Replacing them in the kernel with a more cache-aware (or, better, cache-oblivious) alternative ought to be an easy way to speed up affected kernel operations, except that it appears it would require rewriting zillions of search and insert functions. It seems unfortunate that the design of the kernel rbtrees is so intrusive, but there may have been no choice, in C. Thu, 29 Jun 2006 09:04:44 +0000 Trees II: red-black trees https://lwn.net/Articles/189575/ https://lwn.net/Articles/189575/ opennw Wonderful article, thank you. I think the "root-*gt;rb_node;" in <i>my_rb_search()</i> should be "root->rb_node". (I suspect the "*" should be a "&amp;"). Thu, 29 Jun 2006 08:41:57 +0000 Trees II: red-black trees https://lwn.net/Articles/189564/ https://lwn.net/Articles/189564/ alonz I believe there is a small error in the insertion code: the line<br> <pre> struct my_stuff *stuff = rb_entry(parent, struct my_stuff, parent); </pre> should have been written as<br> <pre> struct my_stuff *stuff = rb_entry(parent, struct my_stuff, node); </pre> Thu, 29 Jun 2006 06:36:00 +0000