perf(hash): add inline FNV-1a hash functions to internal/hash package
Zero-allocation alternative to hash/fnv.New64a(). Computes FNV-1a inline without heap-allocating a hash.Hash64 object per call.
This commit is contained in:
parent
7f08b1387d
commit
c59d387451
19
internal/hash/hash.go
Normal file
19
internal/hash/hash.go
Normal file
@ -0,0 +1,19 @@
|
||||
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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user