-
Notifications
You must be signed in to change notification settings - Fork 1
/
jenkins.go
54 lines (41 loc) · 818 Bytes
/
jenkins.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
package jenkins
import "hash"
type jenkhash uint32
const (
blockSize = 1
hashSize = 4
)
// New returns a new jenkins hash conforming to hash.Hash32 interface
func New() hash.Hash32 {
var j jenkhash
return &j
}
func (j *jenkhash) Write(key []byte) (int, error) {
hash := *j
for _, b := range key {
hash += jenkhash(b)
hash += (hash << 10)
hash ^= (hash >> 6)
}
hash += (hash << 3)
hash ^= (hash >> 11)
hash += (hash << 15)
*j = hash
return len(key), nil
}
func (j *jenkhash) Reset() {
*j = 0
}
func (j *jenkhash) Size() int {
return hashSize
}
func (j *jenkhash) BlockSize() int {
return blockSize
}
func (j *jenkhash) Sum32() uint32 {
return uint32(*j)
}
func (j *jenkhash) Sum(in []byte) []byte {
v := j.Sum32()
return append(in, byte(v>>24), byte(v>>16), byte(v>>8), byte(v))
}