-
Notifications
You must be signed in to change notification settings - Fork 0
/
xxh3_64.go
64 lines (50 loc) · 1.38 KB
/
xxh3_64.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
package xxh3
import (
"fmt"
"hash"
)
// New64 returns a new hash.Hash64 computing the XXH3-64 checksum
func New64() hash.Hash64 {
return New64WithSeed(0)
}
// New64WithSecret returns a new hash.Hash64 computing the XXH3-64 checksum
func New64WithSecret(secret []byte) (hash.Hash64, error) {
if len(secret) < SECRET_SIZE_MIN {
return nil, fmt.Errorf("secret too short")
}
return newDigest64(0, secret), nil
}
// New64WithSeed returns a new hash.Hash64 computing the XXH3-64 checksum
func New64WithSeed(seed uint64) hash.Hash64 {
secret := make([]byte, SECRET_DEFAULT_SIZE)
GenCustomSecret(secret, seed)
return newDigest64(seed, secret)
}
// Sum64 returns the 64bits Hash value.
func Sum64(input []byte) (out [Size64]byte) {
d := New64()
d.Write(input)
sum := d.Sum(nil)
copy(out[:], sum)
return
}
// Sum64WithSeed returns the 64bits Hash value.
func Sum64WithSeed(input []byte, seed uint64) (out [Size64]byte) {
d := New64WithSeed(seed)
d.Write(input)
sum := d.Sum(nil)
copy(out[:], sum)
return
}
// Checksum64 returns the uint64 value.
func Checksum64(input []byte) uint64 {
d := New64()
d.Write(input)
return d.Sum64()
}
// Checksum64WithSeed returns the uint64 value.
func Checksum64WithSeed(input []byte, seed uint64) uint64 {
d := New64WithSeed(seed)
d.Write(input)
return d.Sum64()
}