[erlang-questions] How would you do 100 ifs?

Robert Virding <>
Tue Nov 15 15:45:49 CET 2011

If you want a more complete implementation of Red-Black trees then look at:


The module is dict/orddict compatible. One of these days I will fix the documentation and add it to the distribution. The algorithm for Red-Black trees is a little complex in that it works on both branches. I also have a simpler tree based on an algorithm by Arne Andersson which is like a one-sided rb-tree. It is almost as fast and a better base for specialisation because of its simplicity.

One thing is a little unclear to me and that is how static is your "table"? Is compile-time static, or initialisation static? If it compile-time static then it is faster to do the binary tree "by hand" as clauses in code.


P.S. This is the same Arne Andersson whose algorithm is used in gb_trees, probably same algorithm but we read different papers presenting it.

----- Original Message -----
> On 15 Nov 2011, at 13:27, Max Bourinov wrote:
> > I have a value X which is integer, and I have a list of ranges
> > [0....200),[200....600),[600...1000)....etc....[100000, infinity]
> > (this is just an example). We can assume that the list is static.
> >
> > I have frequently check the index of the range X belongs to.
> You could go for an Interval Tree. I implemented one, extending the
> Red-Black Tree from
> http://jamesaimonetti.com/2009/12/01/red-black-trees-in-erlang/:
> https://gist.github.com/1367172
> ian
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list