github.com/GitbookIO/syncgroup@v0.0.0-20200915204659-4f0b2961ab10/quickhash/fnva.go (about) 1 package quickhash 2 3 const ( 4 offset64 uint64 = 14695981039346656037 5 prime64 uint64 = 1099511628211 6 ) 7 8 // sum64 is an in-lined version of Go's built-in fnv 64a hash. 9 // https://golang.org/pkg/hash/fnv/ 10 // 11 // These lines of code are equivalent: 12 // 13 // hash := sum64(data) 14 // 15 // h := fnv.New64a() 16 // h.Write(data) 17 // hash := h.Sum64() 18 // 19 // but the former creates no allocations. 20 func Fnv64a(data []byte) uint64 { 21 hash := offset64 22 for _, c := range data { 23 hash ^= uint64(c) 24 hash *= prime64 25 } 26 return hash 27 }