-
Notifications
You must be signed in to change notification settings - Fork 0
/
xxh3_128.go
63 lines (49 loc) · 1.38 KB
/
xxh3_128.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
package xxh3
import(
"fmt"
)
// New128 returns a new Hash128 computing the XXH3-128 checksum
func New128() Hash128 {
return New128WithSeed(0)
}
// New128WithSecret returns a new Hash128 computing the XXH3-128 checksum
func New128WithSecret(secret []byte) (Hash128, error) {
if len(secret) < SECRET_SIZE_MIN {
return nil, fmt.Errorf("secret too short")
}
return newDigest128(0, secret), nil
}
// New128WithSeed returns a new Hash128 computing the XXH3-128 checksum
func New128WithSeed(seed uint64) Hash128 {
secret := make([]byte, SECRET_DEFAULT_SIZE)
GenCustomSecret(secret, seed)
return newDigest128(seed, secret)
}
// Sum128 returns the 128bits Hash value.
func Sum128(input []byte) (out [Size128]byte) {
d := New128()
d.Write(input)
sum := d.Sum(nil)
copy(out[:], sum)
return
}
// Sum128WithSeed returns the 128bits Hash value.
func Sum128WithSeed(input []byte, seed uint64) (out [Size128]byte) {
d := New128WithSeed(seed)
d.Write(input)
sum := d.Sum(nil)
copy(out[:], sum)
return
}
// Checksum128 returns the Uint128 value.
func Checksum128(input []byte) Uint128 {
d := New128()
d.Write(input)
return d.Sum128()
}
// Checksum128WithSeed returns the Uint128 value.
func Checksum128WithSeed(input []byte, seed uint64) Uint128 {
d := New128WithSeed(seed)
d.Write(input)
return d.Sum128()
}