Skip to content

Commit

Permalink
use mixhash
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyunhao116 committed Oct 28, 2024
1 parent cb7705f commit 797b8ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ var (
2048,
4096,
8192,
1 << 16}
1 << 16,
}
)

func BenchmarkMapAccessHit(b *testing.B) {
Expand Down
9 changes: 5 additions & 4 deletions hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 797b8ba

Please sign in to comment.