Zero-allocation alternative to hash/fnv.New64a(). Computes FNV-1a inline without heap-allocating a hash.Hash64 object per call.
20 lines
342 B
Go
20 lines
342 B
Go
package hash
|
|
|
|
func FNV64a(key string) uint64 {
|
|
var h uint64 = 14695981039346656037
|
|
for i := 0; i < len(key); i++ {
|
|
h ^= uint64(key[i])
|
|
h *= 1099511628211
|
|
}
|
|
return h
|
|
}
|
|
|
|
func FNV64aBytes(key []byte) uint64 {
|
|
var h uint64 = 14695981039346656037
|
|
for i := 0; i < len(key); i++ {
|
|
h ^= uint64(key[i])
|
|
h *= 1099511628211
|
|
}
|
|
return h
|
|
}
|