[erlang-questions] ranged lookup on ordered_set ETS

Ulf Wiger ulf.wiger@REDACTED
Thu Aug 4 09:48:32 CEST 2011


On 4 Aug 2011, at 08:56, caox wrote:

> Hi
> 	According to ETS reference,  records in ordered_set ETS are stored in the Erlang Term order of  their key. So, is there a efficient way to do a ranged lookup of key on this kind of ETS without scanning the whole table. For example,    100 < Key  <105.
> 	 I guess ets:select/2 doesn't fit for the job.

If you arrange the key so that you can call ets:select/2 with the first part of the key bound, then it will only scan the subset that matches the bound part.

E.g. if you have a table where the key is {Document, Chapter}, and call

ets:select(Docs, [{{{Document,'$1'}, '$2'}, [], [{{'$1','$2'}}]}]).

Your search time will be proportional to the number of chapters in the book, modulo the normal O factor of ordered_set tables.

BR,
Ulf W

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com






More information about the erlang-questions mailing list