mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 19:21:19 +00:00
eb70fc73cd
Former-commit-id: 25dc367490dd16ef4fa1d462118aa438df1b319a [formerly 6fab78aeb8b9f54fddbad1406f97392b753a830a] Former-commit-id: 0de0bb3ef9af1735ac8ecd1aefe2d57c0f76c62d
33 lines
820 B
Go
33 lines
820 B
Go
package models // import "github.com/influxdata/influxdb/models"
|
|
|
|
// from stdlib hash/fnv/fnv.go
|
|
const (
|
|
prime64 = 1099511628211
|
|
offset64 = 14695981039346656037
|
|
)
|
|
|
|
// InlineFNV64a is an alloc-free port of the standard library's fnv64a.
|
|
// See https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function.
|
|
type InlineFNV64a uint64
|
|
|
|
// NewInlineFNV64a returns a new instance of InlineFNV64a.
|
|
func NewInlineFNV64a() InlineFNV64a {
|
|
return offset64
|
|
}
|
|
|
|
// Write adds data to the running hash.
|
|
func (s *InlineFNV64a) Write(data []byte) (int, error) {
|
|
hash := uint64(*s)
|
|
for _, c := range data {
|
|
hash ^= uint64(c)
|
|
hash *= prime64
|
|
}
|
|
*s = InlineFNV64a(hash)
|
|
return len(data), nil
|
|
}
|
|
|
|
// Sum64 returns the uint64 of the current resulting hash.
|
|
func (s *InlineFNV64a) Sum64() uint64 {
|
|
return uint64(*s)
|
|
}
|