aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFredrik Gustafsson <[email protected]>2013-10-22 09:53:52 +0200
committerFredrik Gustafsson <[email protected]>2013-10-22 09:53:52 +0200
commitaa3d0613b1e67f378ee11838f67e7cfbe1bc5928 (patch)
tree10bf9be0748bf57d5ed4d7b78ab1417b834ce10d
parenta6141d40a3596090c41f7e52537eaab2e733510c (diff)
parente6757fb65ef28f6b4b16d626f119bd162c415a81 (diff)
downloadotp-aa3d0613b1e67f378ee11838f67e7cfbe1bc5928.tar.gz
otp-aa3d0613b1e67f378ee11838f67e7cfbe1bc5928.tar.bz2
otp-aa3d0613b1e67f378ee11838f67e7cfbe1bc5928.zip
Merge branch 'mh/dict_orddict_is_empty/OTP-11353'
* mh/dict_orddict_is_empty/OTP-11353: Update primary bootstrap Add dict:is_empty/1 and orddict:is_empty/1
-rw-r--r--bootstrap/lib/stdlib/ebin/dict.beambin9132 -> 9216 bytes
-rw-r--r--bootstrap/lib/stdlib/ebin/orddict.beambin2748 -> 2804 bytes
-rw-r--r--lib/stdlib/doc/src/dict.xml7
-rw-r--r--lib/stdlib/doc/src/orddict.xml7
-rw-r--r--lib/stdlib/src/dict.erl7
-rw-r--r--lib/stdlib/src/orddict.erl8
-rw-r--r--lib/stdlib/test/dict_SUITE.erl11
-rw-r--r--lib/stdlib/test/dict_test_lib.erl1
8 files changed, 38 insertions, 3 deletions
diff --git a/bootstrap/lib/stdlib/ebin/dict.beam b/bootstrap/lib/stdlib/ebin/dict.beam
index 83d30876cc..df8bdae61d 100644
--- a/bootstrap/lib/stdlib/ebin/dict.beam
+++ b/bootstrap/lib/stdlib/ebin/dict.beam
Binary files differ
diff --git a/bootstrap/lib/stdlib/ebin/orddict.beam b/bootstrap/lib/stdlib/ebin/orddict.beam
index 6892fd2c9e..722117e542 100644
--- a/bootstrap/lib/stdlib/ebin/orddict.beam
+++ b/bootstrap/lib/stdlib/ebin/orddict.beam
Binary files differ
diff --git a/lib/stdlib/doc/src/dict.xml b/lib/stdlib/doc/src/dict.xml
index b8cf61af80..6ff81b56ee 100644
--- a/lib/stdlib/doc/src/dict.xml
+++ b/lib/stdlib/doc/src/dict.xml
@@ -177,6 +177,13 @@ merge(Fun, D1, D2) ->
</desc>
</func>
<func>
+ <name name="is_empty" arity="1"/>
+ <fsummary>Return true if the dictionary is empty</fsummary>
+ <desc>
+ <p>Returns <c>true</c> if <c><anno>Dict</anno></c> has no elements, <c>false</c> otherwise.</p>
+ </desc>
+ </func>
+ <func>
<name name="store" arity="3"/>
<fsummary>Store a value in a dictionary</fsummary>
<desc>
diff --git a/lib/stdlib/doc/src/orddict.xml b/lib/stdlib/doc/src/orddict.xml
index b6aee7a7d6..6d1702bc59 100644
--- a/lib/stdlib/doc/src/orddict.xml
+++ b/lib/stdlib/doc/src/orddict.xml
@@ -187,6 +187,13 @@ merge(Fun, D1, D2) ->
</desc>
</func>
<func>
+ <name name="is_empty" arity="1"/>
+ <fsummary>Return true if the dictionary is empty</fsummary>
+ <desc>
+ <p>Returns <c>true</c> if <c><anno>Orddict</anno></c> has no elements, <c>false</c> otherwise.</p>
+ </desc>
+ </func>
+ <func>
<name name="store" arity="3"/>
<fsummary>Store a value in a dictionary</fsummary>
<desc>
diff --git a/lib/stdlib/src/dict.erl b/lib/stdlib/src/dict.erl
index 32a7878da4..7e198a2469 100644
--- a/lib/stdlib/src/dict.erl
+++ b/lib/stdlib/src/dict.erl
@@ -36,7 +36,7 @@
-module(dict).
%% Standard interface.
--export([new/0,is_key/2,to_list/1,from_list/1,size/1]).
+-export([new/0,is_key/2,to_list/1,from_list/1,size/1,is_empty/1]).
-export([fetch/2,find/2,fetch_keys/1,erase/2]).
-export([store/3,append/3,append_list/3,update/3,update/4,update_counter/3]).
-export([fold/3,map/2,filter/2,merge/3]).
@@ -112,6 +112,11 @@ from_list(L) ->
size(#dict{size=N}) when is_integer(N), N >= 0 -> N.
+-spec is_empty(Dict) -> boolean() when
+ Dict :: dict().
+
+is_empty(#dict{size=N}) -> N =:= 0.
+
-spec fetch(Key, Dict) -> Value when
Key :: term(),
Dict :: dict(),
diff --git a/lib/stdlib/src/orddict.erl b/lib/stdlib/src/orddict.erl
index 45d3c84b3e..da60fc1bb6 100644
--- a/lib/stdlib/src/orddict.erl
+++ b/lib/stdlib/src/orddict.erl
@@ -20,7 +20,7 @@
-module(orddict).
%% Standard interface.
--export([new/0,is_key/2,to_list/1,from_list/1,size/1]).
+-export([new/0,is_key/2,to_list/1,from_list/1,size/1,is_empty/1]).
-export([fetch/2,find/2,fetch_keys/1,erase/2]).
-export([store/3,append/3,append_list/3,update/3,update/4,update_counter/3]).
-export([fold/3,map/2,filter/2,merge/3]).
@@ -64,6 +64,12 @@ from_list(Pairs) ->
size(D) -> length(D).
+-spec is_empty(Orddict) -> boolean() when
+ Orddict :: orddict().
+
+is_empty([]) -> true;
+is_empty([_|_]) -> false.
+
-spec fetch(Key, Orddict) -> Value when
Key :: term(),
Value :: term(),
diff --git a/lib/stdlib/test/dict_SUITE.erl b/lib/stdlib/test/dict_SUITE.erl
index 0223240479..69814e12ce 100644
--- a/lib/stdlib/test/dict_SUITE.erl
+++ b/lib/stdlib/test/dict_SUITE.erl
@@ -17,7 +17,7 @@
%% %CopyrightEnd%
%%
-%% This module tests the ordsets, sets, and gb_sets modules.
+%% This module tests the orddict, dict, and gb_trees modules.
%%
-module(dict_SUITE).
@@ -68,6 +68,7 @@ create_1(M) ->
D0 = M(empty, []),
[] = M(to_list, D0),
0 = M(size, D0),
+ true = M(is_empty, D0),
D0.
store(Config) when is_list(Config) ->
@@ -81,6 +82,14 @@ store_1(List, M) ->
D1 = foldl(fun({K,V}, Dict) -> M(enter, {K,V,Dict}) end,
M(empty, []), List),
true = M(equal, {D0,D1}),
+ case List of
+ [] ->
+ true = M(is_empty, D0),
+ true = M(is_empty, D1);
+ [_|_] ->
+ false = M(is_empty, D0),
+ false = M(is_empty, D1)
+ end,
D0.
%%%
diff --git a/lib/stdlib/test/dict_test_lib.erl b/lib/stdlib/test/dict_test_lib.erl
index e308fd0721..4fdb4fa0bd 100644
--- a/lib/stdlib/test/dict_test_lib.erl
+++ b/lib/stdlib/test/dict_test_lib.erl
@@ -28,6 +28,7 @@ new(Mod, Eq) ->
(from_list, L) -> from_list(Mod, L);
(module, []) -> Mod;
(size, D) -> Mod:size(D);
+ (is_empty, D) -> Mod:is_empty(D);
(to_list, D) -> to_list(Mod, D)
end.