github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/influxdb/models/inline_fnv.go (about) 1 package models 2 3 // from stdlib hash/fnv/fnv.go 4 const ( 5 prime64 = 1099511628211 6 offset64 = 14695981039346656037 7 ) 8 9 // InlineFNV64a is an alloc-free port of the standard library's fnv64a. 10 // See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function. 11 type InlineFNV64a uint64 12 13 // NewInlineFNV64a returns a new instance of InlineFNV64a. 14 func NewInlineFNV64a() InlineFNV64a { 15 return offset64 16 } 17 18 // Write adds data to the running hash. 19 func (s *InlineFNV64a) Write(data []byte) (int, error) { 20 hash := uint64(*s) 21 for _, c := range data { 22 hash ^= uint64(c) 23 hash *= prime64 24 } 25 *s = InlineFNV64a(hash) 26 return len(data), nil 27 } 28 29 // Sum64 returns the uint64 of the current resulting hash. 30 func (s *InlineFNV64a) Sum64() uint64 { 31 return uint64(*s) 32 }