github.com/fufuok/balancer@v1.0.0/utils/hash.go (about) 1 package utils 2 3 const ( 4 // FNVa offset basis. See https://en.wikipedia.org/wiki/Fowler–Noll–Vo_hash_function#FNV-1a_hash 5 offset64 = 14695981039346656037 6 prime64 = 1099511628211 7 ) 8 9 func HashString(s ...string) uint64 { 10 return Sum64(AddString(s...)) 11 } 12 13 // Sum64 similar to fnv.New64a().Sum64(), but faster. 14 func Sum64(s string) uint64 { 15 var h uint64 = offset64 16 for i := 0; i < len(s); i++ { 17 h ^= uint64(s[i]) 18 h *= prime64 19 } 20 return h 21 }