Efficient Functional Data Structures
Ulf Wiger
etxuwig@REDACTED
Tue Jan 7 10:51:55 CET 2003
On Tue, 7 Jan 2003, Klacke wrote:
>ets:match_object(T, {[a, b | '_'] .....
>
>
>a cons pattern would do the trick
>
>/klacke
For searches like the one above, an ordered_set table is
actually more efficient than a set, since it will not scan
all objects -- only the ones that start with [a, b].
The same is true when using ets:select/2, as long as the
first part(s) of the key is bound, and (if I recall
correctly), there are no guard patterns.
In other words, ets:match_object(T, {[`_`,b ¦ `_`], ...})
will have to search the entire table for both set and
ordered_set. Also,
ets:select(T,ets:fun2ms(fun({[H¦T],Val} when H > 10 ->
{[H¦T], Val}
end)).
For really sophisticated ets searches, look at ets:select/2,
and also take a look at the ms_transform module.
(My X client seems to map the vertical bar to something that
the Erlang parser doesn`t like, so I`ve had trouble
producing a working example... I have yet to figure this
out.)
/Uffe
--
Ulf Wiger, Senior Specialist,
/ / / Architecture & Design of Carrier-Class Software
/ / / Strategic Product & System Management
/ / / Ericsson Telecom AB, ATM Multiservice Networks
More information about the erlang-questions
mailing list