From 44cbc2691654adb20516490e079602843ab4c371 Mon Sep 17 00:00:00 2001 From: Patrik Nyblom Date: Fri, 13 Aug 2010 11:30:42 +0200 Subject: Add documentation for ets:select_reverse/1/2/3 --- lib/stdlib/doc/src/ets.xml | 107 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 14 deletions(-) (limited to 'lib/stdlib/doc') diff --git a/lib/stdlib/doc/src/ets.xml b/lib/stdlib/doc/src/ets.xml index 5df60a92e5..dd4a289c61 100644 --- a/lib/stdlib/doc/src/ets.xml +++ b/lib/stdlib/doc/src/ets.xml @@ -1384,6 +1384,28 @@ is_integer(X), is_integer(Y), X + Y < 4711]]> objects in the table.

+ + select_count(Tab, MatchSpec) -> NumMatched + Match the objects in an ETS table against a match_spec and returns the number of objects for which the match_spec returned 'true' + + Tab = tid() | atom() + Object = tuple() + MatchSpec = match_spec() + NumMatched = integer() + + +

Matches the objects in the table Tab using a + match_spec. If the + match_spec returns true for an object, that object + considered a match and is counted. For any other result from + the match_spec the object is not considered a match and is + therefore not counted.

+

The function could be described as a match_delete/2 + that does not actually delete any elements, but only counts + them.

+

The function returns the number of objects matched.

+
+
select_delete(Tab, MatchSpec) -> NumDeleted Match the objects in an ETS table against a match_spec and deletes objects where the match_spec returns 'true' @@ -1411,25 +1433,82 @@ is_integer(X), is_integer(Y), X + Y < 4711]]> - select_count(Tab, MatchSpec) -> NumMatched - Match the objects in an ETS table against a match_spec and returns the number of objects for which the match_spec returned 'true' + select_reverse(Tab, MatchSpec) -> [Match] + Match the objects in an ETS table against a match_spec. Tab = tid() | atom() - Object = tuple() + Match = term() MatchSpec = match_spec() - NumMatched = integer() -

Matches the objects in the table Tab using a - match_spec. If the - match_spec returns true for an object, that object - considered a match and is counted. For any other result from - the match_spec the object is not considered a match and is - therefore not counted.

-

The function could be described as a match_delete/2 - that does not actually delete any elements, but only counts - them.

-

The function returns the number of objects matched.

+ +

Works like select/2, but returns the list in reverse + order for the ordered_set table type. For all other table + types, the return value is identical to that of select/2.

+ +
+
+ + select_reverse(Tab, MatchSpec, Limit) -> {[Match],Continuation} | '$end_of_table' + Match the objects in an ETS table against a match_spec and returns part of the answers. + + Tab = tid() | atom() + Match = term() + MatchSpec = match_spec() + Continuation = term() + + + +

Works like select/3, but for the ordered_set + table type, traversing is done starting at the last object in + Erlang term order and moves towards the first. For all other + table types, the return value is identical to that of + select/3.

+ +

Note that this is not equivalent to + reversing the result list of a select/3 call, as the result list + is not only reversed, but also contains the last Limit + matching objects in the table, not the first.

+ +
+
+ + select_reverse(Continuation) -> {[Match],Continuation} | '$end_of_table' + Continue matching objects in an ETS table. + + Match = term() + Continuation = term() + + + +

Continues a match started with + ets:select_reverse/3. If the table is an + ordered_set, the traversal of the table will continue + towards objects with keys earlier in the Erlang term order. The + returned list will also contain objects with keys in reverse + order.

+ +

For all other table types, the behaviour is exatly that of select/1.

+

Example:

+ +1> T = ets:new(x,[ordered_set]). +2> [ ets:insert(T,{N}) || N <- lists:seq(1,10) ]. +... +3> {R0,C0} = ets:select_reverse(T,[{'_',[],['$_']}],4). +... +4> R0. +[{10},{9},{8},{7}] +5> {R1,C1} = ets:select_reverse(C0). +... +6> R1. +[{6},{5},{4},{3}] +7> {R2,C2} = ets:select_reverse(C1). +... +8> R2. +[{2},{1}] +9> '$end_of_table' = ets:select_reverse(C2). +... +
-- cgit v1.2.3