From f6b671de6a08340c454449185655284f8078a53d Mon Sep 17 00:00:00 2001 From: Claudio Russo Date: Fri, 16 Feb 2024 15:18:14 +0000 Subject: [PATCH] simplify hash to just use low 28 bits --- collections/motoko/src/ZhenyaHashmap.mo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/collections/motoko/src/ZhenyaHashmap.mo b/collections/motoko/src/ZhenyaHashmap.mo index 19b7d8df..4547e1c0 100644 --- a/collections/motoko/src/ZhenyaHashmap.mo +++ b/collections/motoko/src/ZhenyaHashmap.mo @@ -9,7 +9,12 @@ import Prim "mo:prim"; actor { stable let profiling = Profiling.init(); - let hash : HashMap.HashUtils = HashMap.n64hash; + let public func hashNat64(key: Nat64): Nat32 { + Prim.nat64ToNat32(key & 0x0fff_ffff); + }; + + let hash : HashMap.HashUtils = (hashNat64, func (x,y) = x == y); + stable var map = HashMap.new(); let rand = Random.new(null, 42);