Codebase list golang-github-pierrec-xxhash / 959cb6c
Import upstream version 0.1.5+git20201207.1.36da3d2 Debian Janitor 2 years ago
5 changed file(s) with 178 addition(s) and 139 deletion(s). Raw diff Collapse all Expand all
0 arch:
1 - amd64
2 - ppc64le
03 language: go
14
25 go:
3 - 1.4
4 - 1.5
6 - 1.13
7 - 1.14
8 - 1.15
59
610 script:
711 - go test -cpu=2 github.com/pierrec/xxHash/xxHash32
0 module github.com/pierrec/xxHash
7878 xxh.bufused += len(input) - r
7979
8080 // fast rotl(13)
81 p32 := xxh.v1 + (uint32(xxh.buf[p+3])<<24|uint32(xxh.buf[p+2])<<16|uint32(xxh.buf[p+1])<<8|uint32(xxh.buf[p]))*prime32_2
82 xxh.v1 = (p32<<13 | p32>>19) * prime32_1
83 p += 4
84 p32 = xxh.v2 + (uint32(xxh.buf[p+3])<<24|uint32(xxh.buf[p+2])<<16|uint32(xxh.buf[p+1])<<8|uint32(xxh.buf[p]))*prime32_2
85 xxh.v2 = (p32<<13 | p32>>19) * prime32_1
86 p += 4
87 p32 = xxh.v3 + (uint32(xxh.buf[p+3])<<24|uint32(xxh.buf[p+2])<<16|uint32(xxh.buf[p+1])<<8|uint32(xxh.buf[p]))*prime32_2
88 xxh.v3 = (p32<<13 | p32>>19) * prime32_1
89 p += 4
90 p32 = xxh.v4 + (uint32(xxh.buf[p+3])<<24|uint32(xxh.buf[p+2])<<16|uint32(xxh.buf[p+1])<<8|uint32(xxh.buf[p]))*prime32_2
91 xxh.v4 = (p32<<13 | p32>>19) * prime32_1
92
81 xxh.v1 = rol13(xxh.v1+u32(xxh.buf[:])*prime32_2) * prime32_1
82 xxh.v2 = rol13(xxh.v2+u32(xxh.buf[4:])*prime32_2) * prime32_1
83 xxh.v3 = rol13(xxh.v3+u32(xxh.buf[8:])*prime32_2) * prime32_1
84 xxh.v4 = rol13(xxh.v4+u32(xxh.buf[12:])*prime32_2) * prime32_1
9385 p = r
9486 xxh.bufused = 0
9587 }
9688
97 for n := n - 16; p <= n; {
98 p32 := xxh.v1 + (uint32(input[p+3])<<24|uint32(input[p+2])<<16|uint32(input[p+1])<<8|uint32(input[p]))*prime32_2
99 xxh.v1 = (p32<<13 | p32>>19) * prime32_1
100 p += 4
101 p32 = xxh.v2 + (uint32(input[p+3])<<24|uint32(input[p+2])<<16|uint32(input[p+1])<<8|uint32(input[p]))*prime32_2
102 xxh.v2 = (p32<<13 | p32>>19) * prime32_1
103 p += 4
104 p32 = xxh.v3 + (uint32(input[p+3])<<24|uint32(input[p+2])<<16|uint32(input[p+1])<<8|uint32(input[p]))*prime32_2
105 xxh.v3 = (p32<<13 | p32>>19) * prime32_1
106 p += 4
107 p32 = xxh.v4 + (uint32(input[p+3])<<24|uint32(input[p+2])<<16|uint32(input[p+1])<<8|uint32(input[p]))*prime32_2
108 xxh.v4 = (p32<<13 | p32>>19) * prime32_1
109 p += 4
110 }
89 // Causes compiler to work directly from registers instead of stack:
90 v1, v2, v3, v4 := xxh.v1, xxh.v2, xxh.v3, xxh.v4
91 for n := n - 16; p <= n; p += 16 {
92 sub := input[p:][:16] //BCE hint for compiler
93 v1 = rol13(v1+u32(sub[:])*prime32_2) * prime32_1
94 v2 = rol13(v2+u32(sub[4:])*prime32_2) * prime32_1
95 v3 = rol13(v3+u32(sub[8:])*prime32_2) * prime32_1
96 v4 = rol13(v4+u32(sub[12:])*prime32_2) * prime32_1
97 }
98 xxh.v1, xxh.v2, xxh.v3, xxh.v4 = v1, v2, v3, v4
11199
112100 copy(xxh.buf[xxh.bufused:], input[p:])
113101 xxh.bufused += len(input) - p
119107 func (xxh *xxHash) Sum32() uint32 {
120108 h32 := uint32(xxh.totalLen)
121109 if xxh.totalLen >= 16 {
122 h32 += ((xxh.v1 << 1) | (xxh.v1 >> 31)) +
123 ((xxh.v2 << 7) | (xxh.v2 >> 25)) +
124 ((xxh.v3 << 12) | (xxh.v3 >> 20)) +
125 ((xxh.v4 << 18) | (xxh.v4 >> 14))
110 h32 += rol1(xxh.v1) + rol7(xxh.v2) + rol12(xxh.v3) + rol18(xxh.v4)
126111 } else {
127112 h32 += xxh.seed + prime32_5
128113 }
130115 p := 0
131116 n := xxh.bufused
132117 for n := n - 4; p <= n; p += 4 {
133 h32 += (uint32(xxh.buf[p+3])<<24 | uint32(xxh.buf[p+2])<<16 | uint32(xxh.buf[p+1])<<8 | uint32(xxh.buf[p])) * prime32_3
134 h32 = ((h32 << 17) | (h32 >> 15)) * prime32_4
118 h32 += u32(xxh.buf[p:p+4]) * prime32_3
119 h32 = rol17(h32) * prime32_4
135120 }
136121 for ; p < n; p++ {
137122 h32 += uint32(xxh.buf[p]) * prime32_5
138 h32 = ((h32 << 11) | (h32 >> 21)) * prime32_1
123 h32 = rol11(h32) * prime32_1
139124 }
140125
141126 h32 ^= h32 >> 15
160145 v3 := seed
161146 v4 := seed - prime32_1
162147 p := 0
163 for p <= n-16 {
164 v1 += (uint32(input[p+3])<<24 | uint32(input[p+2])<<16 | uint32(input[p+1])<<8 | uint32(input[p])) * prime32_2
165 v1 = (v1<<13 | v1>>19) * prime32_1
166 p += 4
167 v2 += (uint32(input[p+3])<<24 | uint32(input[p+2])<<16 | uint32(input[p+1])<<8 | uint32(input[p])) * prime32_2
168 v2 = (v2<<13 | v2>>19) * prime32_1
169 p += 4
170 v3 += (uint32(input[p+3])<<24 | uint32(input[p+2])<<16 | uint32(input[p+1])<<8 | uint32(input[p])) * prime32_2
171 v3 = (v3<<13 | v3>>19) * prime32_1
172 p += 4
173 v4 += (uint32(input[p+3])<<24 | uint32(input[p+2])<<16 | uint32(input[p+1])<<8 | uint32(input[p])) * prime32_2
174 v4 = (v4<<13 | v4>>19) * prime32_1
175 p += 4
148 for n := n - 16; p <= n; p += 16 {
149 sub := input[p:][:16] //BCE hint for compiler
150 v1 = rol13(v1+u32(sub[:])*prime32_2) * prime32_1
151 v2 = rol13(v2+u32(sub[4:])*prime32_2) * prime32_1
152 v3 = rol13(v3+u32(sub[8:])*prime32_2) * prime32_1
153 v4 = rol13(v4+u32(sub[12:])*prime32_2) * prime32_1
176154 }
177155 input = input[p:]
178156 n -= p
179 h32 += ((v1 << 1) | (v1 >> 31)) +
180 ((v2 << 7) | (v2 >> 25)) +
181 ((v3 << 12) | (v3 >> 20)) +
182 ((v4 << 18) | (v4 >> 14))
157 h32 += rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
183158 }
184159
185160 p := 0
186 for p <= n-4 {
187 h32 += (uint32(input[p+3])<<24 | uint32(input[p+2])<<16 | uint32(input[p+1])<<8 | uint32(input[p])) * prime32_3
188 h32 = ((h32 << 17) | (h32 >> 15)) * prime32_4
189 p += 4
161 for n := n - 4; p <= n; p += 4 {
162 h32 += u32(input[p:p+4]) * prime32_3
163 h32 = rol17(h32) * prime32_4
190164 }
191165 for p < n {
192166 h32 += uint32(input[p]) * prime32_5
193 h32 = ((h32 << 11) | (h32 >> 21)) * prime32_1
167 h32 = rol11(h32) * prime32_1
194168 p++
195169 }
196170
202176
203177 return h32
204178 }
179
180 func u32(buf []byte) uint32 {
181 // go compiler recognizes this pattern and optimizes it on little endian platforms
182 return uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24
183 }
184
185 func rol1(u uint32) uint32 {
186 return u<<1 | u>>31
187 }
188
189 func rol7(u uint32) uint32 {
190 return u<<7 | u>>25
191 }
192
193 func rol11(u uint32) uint32 {
194 return u<<11 | u>>21
195 }
196
197 func rol12(u uint32) uint32 {
198 return u<<12 | u>>20
199 }
200
201 func rol13(u uint32) uint32 {
202 return u<<13 | u>>19
203 }
204
205 func rol17(u uint32) uint32 {
206 return u<<17 | u>>15
207 }
208
209 func rol18(u uint32) uint32 {
210 return u<<18 | u>>14
211 }
7878 xxh.bufused += len(input) - r
7979
8080 // fast rotl(31)
81 p64 := xxh.v1 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
82 xxh.v1 = (p64<<31 | p64>>33) * prime64_1
83 p += 8
84 p64 = xxh.v2 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
85 xxh.v2 = (p64<<31 | p64>>33) * prime64_1
86 p += 8
87 p64 = xxh.v3 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
88 xxh.v3 = (p64<<31 | p64>>33) * prime64_1
89 p += 8
90 p64 = xxh.v4 + (uint64(xxh.buf[p+7])<<56|uint64(xxh.buf[p+6])<<48|uint64(xxh.buf[p+5])<<40|uint64(xxh.buf[p+4])<<32|uint64(xxh.buf[p+3])<<24|uint64(xxh.buf[p+2])<<16|uint64(xxh.buf[p+1])<<8|uint64(xxh.buf[p]))*prime64_2
91 xxh.v4 = (p64<<31 | p64>>33) * prime64_1
92
81 xxh.v1 = rol31(xxh.v1+u64(xxh.buf[:])*prime64_2) * prime64_1
82 xxh.v2 = rol31(xxh.v2+u64(xxh.buf[8:])*prime64_2) * prime64_1
83 xxh.v3 = rol31(xxh.v3+u64(xxh.buf[16:])*prime64_2) * prime64_1
84 xxh.v4 = rol31(xxh.v4+u64(xxh.buf[24:])*prime64_2) * prime64_1
9385 p = r
9486 xxh.bufused = 0
9587 }
9688
97 for n := n - 32; p <= n; {
98 p64 := xxh.v1 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
99 xxh.v1 = (p64<<31 | p64>>33) * prime64_1
100 p += 8
101 p64 = xxh.v2 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
102 xxh.v2 = (p64<<31 | p64>>33) * prime64_1
103 p += 8
104 p64 = xxh.v3 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
105 xxh.v3 = (p64<<31 | p64>>33) * prime64_1
106 p += 8
107 p64 = xxh.v4 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
108 xxh.v4 = (p64<<31 | p64>>33) * prime64_1
109 p += 8
110 }
89 // Causes compiler to work directly from registers instead of stack:
90 v1, v2, v3, v4 := xxh.v1, xxh.v2, xxh.v3, xxh.v4
91 for n := n - 32; p <= n; p += 32 {
92 sub := input[p:][:32] //BCE hint for compiler
93 v1 = rol31(v1+u64(sub[:])*prime64_2) * prime64_1
94 v2 = rol31(v2+u64(sub[8:])*prime64_2) * prime64_1
95 v3 = rol31(v3+u64(sub[16:])*prime64_2) * prime64_1
96 v4 = rol31(v4+u64(sub[24:])*prime64_2) * prime64_1
97 }
98 xxh.v1, xxh.v2, xxh.v3, xxh.v4 = v1, v2, v3, v4
11199
112100 copy(xxh.buf[xxh.bufused:], input[p:])
113101 xxh.bufused += len(input) - p
119107 func (xxh *xxHash) Sum64() uint64 {
120108 var h64 uint64
121109 if xxh.totalLen >= 32 {
122 h64 = ((xxh.v1 << 1) | (xxh.v1 >> 63)) +
123 ((xxh.v2 << 7) | (xxh.v2 >> 57)) +
124 ((xxh.v3 << 12) | (xxh.v3 >> 52)) +
125 ((xxh.v4 << 18) | (xxh.v4 >> 46))
110 h64 = rol1(xxh.v1) + rol7(xxh.v2) + rol12(xxh.v3) + rol18(xxh.v4)
126111
127112 xxh.v1 *= prime64_2
128 h64 ^= ((xxh.v1 << 31) | (xxh.v1 >> 33)) * prime64_1
129 h64 = h64*prime64_1 + prime64_4
130
131113 xxh.v2 *= prime64_2
132 h64 ^= ((xxh.v2 << 31) | (xxh.v2 >> 33)) * prime64_1
133 h64 = h64*prime64_1 + prime64_4
134
135114 xxh.v3 *= prime64_2
136 h64 ^= ((xxh.v3 << 31) | (xxh.v3 >> 33)) * prime64_1
137 h64 = h64*prime64_1 + prime64_4
138
139115 xxh.v4 *= prime64_2
140 h64 ^= ((xxh.v4 << 31) | (xxh.v4 >> 33)) * prime64_1
141 h64 = h64*prime64_1 + prime64_4 + xxh.totalLen
116
117 h64 = (h64^(rol31(xxh.v1)*prime64_1))*prime64_1 + prime64_4
118 h64 = (h64^(rol31(xxh.v2)*prime64_1))*prime64_1 + prime64_4
119 h64 = (h64^(rol31(xxh.v3)*prime64_1))*prime64_1 + prime64_4
120 h64 = (h64^(rol31(xxh.v4)*prime64_1))*prime64_1 + prime64_4
121
122 h64 += xxh.totalLen
142123 } else {
143124 h64 = xxh.seed + prime64_5 + xxh.totalLen
144125 }
146127 p := 0
147128 n := xxh.bufused
148129 for n := n - 8; p <= n; p += 8 {
149 p64 := (uint64(xxh.buf[p+7])<<56 | uint64(xxh.buf[p+6])<<48 | uint64(xxh.buf[p+5])<<40 | uint64(xxh.buf[p+4])<<32 | uint64(xxh.buf[p+3])<<24 | uint64(xxh.buf[p+2])<<16 | uint64(xxh.buf[p+1])<<8 | uint64(xxh.buf[p])) * prime64_2
150 h64 ^= ((p64 << 31) | (p64 >> 33)) * prime64_1
151 h64 = ((h64<<27)|(h64>>37))*prime64_1 + prime64_4
130 h64 ^= rol31(u64(xxh.buf[p:p+8])*prime64_2) * prime64_1
131 h64 = rol27(h64)*prime64_1 + prime64_4
152132 }
153133 if p+4 <= n {
154 h64 ^= (uint64(xxh.buf[p+3])<<24 | uint64(xxh.buf[p+2])<<16 | uint64(xxh.buf[p+1])<<8 | uint64(xxh.buf[p])) * prime64_1
155 h64 = ((h64<<23)|(h64>>41))*prime64_2 + prime64_3
134 sub := xxh.buf[p : p+4]
135 h64 ^= uint64(u32(sub)) * prime64_1
136 h64 = rol23(h64)*prime64_2 + prime64_3
156137 p += 4
157138 }
158139 for ; p < n; p++ {
159140 h64 ^= uint64(xxh.buf[p]) * prime64_5
160 h64 = ((h64 << 11) | (h64 >> 53)) * prime64_1
141 h64 = rol11(h64) * prime64_1
161142 }
162143
163144 h64 ^= h64 >> 33
180161 v3 := seed
181162 v4 := seed - prime64_1
182163 p := 0
183 for n := n - 32; p <= n; {
184 p64 := v1 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
185 v1 = (p64<<31 | p64>>33) * prime64_1
186 p += 8
187 p64 = v2 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
188 v2 = (p64<<31 | p64>>33) * prime64_1
189 p += 8
190 p64 = v3 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
191 v3 = (p64<<31 | p64>>33) * prime64_1
192 p += 8
193 p64 = v4 + (uint64(input[p+7])<<56|uint64(input[p+6])<<48|uint64(input[p+5])<<40|uint64(input[p+4])<<32|uint64(input[p+3])<<24|uint64(input[p+2])<<16|uint64(input[p+1])<<8|uint64(input[p]))*prime64_2
194 v4 = (p64<<31 | p64>>33) * prime64_1
195 p += 8
164 for n := n - 32; p <= n; p += 32 {
165 sub := input[p:][:32] //BCE hint for compiler
166 v1 = rol31(v1+u64(sub[:])*prime64_2) * prime64_1
167 v2 = rol31(v2+u64(sub[8:])*prime64_2) * prime64_1
168 v3 = rol31(v3+u64(sub[16:])*prime64_2) * prime64_1
169 v4 = rol31(v4+u64(sub[24:])*prime64_2) * prime64_1
196170 }
197171
198 h64 = ((v1 << 1) | (v1 >> 63)) +
199 ((v2 << 7) | (v2 >> 57)) +
200 ((v3 << 12) | (v3 >> 52)) +
201 ((v4 << 18) | (v4 >> 46))
172 h64 = rol1(v1) + rol7(v2) + rol12(v3) + rol18(v4)
202173
203174 v1 *= prime64_2
204 h64 ^= ((v1 << 31) | (v1 >> 33)) * prime64_1
205 h64 = h64*prime64_1 + prime64_4
206
207175 v2 *= prime64_2
208 h64 ^= ((v2 << 31) | (v2 >> 33)) * prime64_1
209 h64 = h64*prime64_1 + prime64_4
210
211176 v3 *= prime64_2
212 h64 ^= ((v3 << 31) | (v3 >> 33)) * prime64_1
213 h64 = h64*prime64_1 + prime64_4
214
215177 v4 *= prime64_2
216 h64 ^= ((v4 << 31) | (v4 >> 33)) * prime64_1
217 h64 = h64*prime64_1 + prime64_4 + uint64(n)
178
179 h64 = (h64^(rol31(v1)*prime64_1))*prime64_1 + prime64_4
180 h64 = (h64^(rol31(v2)*prime64_1))*prime64_1 + prime64_4
181 h64 = (h64^(rol31(v3)*prime64_1))*prime64_1 + prime64_4
182 h64 = (h64^(rol31(v4)*prime64_1))*prime64_1 + prime64_4
183
184 h64 += uint64(n)
218185
219186 input = input[p:]
220187 n -= p
224191
225192 p := 0
226193 for n := n - 8; p <= n; p += 8 {
227 p64 := (uint64(input[p+7])<<56 | uint64(input[p+6])<<48 | uint64(input[p+5])<<40 | uint64(input[p+4])<<32 | uint64(input[p+3])<<24 | uint64(input[p+2])<<16 | uint64(input[p+1])<<8 | uint64(input[p])) * prime64_2
228 h64 ^= ((p64 << 31) | (p64 >> 33)) * prime64_1
229 h64 = ((h64<<27)|(h64>>37))*prime64_1 + prime64_4
194 sub := input[p : p+8]
195 h64 ^= rol31(u64(sub)*prime64_2) * prime64_1
196 h64 = rol27(h64)*prime64_1 + prime64_4
230197 }
231198 if p+4 <= n {
232 h64 ^= (uint64(input[p+3])<<24 | uint64(input[p+2])<<16 | uint64(input[p+1])<<8 | uint64(input[p])) * prime64_1
233 h64 = ((h64<<23)|(h64>>41))*prime64_2 + prime64_3
199 sub := input[p : p+4]
200 h64 ^= uint64(u32(sub)) * prime64_1
201 h64 = rol23(h64)*prime64_2 + prime64_3
234202 p += 4
235203 }
236204 for ; p < n; p++ {
237205 h64 ^= uint64(input[p]) * prime64_5
238 h64 = ((h64 << 11) | (h64 >> 53)) * prime64_1
206 h64 = rol11(h64) * prime64_1
239207 }
240208
241209 h64 ^= h64 >> 33
246214
247215 return h64
248216 }
217
218 func u64(buf []byte) uint64 {
219 // go compiler recognizes this pattern and optimizes it on little endian platforms
220 return uint64(buf[0]) | uint64(buf[1])<<8 | uint64(buf[2])<<16 | uint64(buf[3])<<24 | uint64(buf[4])<<32 | uint64(buf[5])<<40 | uint64(buf[6])<<48 | uint64(buf[7])<<56
221 }
222
223 func u32(buf []byte) uint32 {
224 return uint32(buf[0]) | uint32(buf[1])<<8 | uint32(buf[2])<<16 | uint32(buf[3])<<24
225 }
226
227 func rol1(u uint64) uint64 {
228 return u<<1 | u>>63
229 }
230
231 func rol7(u uint64) uint64 {
232 return u<<7 | u>>57
233 }
234
235 func rol11(u uint64) uint64 {
236 return u<<11 | u>>53
237 }
238
239 func rol12(u uint64) uint64 {
240 return u<<12 | u>>52
241 }
242
243 func rol18(u uint64) uint64 {
244 return u<<18 | u>>46
245 }
246
247 func rol23(u uint64) uint64 {
248 return u<<23 | u>>41
249 }
250
251 func rol27(u uint64) uint64 {
252 return u<<27 | u>>37
253 }
254 func rol31(u uint64) uint64 {
255 return u<<31 | u>>33
256 }
1717 )
1818
1919 func main() {
20 seed := flag.Uint64("seed", 0, "seed value")
20 seed := flag.Uint64("seed", 0, "uint32 or uint64 `seed` based on the selected mode (default 0)")
2121 mode := flag.Int("mode", 1, "hash mode: 0=32bits, 1=64bits")
2222 flag.Parse()
2323
2626 xxh = xxHash32.New(uint32(*seed))
2727 } else {
2828 xxh = xxHash64.New(*seed)
29 }
30
31 print := func(s string) {
32 h := xxh.Sum(nil)
33 n := len(h)
34 j := n - 1
35 for i := 0; i < n/2; {
36 h[i], h[j] = h[j], h[i]
37 i++
38 j--
39 }
40 fmt.Printf("%x %s\n", h, s)
41 }
42
43 if len(flag.Args()) == 0 {
44 if _, err := io.Copy(xxh, os.Stdin); err == nil {
45 print("stdin")
46 }
47 return
2948 }
3049
3150 // Process each file in sequence