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

Max Bourinov bourinov@REDACTED
Tue Nov 15 15:14:53 CET 2011


Hi Knut,

That exactly what I need.

Actually this [0....200),[200....600),[600...1000)....etc....[100000,
infinity]

Should be rad as [0, 200),[200, 600),[600, 1000)....etc....[100000,
infinity]

Thank you for code!
Max




On Tue, Nov 15, 2011 at 5:06 PM, Knut Nesheim <knutin@REDACTED> wrote:

> On Tue, Nov 15, 2011 at 2:27 PM, Max Bourinov <bourinov@REDACTED> 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]
>
> Hi Max,
>
> Some time ago I had to solve the exact same problem. What I wanted was
> fast lookups and low memory overhead. My data is not changing often.
> Storing each key and value in a structure where you could lookup based
> on key (dict, array or your own tuple), would require storing every
> possible key in the range, this was not acceptable for me.
>
> My solution was to implement a binary tree, where the key instead of
> being an exact key, is a range of keys. So the key could be {100, 200}
> and the value would be 'foo'. If you are searching for 101, the value
> returned is 'foo'. My implementation is on github[1]
>
>  [1]: https://github.com/knutin/tree_range
>
> Regards
> Knut
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111115/3e6f2cac/attachment.htm>


More information about the erlang-questions mailing list