From 797b8ba93f64111ea17b43bc17b6818e167b34ec Mon Sep 17 00:00:00 2001 From: zhangyunhao Date: Mon, 28 Oct 2024 08:54:43 +0000 Subject: [PATCH] use mixhash --- bench_test.go | 3 ++- hash.go | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bench_test.go b/bench_test.go index 04ee71c..ac01e10 100644 --- a/bench_test.go +++ b/bench_test.go @@ -24,7 +24,8 @@ var ( 2048, 4096, 8192, - 1 << 16} + 1 << 16, + } ) func BenchmarkMapAccessHit(b *testing.B) { diff --git a/hash.go b/hash.go index 2aa6b39..d3ca88c 100644 --- a/hash.go +++ b/hash.go @@ -2,10 +2,11 @@ package umap import "math/bits" -// Using FxHash: https://searchfox.org/mozilla-central/rev/633345116df55e2d37be9be6555aa739656c5a7d/mfbt/HashFunctions.h -// Benchmarks for different hash algorithms: https://github.com/tkaitchuck/aHash/blob/master/FAQ.md#how-is-ahash-so-fast +func _wymix(a, b uint64) uint64 { + hi, lo := bits.Mul64(a, b) + return hi ^ lo +} func hashUint64(x uint64) uint64 { - const K = 0x517cc1b727220a95 - return (bits.RotateLeft64(x, 5) ^ x) * K + return _wymix(x^0xfffc2d0600147fc8, 0xf6ea71d5ec8a2980) }