aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/dict_test_lib.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-12-19 12:22:41 +0100
committerGitHub <[email protected]>2016-12-19 12:22:41 +0100
commite083566ce098a2cf20a414ccd5ff0e1187c1f645 (patch)
tree8447b49483313bdc23cf10dd46a97db94935fdd8 /lib/stdlib/test/dict_test_lib.erl
parentb460143246eb207b505a554bf15d90655341dcbe (diff)
parenta2d92dff3a8acc534daeeb3dea5edda406a6ab0d (diff)
downloadotp-e083566ce098a2cf20a414ccd5ff0e1187c1f645.tar.gz
otp-e083566ce098a2cf20a414ccd5ff0e1187c1f645.tar.bz2
otp-e083566ce098a2cf20a414ccd5ff0e1187c1f645.zip
Merge pull request #1290 from bjorng/bjorn/stdlib/take
Add take/2 to all dictionary modules OTP-14102
Diffstat (limited to 'lib/stdlib/test/dict_test_lib.erl')
-rw-r--r--lib/stdlib/test/dict_test_lib.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/stdlib/test/dict_test_lib.erl b/lib/stdlib/test/dict_test_lib.erl
index 7c4c3572ae..f6fef7bdf4 100644
--- a/lib/stdlib/test/dict_test_lib.erl
+++ b/lib/stdlib/test/dict_test_lib.erl
@@ -33,7 +33,9 @@ new(Mod, Eq) ->
(iterator, S) -> Mod:iterator(S);
(iterator_from, {Start, S}) -> Mod:iterator_from(Start, S);
(next, I) -> Mod:next(I);
- (to_list, D) -> to_list(Mod, D)
+ (to_list, D) -> to_list(Mod, D);
+ (erase, {K,D}) -> erase(Mod, K, D);
+ (take, {K,D}) -> take(Mod, K, D)
end.
empty(Mod) ->
@@ -67,3 +69,19 @@ enter(Mod, Key, Val, Dict) ->
true ->
Mod:store(Key, Val, Dict)
end.
+
+erase(Mod, Key, Val) when Mod =:= dict; Mod =:= orddict ->
+ Mod:erase(Key, Val);
+erase(gb_trees, Key, Val) ->
+ gb_trees:delete_any(Key, Val).
+
+take(gb_trees, Key, Val) ->
+ Res = try
+ gb_trees:take(Key, Val)
+ catch
+ error:_ ->
+ error
+ end,
+ Res = gb_trees:take_any(Key, Val);
+take(Mod, Key, Val) ->
+ Mod:take(Key, Val).