aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/erl_nif.c
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/beam/erl_nif.c
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/beam/erl_nif.c')
-rw-r--r--erts/emulator/beam/erl_nif.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c
index f7777c8b92..3470cf3fd5 100644
--- a/erts/emulator/beam/erl_nif.c
+++ b/erts/emulator/beam/erl_nif.c
@@ -1214,13 +1214,20 @@ int enif_compare(Eterm lhs, Eterm rhs)
return result;
}
-unsigned long enif_phash2(Eterm term)
+unsigned long enif_hash(ErlNifHash type, Eterm term)
{
#if SIZEOF_LONG < 4
/* This *really* shouldn't happen */
# error Incompatible long word size
#endif
- return make_hash2(term) & ((1 << 27) - 1);
+ switch (type) {
+ case ERL_NIF_INTERNAL_HASH:
+ return make_internal_hash(term);
+ case ERL_NIF_PHASH2:
+ return make_hash2(term) & ((1 << 27) - 1);
+ default:
+ return 0;
+ }
}
int enif_get_tuple(ErlNifEnv* env, Eterm tpl, int* arity, const Eterm** array)