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

Ian Wilkinson ianw1@REDACTED
Tue Nov 15 15:17:03 CET 2011


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



More information about the erlang-questions mailing list