aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2015-01-21 18:22:58 +0100
committerBjörn-Egil Dahlberg <[email protected]>2015-03-12 18:56:41 +0100
commita7a0bb29fd162cdfc6cdf6eb18cb5e2cf22a430e (patch)
tree34d3c6aa8c0de8e676ef25265e0e8f6e8516ed31 /erts
parentb0b6eff0bebd25ba371a027b824426b87bd2a1d6 (diff)
downloadotp-a7a0bb29fd162cdfc6cdf6eb18cb5e2cf22a430e.tar.gz
otp-a7a0bb29fd162cdfc6cdf6eb18cb5e2cf22a430e.tar.bz2
otp-a7a0bb29fd162cdfc6cdf6eb18cb5e2cf22a430e.zip
erts: Add hashmap:find/2
Diffstat (limited to 'erts')
-rw-r--r--erts/emulator/beam/bif.tab1
-rw-r--r--erts/emulator/beam/erl_hashmap.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab
index 6408883e96..c0fb1f8827 100644
--- a/erts/emulator/beam/bif.tab
+++ b/erts/emulator/beam/bif.tab
@@ -617,6 +617,7 @@ bif erlang:get_keys/0
# Hash Array Mappped Trie
bif hashmap:put/3
bif hashmap:get/2
+bif hashmap:find/2
bif hashmap:remove/2
bif hashmap:info/1
bif hashmap:to_list/1
diff --git a/erts/emulator/beam/erl_hashmap.c b/erts/emulator/beam/erl_hashmap.c
index 8e651dd776..a5d6daadd7 100644
--- a/erts/emulator/beam/erl_hashmap.c
+++ b/erts/emulator/beam/erl_hashmap.c
@@ -133,6 +133,28 @@ BIF_RETTYPE hashmap_get_2(BIF_ALIST_2) {
BIF_ERROR(BIF_P, BADARG);
}
+/* hashmap:find/2 */
+
+BIF_RETTYPE hashmap_find_2(BIF_ALIST_2) {
+ if (is_hashmap(BIF_ARG_2)) {
+ Eterm *hp, res;
+ const Eterm *value;
+ Uint32 hx = make_hash2(BIF_ARG_1);
+
+ if ((value = hashmap_get(hx, BIF_ARG_1, BIF_ARG_2)) != NULL) {
+ hp = HAlloc(BIF_P, 3);
+ res = make_tuple(hp);
+ *hp++ = make_arityval(2);
+ *hp++ = am_ok;
+ *hp++ = *value;
+ BIF_RET(res);
+ }
+ BIF_RET(am_error);
+ }
+ BIF_ERROR(BIF_P, BADARG);
+}
+
+
/* hashmap:remove/2 */
BIF_RETTYPE hashmap_remove_2(BIF_ALIST_2) {