File: inline_fnv.go

package info (click to toggle)
influxdb 1.1.1%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,712 kB
  • sloc: sh: 1,231; python: 804; ruby: 118; makefile: 100
file content (27 lines) | stat: -rw-r--r-- 578 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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.
type InlineFNV64a uint64

func NewInlineFNV64a() InlineFNV64a {
	return offset64
}

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
}
func (s *InlineFNV64a) Sum64() uint64 {
	return uint64(*s)
}