aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/nif_SUITE_data
diff options
context:
space:
mode:
authorGuilherme Andrade <[email protected]>2017-04-20 22:44:04 +0100
committerGuilherme Andrade <[email protected]>2017-04-20 22:54:17 +0100
commitd8756f8665a42effa2f3515369058cff4441abeb (patch)
treebce1d8701307f9389c098c3316a6f7a8dee50127 /erts/emulator/test/nif_SUITE_data
parent5ad95cca3f3c6802cd71fdd35dd397c3a37dc239 (diff)
downloadotp-d8756f8665a42effa2f3515369058cff4441abeb.tar.gz
otp-d8756f8665a42effa2f3515369058cff4441abeb.tar.bz2
otp-d8756f8665a42effa2f3515369058cff4441abeb.zip
erts: Refactor enif_phash2 into enif_hash
A more generic hashing function which can also hash terms based on `make_internal_hash'.
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data')
-rw-r--r--erts/emulator/test/nif_SUITE_data/nif_SUITE.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
index dac6d02e9d..9d65b9c09b 100644
--- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
+++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
@@ -687,12 +687,24 @@ static ERL_NIF_TERM compare(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
return enif_make_int(env, enif_compare(argv[0],argv[1]));
}
-static ERL_NIF_TERM phash2_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
- if (argc != 1) {
+ if (argc != 2) {
+ return enif_make_badarg(env);
+ }
+
+ ErlNifHash type;
+ if (enif_is_identical(argv[0], enif_make_atom(env, "internal"))) {
+ type = ERL_NIF_INTERNAL_HASH;
+ }
+ else if (enif_is_identical(argv[0], enif_make_atom(env, "phash2"))) {
+ type = ERL_NIF_PHASH2;
+ }
+ else {
return enif_make_badarg(env);
}
- return enif_make_ulong(env, enif_phash2(argv[0]));
+
+ return enif_make_ulong(env, enif_hash(type, argv[1]));
}
static ERL_NIF_TERM many_args_100(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
@@ -2872,7 +2884,7 @@ static ErlNifFunc nif_funcs[] =
{"tuple_2_list", 1, tuple_2_list},
{"is_identical",2,is_identical},
{"compare",2,compare},
- {"phash2_nif",1,phash2_nif},
+ {"hash_nif",2,hash_nif},
{"many_args_100", 100, many_args_100},
{"clone_bin", 1, clone_bin},
{"make_sub_bin", 3, make_sub_bin},