Skip to content

Commit

Permalink
simplify hash to just use low 27 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
crusso committed Feb 17, 2024
2 parents 7b87f91 + e52f850 commit b0f8341
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 2 additions & 1 deletion collections/motoko/src/ZhenyaHashmap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import Prim "mo:prim";
actor {
stable let profiling = Profiling.init();


// avoid boxed hashes
let public func hashNat64(key: Nat64): Nat32 {
func hashNat64(key: Nat64) : Nat32 {
Prim.nat64ToNat32(key & 0x7ff_ffff); // Nat32 is 27-bit
};

Expand Down
1 change: 0 additions & 1 deletion collections/motoko/src/hashmap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Profiling "../../../utils/motoko/Profiling";

actor {
stable let profiling = Profiling.init();

func hash(x: Nat64) : Nat32 = Hash.hash(Nat64.toNat x);
var map = HashMap.HashMap<Nat64, Nat64>(0, Nat64.equal, hash);
stable var stableMap: [(Nat64, Nat64)] = [];
Expand Down

0 comments on commit b0f8341

Please sign in to comment.