1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
// Package fnv implements FNV-1 and FNV-1a, non-cryptographic hash functions
6
// created by Glenn Fowler, Landon Curt Noll, and Phong Vo.
7
// See http://isthe.com/chongo/tech/comp/fnv/.
23
offset64 = 14695981039346656037
25
prime64 = 1099511628211
28
// New32 returns a new 32-bit FNV-1 hash.Hash.
29
func New32() hash.Hash32 {
30
var s sum32 = offset32
34
// New32a returns a new 32-bit FNV-1a hash.Hash.
35
func New32a() hash.Hash32 {
36
var s sum32a = offset32
40
// New64 returns a new 64-bit FNV-1 hash.Hash.
41
func New64() hash.Hash64 {
42
var s sum64 = offset64
46
// New64a returns a new 64-bit FNV-1a hash.Hash.
47
func New64a() hash.Hash64 {
48
var s sum64a = offset64
52
func (s *sum32) Reset() { *s = offset32 }
53
func (s *sum32a) Reset() { *s = offset32 }
54
func (s *sum64) Reset() { *s = offset64 }
55
func (s *sum64a) Reset() { *s = offset64 }
57
func (s *sum32) Sum32() uint32 { return uint32(*s) }
58
func (s *sum32a) Sum32() uint32 { return uint32(*s) }
59
func (s *sum64) Sum64() uint64 { return uint64(*s) }
60
func (s *sum64a) Sum64() uint64 { return uint64(*s) }
62
func (s *sum32) Write(data []byte) (int, error) {
64
for _, c := range data {
72
func (s *sum32a) Write(data []byte) (int, error) {
74
for _, c := range data {
82
func (s *sum64) Write(data []byte) (int, error) {
84
for _, c := range data {
92
func (s *sum64a) Write(data []byte) (int, error) {
94
for _, c := range data {
102
func (s *sum32) Size() int { return 4 }
103
func (s *sum32a) Size() int { return 4 }
104
func (s *sum64) Size() int { return 8 }
105
func (s *sum64a) Size() int { return 8 }
107
func (s *sum32) BlockSize() int { return 1 }
108
func (s *sum32a) BlockSize() int { return 1 }
109
func (s *sum64) BlockSize() int { return 1 }
110
func (s *sum64a) BlockSize() int { return 1 }
112
func (s *sum32) Sum(in []byte) []byte {
114
return append(in, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
117
func (s *sum32a) Sum(in []byte) []byte {
119
return append(in, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
122
func (s *sum64) Sum(in []byte) []byte {
124
return append(in, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
127
func (s *sum64a) Sum(in []byte) []byte {
129
return append(in, byte(v>>56), byte(v>>48), byte(v>>40), byte(v>>32), byte(v>>24), byte(v>>16), byte(v>>8), byte(v))