-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathhasher128.go
73 lines (60 loc) · 1.79 KB
/
hasher128.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package xxh3
import (
"hash"
)
// Hasher128 implements the hash.Hash interface.
// It will return hashes that are 128 bits.
type Hasher128 struct {
h Hasher
}
var (
_ hash.Hash = (*Hasher128)(nil)
)
// New128 returns a new 128 bit Hasher that implements the hash.Hash interface.
func New128() *Hasher128 {
return &Hasher128{}
}
// NewSeed128 returns a new Hasher128 that implements the hash.Hash interface.
func NewSeed128(seed uint64) *Hasher128 {
var h Hasher128
h.ResetSeed(seed)
return &h
}
// Reset resets the Hash to its initial state.
func (h *Hasher128) Reset() {
h.h.Reset()
}
// ResetSeed will reset the hash and set a new seed.
// This will change the original state used by Reset.
func (h *Hasher128) ResetSeed(seed uint64) {
h.h.ResetSeed(seed)
}
// BlockSize returns the hash's underlying block size.
// The Write method will accept any amount of data, but
// it may operate more efficiently if all writes are a
// multiple of the block size.
func (h *Hasher128) BlockSize() int { return _stripe }
// Size returns the number of bytes Sum will return.
func (h *Hasher128) Size() int { return 16 }
// Sum appends the current hash to b and returns the resulting slice.
// It does not change the underlying hash state.
func (h *Hasher128) Sum(b []byte) []byte {
sum := h.h.Sum128().Bytes()
return append(b, sum[:]...)
}
// Write adds more data to the running hash.
// It never returns an error.
func (h *Hasher128) Write(buf []byte) (int, error) {
h.h.update(buf)
return len(buf), nil
}
// WriteString adds more data to the running hash.
// It never returns an error.
func (h *Hasher128) WriteString(buf string) (int, error) {
h.h.updateString(buf)
return len(buf), nil
}
// Sum128 returns the 128-bit hash of the written data.
func (h *Hasher128) Sum128() Uint128 {
return h.h.Sum128()
}