Skip to content

Commit

Permalink
use better hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
crusso committed Feb 14, 2024
1 parent 81ed4c7 commit 1b763c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions collections/motoko/src/ZhenyaHashmap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Iter "mo:base/Iter";
import Option "mo:base/Option";
import Random "random";
import Profiling "../../../utils/motoko/Profiling";

import Prim "mo:prim";
actor {
stable let profiling = Profiling.init();
func f_hash(x : Nat64) : Nat32 = Hash.hash(Nat64.toNat x);

func f_hash(x : Nat64) : Nat32 = Prim.nat64ToNat32(x & 0xffffffff);
let hash : HashMap.HashUtils<Nat64> = (f_hash, Nat64.equal);
stable var map = HashMap.new<Nat64, Nat64>();
let rand = Random.new(null, 42);
Expand Down
2 changes: 1 addition & 1 deletion collections/motoko/src/hashmap.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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 1b763c4

Please sign in to comment.