Files
EdgeNode/internal/utils/fnv/hash.go

31 lines
502 B
Go
Raw Normal View History

2022-03-15 18:32:39 +08:00
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package fnv
const (
offset64 uint64 = 14695981039346656037
prime64 uint64 = 1099511628211
)
2022-03-16 17:06:26 +08:00
// HashString
// 非unique Hash
func HashString(key string) uint64 {
var hash = offset64
for _, b := range key {
hash ^= uint64(b)
hash *= prime64
}
return hash
}
2022-03-15 18:32:39 +08:00
// Hash
// 非unique Hash
2022-03-16 17:06:26 +08:00
func Hash(key []byte) uint64 {
2022-03-15 18:32:39 +08:00
var hash = offset64
for _, b := range key {
hash ^= uint64(b)
hash *= prime64
}
return hash
}