[erlang-questions] Ordered set with lower_bound

Paul Mineiro paul-trapexit@REDACTED
Fri Oct 9 01:32:32 CEST 2009


On Thu, 8 Oct 2009, Igor Ribeiro Sucupira wrote:

> Hi.
>
> I need some ordered set that allows me to "search and then iterate"
> efficiently. In other words, I need this functionality:
> http://www.cplusplus.com/reference/stl/set/lower_bound/
>
> After looking at the documentation for gb_sets and ordsets, I have
> concluded that Erlang does not provide that functionality and I'll
> have to roll my own. Is it the right conclusion?  :-)

ets:next/2 on an ordered_set table acts like that.  "efficiently" ...
well, it'll be O (log N) per call, you might have hoped for O (1) after
the first O (log N) call.  also you might not like the constant factors.
benchmark to be sure.

-- p

p.z. perhaps ets:slot/2 is faster?


More information about the erlang-questions mailing list