One-shot helpers (Go 1.19+)
h1 := maphash.String(maphash.MakeSeed(), "hello")
h2 := maphash.Bytes(maphash.MakeSeed(), []byte("hello"))
hash/maphashFast, randomly-seeded hashing for strings and bytes. The same hash Go's map uses internally — great for building sharded caches.
Unlike crypto hashes, maphash is deliberately non-portable and per-process random (defeats collision-DoS). Unlike fnv/crc, it's very fast. Use it when you want 'hash a key, pick a shard' — NOT when the hash value needs to survive process restarts.
h1 := maphash.String(maphash.MakeSeed(), "hello")
h2 := maphash.Bytes(maphash.MakeSeed(), []byte("hello"))
var h maphash.Hash
h.SetSeed(maphash.MakeSeed())
h.WriteString("user:")
h.WriteString(userID)
sum := h.Sum64()
seed := maphash.MakeSeed()
n := maphash.Comparable(seed, struct{ X, Y int }{3, 4})
fmt.Println(n)