[erlang-questions] ranged lookup on ordered_set ETS

caox <>
Thu Aug 4 10:18:22 CEST 2011


Thanks. 

You mean in the case  100 <Key  <105, the key could be arranged in format of 
{100, Extra}, {106, Extra}, {110, Extra} or sth like that. And then match_spec like [{100, '$1'}, [], []} can be applied to do the match job.

So the ordered_set table is only for the case that the order of search result is significant, but not for ranged searching.

在 2011-8-4,下午3:48, Ulf Wiger 写道:

> 
> 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