<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
I would assume that inifinity is 10,000,000 (that is a pretty big
number, if it is not enough you can just use X * 10,000,000 as
infinity) and then I would create a dict and store an index for each
number between 0 and 10,000,000 based on the index in the list and
then look up the value for X in the dict.<br>
<br>
Something like this:<br>
<tt><br>
{_,Lookup} = lists:foldl( fun(Ls,{Index,Dict}) -> <br>
NewDict = lists:foldl(
fun(L, D) -> <a class="moz-txt-link-freetext" href="dict:store(L,Index,D)">dict:store(L,Index,D)</a> end,<br>
Dict,<br>
Ls),<br>
{Index+1, NewDict}<br>
end,<br>
{0, <a class="moz-txt-link-freetext" href="dict:new()">dict:new()</a>},<br>
ListOfRanges),<br>
<a class="moz-txt-link-freetext" href="dict:find(X,Lookup)">dict:find(X,Lookup)</a>.<br>
<br>
</tt>But bear with me I have not given this much thought let alone
pushed through the compiler.<br>
<br>
Cheers,<br>
Torben<br>
<tt> </tt><br>
<br>
On 15/11/11 14:27 , Max Bourinov wrote:
<blockquote
cite="mid:CANsaZAh+L_q61A8Qm5YDbra5WVYjGJhis4J3tZasSeYHWRk58g@mail.gmail.com"
type="cite">Hi guys,
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>I have frequently check the index of the range X belongs to.</div>
<div>How would you implement it in Erlang?</div>
<div><br clear="all">
<div>Best regards,</div>
<div>Max</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
</body>
</html>