Debian Codegraph @

hasher128.go

raw
1 package xxh3
2
3 import (
4 "hash"
5 )
6
7 // Hasher128 implements the hash.Hash interface.
8 // It will return hashes that are 128 bits.
9 type Hasher128 struct {
10 h Hasher
11 }
12
13 var (
14 _ hash.Hash = (*Hasher128)(nil)
15 )
16
17 // New128 returns a new 128 bit Hasher that implements the hash.Hash interface.
18 func New128() *Hasher128 {
19 return &Hasher128{}
20 }
21
22 // NewSeed128 returns a new Hasher128 that implements the hash.Hash interface.
23 func NewSeed128(seed uint64) *Hasher128 {
24 var h Hasher128
25 h.ResetSeed(seed)
26 return &h
27 }
28
29 // Reset resets the Hash to its initial state.
30 func (h *Hasher128) Reset() {
31 h.h.Reset()
32 }
33
34 // ResetSeed will reset the hash and set a new seed.
35 // This will change the original state used by Reset.
36 func (h *Hasher128) ResetSeed(seed uint64) {
37 h.h.ResetSeed(seed)
38 }
39
40 // BlockSize returns the hash's underlying block size.
41 // The Write method will accept any amount of data, but
42 // it may operate more efficiently if all writes are a
43 // multiple of the block size.
44 func (h *Hasher128) BlockSize() int { return _stripe }
45
46 // Size returns the number of bytes Sum will return.
47 func (h *Hasher128) Size() int { return 16 }
48
49 // Sum appends the current hash to b and returns the resulting slice.
50 // It does not change the underlying hash state.
51 func (h *Hasher128) Sum(b []byte) []byte {
52 sum := h.h.Sum128().Bytes()
53 return append(b, sum[:]...)
54 }
55
56 // Write adds more data to the running hash.
57 // It never returns an error.
58 func (h *Hasher128) Write(buf []byte) (int, error) {
59 h.h.update(buf)
60 return len(buf), nil
61 }
62
63 // WriteString adds more data to the running hash.
64 // It never returns an error.
65 func (h *Hasher128) WriteString(buf string) (int, error) {
66 h.h.updateString(buf)
67 return len(buf), nil
68 }
69
70 // Sum128 returns the 128-bit hash of the written data.
71 func (h *Hasher128) Sum128() Uint128 {
72 return h.h.Sum128()
73 }