-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwyhash.go
144 lines (118 loc) · 7.84 KB
/
wyhash.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT.
//go:generate bundle -o wyhash.go github.com/zeebo/wyhash
package lru
import (
"encoding/binary"
"math/bits"
"unsafe"
)
type (
wyhash_ptr = unsafe.Pointer
wyhash_uptr = uintptr
wyhash_u32 = uint32
wyhash_u64 = uint64
)
const (
wyhash__wyp0 = 0xa0761d6478bd642f
wyhash__wyp1 = 0xe7037ed1a0b428db
wyhash__wyp2 = 0x8ebc6af09c88c6e3
wyhash__wyp3 = 0x589965cc75374cc3
wyhash__wyp4 = 0x1d8e4e27c47d124f
)
func wyhash_i(p wyhash_ptr, n wyhash_uptr) wyhash_ptr { return wyhash_ptr(wyhash_uptr(p) + n) }
func wyhash__wymum(A, B wyhash_u64) wyhash_u64 {
hi, lo := bits.Mul64(A, B)
return hi ^ lo
}
func wyhash__wyr8(p wyhash_ptr) wyhash_u64 {
return binary.LittleEndian.Uint64((*[8]byte)(p)[:])
}
func wyhash__wyr4(p wyhash_ptr) wyhash_u64 {
return wyhash_u64(binary.LittleEndian.Uint32((*[4]byte)(p)[:]))
}
func wyhash__wyr3(p wyhash_ptr, k wyhash_uptr) wyhash_u64 {
b0 := wyhash_u64(*(*byte)(p))
b1 := wyhash_u64(*(*byte)(wyhash_i(p, k>>1)))
b2 := wyhash_u64(*(*byte)(wyhash_i(p, k-1)))
return b0<<16 | b1<<8 | b2
}
func wyhash__wyr9(p wyhash_ptr) wyhash_u64 {
b := (*[8]byte)(p)
return wyhash_u64(wyhash_u32(b[0])|wyhash_u32(b[1])<<8|wyhash_u32(b[2])<<16|wyhash_u32(b[3])<<24)<<32 |
wyhash_u64(wyhash_u32(b[4])|wyhash_u32(b[5])<<8|wyhash_u32(b[6])<<16|wyhash_u32(b[7])<<24)
}
func wyhash_hash(data string, seed wyhash_u64) wyhash_u64 {
p, len := *(*wyhash_ptr)(wyhash_ptr(&data)), wyhash_uptr(len(data))
see1, off := seed, len
switch {
case len <= 0x03:
return wyhash__wymum(wyhash__wymum(wyhash__wyr3(p, len)^seed^wyhash__wyp0, seed^wyhash__wyp1)^seed, wyhash_u64(len)^wyhash__wyp4)
case len <= 0x08:
return wyhash__wymum(wyhash__wymum(wyhash__wyr4(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr4(wyhash_i(p, len-0x04))^seed^wyhash__wyp1)^seed, wyhash_u64(len)^wyhash__wyp4)
case len <= 0x10:
return wyhash__wymum(wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, len-0x08))^seed^wyhash__wyp1)^seed, wyhash_u64(len)^wyhash__wyp4)
case len <= 0x18:
return wyhash__wymum(wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, 0x08))^seed^wyhash__wyp1)^wyhash__wymum(wyhash__wyr9(wyhash_i(p, len-0x08))^seed^wyhash__wyp2, seed^wyhash__wyp3), wyhash_u64(len)^wyhash__wyp4)
case len <= 0x20:
return wyhash__wymum(wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, 0x08))^seed^wyhash__wyp1)^wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x10))^seed^wyhash__wyp2, wyhash__wyr9(wyhash_i(p, len-0x08))^seed^wyhash__wyp3), wyhash_u64(len)^wyhash__wyp4)
case len <= 0x100:
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x08))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x10))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x18))^see1^wyhash__wyp3)
if len > 0x40 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x20))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x28))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x30))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x38))^see1^wyhash__wyp3)
if len > 0x60 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x40))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x48))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x50))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x58))^see1^wyhash__wyp3)
if len > 0x80 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x60))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x68))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x70))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x78))^see1^wyhash__wyp3)
if len > 0xa0 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x80))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x88))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x90))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x98))^see1^wyhash__wyp3)
if len > 0xc0 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xa0))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0xa8))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xb0))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0xb8))^see1^wyhash__wyp3)
if len > 0xe0 {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xc0))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0xc8))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xd0))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0xd8))^see1^wyhash__wyp3)
}
}
}
}
}
}
off = (off-1)%0x20 + 1
p = wyhash_i(p, len-off)
default:
for ; off > 0x100; off, p = off-0x100, wyhash_i(p, 0x100) {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x08))^seed^wyhash__wyp1) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x10))^seed^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x18))^seed^wyhash__wyp3)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x20))^see1^wyhash__wyp1, wyhash__wyr8(wyhash_i(p, 0x28))^see1^wyhash__wyp2) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x30))^see1^wyhash__wyp3, wyhash__wyr8(wyhash_i(p, 0x38))^see1^wyhash__wyp0)
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x40))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x48))^seed^wyhash__wyp1) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x50))^seed^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x58))^seed^wyhash__wyp3)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x60))^see1^wyhash__wyp1, wyhash__wyr8(wyhash_i(p, 0x68))^see1^wyhash__wyp2) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x70))^see1^wyhash__wyp3, wyhash__wyr8(wyhash_i(p, 0x78))^see1^wyhash__wyp0)
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x80))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x88))^seed^wyhash__wyp1) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x90))^seed^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x98))^seed^wyhash__wyp3)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xa0))^see1^wyhash__wyp1, wyhash__wyr8(wyhash_i(p, 0xa8))^see1^wyhash__wyp2) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xb0))^see1^wyhash__wyp3, wyhash__wyr8(wyhash_i(p, 0xb8))^see1^wyhash__wyp0)
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xc0))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0xc8))^seed^wyhash__wyp1) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xd0))^seed^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0xd8))^seed^wyhash__wyp3)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xe0))^see1^wyhash__wyp1, wyhash__wyr8(wyhash_i(p, 0xe8))^see1^wyhash__wyp2) ^ wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0xf0))^see1^wyhash__wyp3, wyhash__wyr8(wyhash_i(p, 0xf8))^see1^wyhash__wyp0)
}
for ; off > 0x20; off, p = off-0x20, wyhash_i(p, 0x20) {
seed = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr8(wyhash_i(p, 0x08))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr8(wyhash_i(p, 0x10))^see1^wyhash__wyp2, wyhash__wyr8(wyhash_i(p, 0x18))^see1^wyhash__wyp3)
}
}
switch {
case off > 0x18:
seed = wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, 0x08))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x10))^see1^wyhash__wyp2, wyhash__wyr9(wyhash_i(p, off-0x08))^see1^wyhash__wyp3)
case off > 0x10:
seed = wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, 0x08))^seed^wyhash__wyp1)
see1 = wyhash__wymum(wyhash__wyr9(wyhash_i(p, off-0x08))^see1^wyhash__wyp2, see1^wyhash__wyp3)
case off > 0x08:
seed = wyhash__wymum(wyhash__wyr9(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr9(wyhash_i(p, off-0x08))^seed^wyhash__wyp1)
case off > 0x03:
seed = wyhash__wymum(wyhash__wyr4(wyhash_i(p, 0x00))^seed^wyhash__wyp0, wyhash__wyr4(wyhash_i(p, off-0x04))^seed^wyhash__wyp1)
default:
seed = wyhash__wymum(wyhash__wyr3(p, off)^seed^wyhash__wyp0, seed^wyhash__wyp1)
}
return wyhash__wymum(seed^see1, wyhash_u64(len)^wyhash__wyp4)
}