mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-06 18:10:26 +08:00
31 lines
502 B
Go
31 lines
502 B
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package fnv
|
|
|
|
const (
|
|
offset64 uint64 = 14695981039346656037
|
|
prime64 uint64 = 1099511628211
|
|
)
|
|
|
|
// HashString
|
|
// 非unique Hash
|
|
func HashString(key string) uint64 {
|
|
var hash = offset64
|
|
for _, b := range key {
|
|
hash ^= uint64(b)
|
|
hash *= prime64
|
|
}
|
|
return hash
|
|
}
|
|
|
|
// Hash
|
|
// 非unique Hash
|
|
func Hash(key []byte) uint64 {
|
|
var hash = offset64
|
|
for _, b := range key {
|
|
hash ^= uint64(b)
|
|
hash *= prime64
|
|
}
|
|
return hash
|
|
}
|