Tuesday July 27, 2010

It’s been a while since I posted last so I thought I would throw my blog a bone… Once again I was looking for a good B-Tree implementation in C# on the net but came up empty. In the hopes of simplifying other developer’s lives I’ve created a generic B-Tree library that allows you to create a B-Tree with an arbitrary key type and value type. I’ve included support for specifying the key order by allowing you to supply a Comparer<T>. I’ve also allowed the B-Tree to support duplicate keys. Value comparison is also customizable by supplying a EqualityComparer<T>.

Why are B-trees a good thing for .NET you ask? Well the standard .NET library implements a hash table using the Dictionary<TKey,TValue> generic class. Hash tables do not support duplicate keys, and B-Trees are also much more efficient for supporting large key sets for both insertion and deletion. For more details on how a B-Tree data structure works see this: Wikipedia B-Tree article

If there is any interest I might add support for the IQueryable interface, making it LINQ compatible. For now this B-Tree library is used as the key index for a simple flat file caching database. Although it's far less functional than a full SQL database, caching with an in-memory key structure to a flat file out performs caching to any SQL database hands down.

Below is a link to the library this is released under the version 3 of the GNU public license.