<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: B-tree vs. Binary Search Tree</title>
	<atom:link href="http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/feed/" rel="self" type="application/rss+xml" />
	<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 22 Oct 2009 21:42:43 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: attractivechaos</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-239</link>
		<dc:creator>attractivechaos</dc:creator>
		<pubDate>Tue, 29 Sep 2009 11:42:50 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-239</guid>
		<description>@alohaeverafter

You may read my other posts about efficient generic programming in C. For generic C libraries, GDSL/Glib uses void*, which may have efficiency issue. &lt;a href=&quot;http://sglib.sourceforge.net/&quot; rel=&quot;nofollow&quot;&gt;Sglib&lt;/a&gt; and &lt;a href=&quot;http://nothings.org/&quot; rel=&quot;nofollow&quot;&gt;Sean&#039;s Tool Box&lt;/a&gt; use macros, although sglib does not use the best algorithm at least for rb-tree. For generic RB-tree, &lt;a href=&quot;http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/tree.h&quot; rel=&quot;nofollow&quot;&gt;Niels Provos&#039; tree library&lt;/a&gt; is recommended due to its performance and stability. For generic hash table libraries in C, I recommend my own implementation.

STL is the work of several phenomenal programmers who have considerable influence over the C++ programming. It is difficult for a common/unknown programmer to write something widely accepted by the C community. In addition, good C programmers, like me, love to reinvent the wheel. They do not rely too much on existing libraries as much as C++ programmers do.</description>
		<content:encoded><![CDATA[<p>@alohaeverafter</p>
<p>You may read my other posts about efficient generic programming in C. For generic C libraries, GDSL/Glib uses void*, which may have efficiency issue. <a href="http://sglib.sourceforge.net/" rel="nofollow">Sglib</a> and <a href="http://nothings.org/" rel="nofollow">Sean&#8217;s Tool Box</a> use macros, although sglib does not use the best algorithm at least for rb-tree. For generic RB-tree, <a href="http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/tree.h" rel="nofollow">Niels Provos&#8217; tree library</a> is recommended due to its performance and stability. For generic hash table libraries in C, I recommend my own implementation.</p>
<p>STL is the work of several phenomenal programmers who have considerable influence over the C++ programming. It is difficult for a common/unknown programmer to write something widely accepted by the C community. In addition, good C programmers, like me, love to reinvent the wheel. They do not rely too much on existing libraries as much as C++ programmers do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alohaeverafter</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-238</link>
		<dc:creator>alohaeverafter</dc:creator>
		<pubDate>Tue, 29 Sep 2009 10:55:21 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-238</guid>
		<description>What’s more important, C++ programmers have STL. but most C programmers have to achieve generic programming at the cost of efficiency. I want to change this. Although the .h source code is hard to read, the API does not look so bad. What do you think? Do you have better ideas? I am still exploring the methods.
&lt;a href=&quot;http://www.thebootcd.com&quot; rel=&quot;nofollow&quot;&gt;www.thebootcd.com&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>What’s more important, C++ programmers have STL. but most C programmers have to achieve generic programming at the cost of efficiency. I want to change this. Although the .h source code is hard to read, the API does not look so bad. What do you think? Do you have better ideas? I am still exploring the methods.<br />
<a href="http://www.thebootcd.com" rel="nofollow">http://www.thebootcd.com</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MikeJ</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-208</link>
		<dc:creator>MikeJ</dc:creator>
		<pubDate>Fri, 17 Jul 2009 12:42:59 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-208</guid>
		<description>So for a container keeping tags (strings or longs) and some pointer to a real struct of data with ability to find, getnext, add, delete items in the container khash or kbtree? I realize my mileage may vary just curious your thoughts between the two.</description>
		<content:encoded><![CDATA[<p>So for a container keeping tags (strings or longs) and some pointer to a real struct of data with ability to find, getnext, add, delete items in the container khash or kbtree? I realize my mileage may vary just curious your thoughts between the two.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: attractivechaos</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-206</link>
		<dc:creator>attractivechaos</dc:creator>
		<pubDate>Fri, 17 Jul 2009 08:11:15 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-206</guid>
		<description>@MikeJ

You can put the key and value in one struct:

typedef struct { int key, val; } cell_t;

and

#define cell_cmp(a, b) (((a).key &gt; (b).key) - ((a).key &lt; (b).key)

thus the B-tree is only built for cell_t::key and you can save other information in val.

In fact, STL hash_map is also implemented in a similar way.</description>
		<content:encoded><![CDATA[<p>@MikeJ</p>
<p>You can put the key and value in one struct:</p>
<p>typedef struct { int key, val; } cell_t;</p>
<p>and</p>
<p>#define cell_cmp(a, b) (((a).key &gt; (b).key) &#8211; ((a).key &lt; (b).key)</p>
<p>thus the B-tree is only built for cell_t::key and you can save other information in val.</p>
<p>In fact, STL hash_map is also implemented in a similar way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MikeJ</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-205</link>
		<dc:creator>MikeJ</dc:creator>
		<pubDate>Thu, 16 Jul 2009 19:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-205</guid>
		<description>In KBtree.h, where does one associate a value with a key similar to your hash? For example, you a key of str and data to associate with the key of (struct *x).  I don&#039;t see anyplace to associate data with keys.</description>
		<content:encoded><![CDATA[<p>In KBtree.h, where does one associate a value with a key similar to your hash? For example, you a key of str and data to associate with the key of (struct *x).  I don&#8217;t see anyplace to associate data with keys.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: attractivechaos</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-97</link>
		<dc:creator>attractivechaos</dc:creator>
		<pubDate>Sun, 28 Sep 2008 04:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-97</guid>
		<description>I meant to try Judy, but I did not know how to use Judy in 5 minutes and I gave up. Well, I should have tried further.

Although I have not tried, I tend to believe it may have a better performance than my B-tree implementatin. You can have a look at &lt;a href=&quot;http://www.nothings.org/computer/judy/&quot; rel=&quot;nofollow&quot;&gt;this page&lt;/a&gt;, where a Judy hash table is compared with a traditional hash table. It seems to me that conclusion is on random input, Judy is comparable to hash table. Sean&#039;s hash table has similar speed to my khash.h and in my hash table benchmark, khash.h is times faster than kbtree.h with slightly larger memory footprint. Putting all these together, I think Judy is probably faster than my kbtree.h.

I will try to do an experiment.</description>
		<content:encoded><![CDATA[<p>I meant to try Judy, but I did not know how to use Judy in 5 minutes and I gave up. Well, I should have tried further.</p>
<p>Although I have not tried, I tend to believe it may have a better performance than my B-tree implementatin. You can have a look at <a href="http://www.nothings.org/computer/judy/" rel="nofollow">this page</a>, where a Judy hash table is compared with a traditional hash table. It seems to me that conclusion is on random input, Judy is comparable to hash table. Sean&#8217;s hash table has similar speed to my khash.h and in my hash table benchmark, khash.h is times faster than kbtree.h with slightly larger memory footprint. Putting all these together, I think Judy is probably faster than my kbtree.h.</p>
<p>I will try to do an experiment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsh</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-95</link>
		<dc:creator>jsh</dc:creator>
		<pubDate>Sun, 28 Sep 2008 03:16:57 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-95</guid>
		<description>how does this perform vs a judy array. http://judy.sourceforge.net/</description>
		<content:encoded><![CDATA[<p>how does this perform vs a judy array. <a href="http://judy.sourceforge.net/" rel="nofollow">http://judy.sourceforge.net/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: attractivechaos</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-93</link>
		<dc:creator>attractivechaos</dc:creator>
		<pubDate>Fri, 26 Sep 2008 11:59:07 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-93</guid>
		<description>Thanks person and Reid for directing me to the cache-oblivious algorithms. I have just spent a few hours on what it is and what resources are available.

I could vaguely see what cache-oblivious algorithms are and the advantages of them, but I do not how to implement one really. I a bit doubt B-tree is not cache-oblivious, though.

Cache-oblivioius algorithms are pretty limited to the academic world. And my understanding of this world is people here care more about theoretical performance rather than practical. They try to reduce the number of theoretical cache misses at cost of adding more operations. The resultant program might not be faster in practice. I was also trying to find actual code on cache-oblivious search tree and the only code I can find claims that their cache-oblivious red-black tree is far slower than SGI STL&#039;s implementation. I think I will stop here unless someone could give me source code and so I can benchmark it. It is really a pain to implement one by myself while getting a worse result.</description>
		<content:encoded><![CDATA[<p>Thanks person and Reid for directing me to the cache-oblivious algorithms. I have just spent a few hours on what it is and what resources are available.</p>
<p>I could vaguely see what cache-oblivious algorithms are and the advantages of them, but I do not how to implement one really. I a bit doubt B-tree is not cache-oblivious, though.</p>
<p>Cache-oblivioius algorithms are pretty limited to the academic world. And my understanding of this world is people here care more about theoretical performance rather than practical. They try to reduce the number of theoretical cache misses at cost of adding more operations. The resultant program might not be faster in practice. I was also trying to find actual code on cache-oblivious search tree and the only code I can find claims that their cache-oblivious red-black tree is far slower than SGI STL&#8217;s implementation. I think I will stop here unless someone could give me source code and so I can benchmark it. It is really a pain to implement one by myself while getting a worse result.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: person</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-91</link>
		<dc:creator>person</dc:creator>
		<pubDate>Fri, 26 Sep 2008 00:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-91</guid>
		<description>What about modifying a tree data structure in such a manner that it becomes cache oblivious? That should perform well!</description>
		<content:encoded><![CDATA[<p>What about modifying a tree data structure in such a manner that it becomes cache oblivious? That should perform well!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: attractivechaos</title>
		<link>http://attractivechaos.wordpress.com/2008/09/24/b-tree-vs-binary-search-tree/#comment-89</link>
		<dc:creator>attractivechaos</dc:creator>
		<pubDate>Thu, 25 Sep 2008 21:35:10 +0000</pubDate>
		<guid isPermaLink="false">http://attractivechaos.wordpress.com/?p=507#comment-89</guid>
		<description>@AI

The benchmark is &lt;a href=&quot;http://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;, showed with hash table comparisons. I will separate them out when I have time.

@josh

People have done a lot of comparisons between AVL tree and red-black tree. My impression is they have quite similar practical performance. And AVL is a binary tree. It has to use two pointers at least. So my argument largely stands for AVL tree, too. I will also pick up some good AVL tree implementations in my benchmark in future.

@Sebastain

I admit that the the code itself looks terrible at the first sight, but to the best of my knowledge, this might be the best way to achieve generic programming in C while maintaining the best performance. If you have better ideas, I am more than happy to learn. In addition, when I am used to such macros, I do not feel too much difficulty in reading, writing, debugging or maintaining them.

@Reid

I know the standard splay tree only use two pointers, but in practice it is not as fast as the standard red-black tree. I have a library with splay tree and RB tree, written by the same programmer. RB tree is obviously faster for random input. As for red-black tree, I was saying we need parent pointer for &quot;the standard red-black tree&quot;. I am aware that some variants (such as left-leaning red-black tree) do not need a parent pointer, but the red-black tree in the majority of textbooks requires one additional pointer. I call them standard. Furthermore, from what I learn these days, no red-black tree using two pointers is as fast as the red-black tree implemented in STL which use three pointers.

I also believe B-tree tends to be more cache efficient. Another possible reason that B-tree is efficient is that you do not need to re-balance a B-tree so frequently as other binary trees, as is stated in wiki.

@Stuart

I used to write such things (a hash table for example) in C++ and I think I am not bad at that. However, I found the only piece of C++ code in my C project is always related to C++ template headers, which makes me feel uneasy.

What&#039;s more important, C++ programmers have STL. but most C programmers have to achieve generic programming at the cost of efficiency. I want to change this. Although the .h source code is hard to read, the API does not look so bad. What do you think? Do you have better ideas? I am still exploring the methods.</description>
		<content:encoded><![CDATA[<p>@AI</p>
<p>The benchmark is <a href="http://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/" rel="nofollow">here</a>, showed with hash table comparisons. I will separate them out when I have time.</p>
<p>@josh</p>
<p>People have done a lot of comparisons between AVL tree and red-black tree. My impression is they have quite similar practical performance. And AVL is a binary tree. It has to use two pointers at least. So my argument largely stands for AVL tree, too. I will also pick up some good AVL tree implementations in my benchmark in future.</p>
<p>@Sebastain</p>
<p>I admit that the the code itself looks terrible at the first sight, but to the best of my knowledge, this might be the best way to achieve generic programming in C while maintaining the best performance. If you have better ideas, I am more than happy to learn. In addition, when I am used to such macros, I do not feel too much difficulty in reading, writing, debugging or maintaining them.</p>
<p>@Reid</p>
<p>I know the standard splay tree only use two pointers, but in practice it is not as fast as the standard red-black tree. I have a library with splay tree and RB tree, written by the same programmer. RB tree is obviously faster for random input. As for red-black tree, I was saying we need parent pointer for &#8220;the standard red-black tree&#8221;. I am aware that some variants (such as left-leaning red-black tree) do not need a parent pointer, but the red-black tree in the majority of textbooks requires one additional pointer. I call them standard. Furthermore, from what I learn these days, no red-black tree using two pointers is as fast as the red-black tree implemented in STL which use three pointers.</p>
<p>I also believe B-tree tends to be more cache efficient. Another possible reason that B-tree is efficient is that you do not need to re-balance a B-tree so frequently as other binary trees, as is stated in wiki.</p>
<p>@Stuart</p>
<p>I used to write such things (a hash table for example) in C++ and I think I am not bad at that. However, I found the only piece of C++ code in my C project is always related to C++ template headers, which makes me feel uneasy.</p>
<p>What&#8217;s more important, C++ programmers have STL. but most C programmers have to achieve generic programming at the cost of efficiency. I want to change this. Although the .h source code is hard to read, the API does not look so bad. What do you think? Do you have better ideas? I am still exploring the methods.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
