github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/fnv/hash.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. 2 3 package fnv 4 5 const ( 6 offset64 uint64 = 14695981039346656037 7 prime64 uint64 = 1099511628211 8 ) 9 10 // HashString 11 // 非unique Hash 12 func HashString(key string) uint64 { 13 var hash = offset64 14 for _, b := range key { 15 hash ^= uint64(b) 16 hash *= prime64 17 } 18 return hash 19 } 20 21 // Hash 22 // 非unique Hash 23 func Hash(key []byte) uint64 { 24 var hash = offset64 25 for _, b := range key { 26 hash ^= uint64(b) 27 hash *= prime64 28 } 29 return hash 30 }