aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/utils.c
diff options
context:
space:
mode:
authorGuilherme Andrade <[email protected]>2017-04-19 00:43:37 +0100
committerGuilherme Andrade <[email protected]>2017-04-19 01:25:35 +0100
commit0835f40ae25f97360dc393928796387d3cd6b16e (patch)
tree22b56cc3a6cb90d79efb394ecd1fab58e1182f8c /erts/emulator/beam/utils.c
parent6124bfc9b61227a5e82f1d7273d0895e909aac6e (diff)
downloadotp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.gz
otp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.bz2
otp-0835f40ae25f97360dc393928796387d3cd6b16e.zip
erts: Add enif_phash2 and enif_phash2_ranged
These allow one to hash VM terms from NIF code.
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r--erts/emulator/beam/utils.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c
index 8f3f48f38f..72c59b33c6 100644
--- a/erts/emulator/beam/utils.c
+++ b/erts/emulator/beam/utils.c
@@ -1552,6 +1552,16 @@ make_hash2(Eterm term)
}
}
+Uint32
+make_hash2_within_range(Eterm term, Uint32 range)
+{
+ Uint32 hash = make_hash2(term);
+ if (range)
+ return hash % range; /* [0..range-1] */
+ else
+ return hash; /* Special case: 2**32 */
+}
+
/* Term hash function for internal use.
*
* Limitation #1: Is not "portable" in any way between different VM instances.