From 6c3265b86582d4848e1c77efee3a649a137694d6 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson Matches the objects in the table
The match-and-replace operation for each individual object is guaranteed to be
+
The match specifiction must be guaranteed to retain the key
+ of any matched object. If not,
For the moment, due to performance and semantic constraints,
tables of type
The function returns the total number of replaced objects.
-The match/replacement operation atomicity scope is limited - to each individual object.
-Example
+For all 2-tuples with a list in second position, add atom
+1> T = ets:new(x,[]), ets:insert(T, {key, [1, 2, 3]}).
+true
+2> MS = ets:fun2ms(fun({K, L}) when is_list(L) -> {K, [marker | L]} end).
+[{{'$1','$2'},[{is_list,'$2'}],[{{'$1',[marker|'$2']}}]}]
+3> ets:select_replace(T, MS).
+1
+4> ets:tab2list(T).
+[{key,[marker,1,2,3]}]
+
+ A generic single object compare-and-swap operation:
+
+[Old] = ets:lookup(T, Key),
+New = update_object(Old),
+Success = (1 =:= ets:select_replace(T, [{Old, [], [{const, New}]}])),
+
--
cgit v1.2.3