-
Notifications
You must be signed in to change notification settings - Fork 0
/
doublehash32.go
62 lines (51 loc) · 978 Bytes
/
doublehash32.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
package hash
import (
gohash "hash"
"io"
)
// DoubleHash32 satisfies the hash.Hash32 interface.
//
// It is a double hash function that uses two hash functions to generate
// a hash value.
//
// Note:
// - `Sum` is a noop.
// - `Size` is a noop
// - `BlockSize` is a noop.
type DoubleHash32 struct {
io.Writer
fn1 gohash.Hash32
fn2 gohash.Hash32
i uint32
}
func NewDoubleHash32(fn1, fn2 gohash.Hash32, i uint32) gohash.Hash32 {
return &DoubleHash32{
fn1: fn1,
fn2: fn2,
i: i,
}
}
func (h *DoubleHash32) Write(p []byte) (n int, err error) {
h.fn1.Write(p)
h.fn2.Write(p)
return len(p), nil
}
func (h *DoubleHash32) Reset() {
h.fn1.Reset()
h.fn2.Reset()
}
func (h *DoubleHash32) Sum(b []byte) []byte {
// noop
return b
}
func (h *DoubleHash32) Size() int {
// noop
return 0
}
func (h *DoubleHash32) BlockSize() int {
// noop
return 0
}
func (h *DoubleHash32) Sum32() uint32 {
return h.fn1.Sum32() + h.i*h.fn2.Sum32() + (h.i * h.i)
}