1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "utils/hash/farmhash.h"
18
19 // FARMHASH ASSUMPTIONS: Modify as needed, or use -DFARMHASH_ASSUME_SSE42 etc.
20 // Note that if you use -DFARMHASH_ASSUME_SSE42 you likely need -msse42
21 // (or its equivalent for your compiler); if you use -DFARMHASH_ASSUME_AESNI
22 // you likely need -maes (or its equivalent for your compiler).
23
24 #ifdef FARMHASH_ASSUME_SSE42
25 #undef FARMHASH_ASSUME_SSE42
26 #define FARMHASH_ASSUME_SSE42 1
27 #endif
28
29 #ifdef FARMHASH_ASSUME_AESNI
30 #undef FARMHASH_ASSUME_AESNI
31 #define FARMHASH_ASSUME_AESNI 1
32 #endif
33
34 #if !defined(FARMHASH_CAN_USE_CXX11) && defined(LANG_CXX11)
35 #define FARMHASH_CAN_USE_CXX11 1
36 #else
37 #undef FARMHASH_CAN_USE_CXX11
38 #define FARMHASH_CAN_USE_CXX11 0
39 #endif
40
41 // FARMHASH PORTABILITY LAYER: Runtime error if misconfigured
42
43 #ifndef FARMHASH_DIE_IF_MISCONFIGURED
44 #define FARMHASH_DIE_IF_MISCONFIGURED do { *(char*)(len % 17) = 0; } while (0)
45 #endif
46
47 // FARMHASH PORTABILITY LAYER: "static inline" or similar
48
49 #ifndef STATIC_INLINE
50 #define STATIC_INLINE static inline
51 #endif
52
53 // FARMHASH PORTABILITY LAYER: LIKELY and UNLIKELY
54
55 #if !defined(LIKELY)
56 #if defined(FARMHASH_OPTIONAL_BUILTIN_EXPECT) && !defined(HAVE_BUILTIN_EXPECT)
57 #define LIKELY(x) (x)
58 #else
59 #define LIKELY(x) (__builtin_expect(!!(x), 1))
60 #endif
61 #endif
62
63 #undef UNLIKELY
64 #define UNLIKELY(x) !LIKELY(!(x))
65
66 // FARMHASH PORTABILITY LAYER: endianness and byteswapping functions
67
68 #ifdef WORDS_BIGENDIAN
69 #undef FARMHASH_BIG_ENDIAN
70 #define FARMHASH_BIG_ENDIAN 1
71 #endif
72
73 #if defined(FARMHASH_LITTLE_ENDIAN) && defined(FARMHASH_BIG_ENDIAN)
74 #error
75 #endif
76
77 #if !defined(FARMHASH_LITTLE_ENDIAN) && !defined(FARMHASH_BIG_ENDIAN)
78 #define FARMHASH_UNKNOWN_ENDIAN 1
79 #endif
80
81 #if !defined(bswap_32) || !defined(bswap_64)
82 #undef bswap_32
83 #undef bswap_64
84
85 #if defined(HAVE_BUILTIN_BSWAP) || defined(__clang__) || \
86 (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 8) || \
87 __GNUC__ >= 5))
88 // Easy case for bswap: no header file needed.
89 #define bswap_32(x) __builtin_bswap32(x)
90 #define bswap_64(x) __builtin_bswap64(x)
91 #endif
92
93 #endif
94
95 #if defined(FARMHASH_UNKNOWN_ENDIAN) || !defined(bswap_64)
96
97 #ifdef _MSC_VER
98
99 #undef bswap_32
100 #undef bswap_64
101 #define bswap_32(x) _byteswap_ulong(x)
102 #define bswap_64(x) _byteswap_uint64(x)
103
104 #elif defined(__APPLE__)
105
106 // Mac OS X / Darwin features
107 #include <libkern/OSByteOrder.h>
108 #undef bswap_32
109 #undef bswap_64
110 #define bswap_32(x) OSSwapInt32(x)
111 #define bswap_64(x) OSSwapInt64(x)
112
113 #elif defined(__sun) || defined(sun)
114
115 #include <sys/byteorder.h>
116 #undef bswap_32
117 #undef bswap_64
118 #define bswap_32(x) BSWAP_32(x)
119 #define bswap_64(x) BSWAP_64(x)
120
121 #elif defined(__FreeBSD__)
122
123 #include <sys/endian.h>
124 #undef bswap_32
125 #undef bswap_64
126 #define bswap_32(x) bswap32(x)
127 #define bswap_64(x) bswap64(x)
128
129 #elif defined(__OpenBSD__)
130
131 #include <sys/types.h>
132 #undef bswap_32
133 #undef bswap_64
134 #define bswap_32(x) swap32(x)
135 #define bswap_64(x) swap64(x)
136
137 #elif defined(__NetBSD__)
138
139 #include <machine/bswap.h>
140 #include <sys/types.h>
141 #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
142 #undef bswap_32
143 #undef bswap_64
144 #define bswap_32(x) bswap32(x)
145 #define bswap_64(x) bswap64(x)
146 #endif
147
148 #else
149
150 #undef bswap_32
151 #undef bswap_64
152 #include <byteswap.h>
153
154 #endif
155
156 #ifdef WORDS_BIGENDIAN
157 #define FARMHASH_BIG_ENDIAN 1
158 #endif
159
160 #endif
161
162 #ifdef FARMHASH_BIG_ENDIAN
163 #define uint32_in_expected_order(x) (bswap_32(x))
164 #define uint64_in_expected_order(x) (bswap_64(x))
165 #else
166 #define uint32_in_expected_order(x) (x)
167 #define uint64_in_expected_order(x) (x)
168 #endif
169
170 namespace NAMESPACE_FOR_HASH_FUNCTIONS {
171
Fetch64(const char * p)172 STATIC_INLINE uint64_t Fetch64(const char *p) {
173 uint64_t result;
174 memcpy(&result, p, sizeof(result));
175 return uint64_in_expected_order(result);
176 }
177
Fetch32(const char * p)178 STATIC_INLINE uint32_t Fetch32(const char *p) {
179 uint32_t result;
180 memcpy(&result, p, sizeof(result));
181 return uint32_in_expected_order(result);
182 }
183
Bswap32(uint32_t val)184 STATIC_INLINE uint32_t Bswap32(uint32_t val) { return bswap_32(val); }
Bswap64(uint64_t val)185 STATIC_INLINE uint64_t Bswap64(uint64_t val) { return bswap_64(val); }
186
187 // FARMHASH PORTABILITY LAYER: bitwise rot
188
BasicRotate32(uint32_t val,int shift)189 STATIC_INLINE uint32_t BasicRotate32(uint32_t val, int shift) {
190 // Avoid shifting by 32: doing so yields an undefined result.
191 return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
192 }
193
BasicRotate64(uint64_t val,int shift)194 STATIC_INLINE uint64_t BasicRotate64(uint64_t val, int shift) {
195 // Avoid shifting by 64: doing so yields an undefined result.
196 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
197 }
198
199 #if defined(_MSC_VER) && defined(FARMHASH_ROTR)
200
Rotate32(uint32_t val,int shift)201 STATIC_INLINE uint32_t Rotate32(uint32_t val, int shift) {
202 return sizeof(unsigned long) == sizeof(val) ?
203 _lrotr(val, shift) :
204 BasicRotate32(val, shift);
205 }
206
Rotate64(uint64_t val,int shift)207 STATIC_INLINE uint64_t Rotate64(uint64_t val, int shift) {
208 return sizeof(unsigned long) == sizeof(val) ?
209 _lrotr(val, shift) :
210 BasicRotate64(val, shift);
211 }
212
213 #else
214
Rotate32(uint32_t val,int shift)215 STATIC_INLINE uint32_t Rotate32(uint32_t val, int shift) {
216 return BasicRotate32(val, shift);
217 }
Rotate64(uint64_t val,int shift)218 STATIC_INLINE uint64_t Rotate64(uint64_t val, int shift) {
219 return BasicRotate64(val, shift);
220 }
221
222 #endif
223
224 } // namespace NAMESPACE_FOR_HASH_FUNCTIONS
225
226 // FARMHASH PORTABILITY LAYER: debug mode or max speed?
227 // One may use -DFARMHASH_DEBUG=1 or -DFARMHASH_DEBUG=0 to force the issue.
228
229 #if !defined(FARMHASH_DEBUG) && (!defined(NDEBUG) || defined(_DEBUG))
230 #define FARMHASH_DEBUG 1
231 #endif
232
233 #undef debug_mode
234 #if FARMHASH_DEBUG
235 #define debug_mode 1
236 #else
237 #define debug_mode 0
238 #endif
239
240 // PLATFORM-SPECIFIC FUNCTIONS AND MACROS
241
242 #undef x86_64
243 #if defined (__x86_64) || defined (__x86_64__)
244 #define x86_64 1
245 #else
246 #define x86_64 0
247 #endif
248
249 #undef x86
250 #if defined(__i386__) || defined(__i386) || defined(__X86__)
251 #define x86 1
252 #else
253 #define x86 x86_64
254 #endif
255
256 #if !defined(is_64bit)
257 #define is_64bit (x86_64 || (sizeof(void*) == 8))
258 #endif
259
260 #undef can_use_sse42
261 #if defined(__SSE4_2__) || defined(FARMHASH_ASSUME_SSE42)
262
263 #include <nmmintrin.h>
264 #define can_use_sse42 1
265 // Now we can use _mm_crc32_u{32,16,8}. And on 64-bit platforms, _mm_crc32_u64.
266
267 #else
268 #define can_use_sse42 0
269 #endif
270
271 #undef can_use_aesni
272 #if defined(__AES__) || defined(FARMHASH_ASSUME_AESNI)
273
274 #include <wmmintrin.h>
275 #define can_use_aesni 1
276 // Now we can use _mm_aesimc_si128 and so on.
277
278 #else
279 #define can_use_aesni 0
280 #endif
281
282 #if can_use_sse42 || can_use_aesni
Load128(const char * s)283 STATIC_INLINE __m128i Load128(const char* s) {
284 return _mm_loadu_si128(reinterpret_cast<const __m128i*>(s));
285 }
286 #endif
287 // Building blocks for hash functions
288
289 // std::swap() was in <algorithm> but is in <utility> from C++11 on.
290 #if !FARMHASH_CAN_USE_CXX11
291 #include <algorithm>
292 #endif
293
294 #undef PERMUTE3
295 #define PERMUTE3(a, b, c) do { std::swap(a, b); std::swap(a, c); } while (0)
296
297 namespace NAMESPACE_FOR_HASH_FUNCTIONS {
298
299 // Some primes between 2^63 and 2^64 for various uses.
300 static const uint64_t k0 = 0xc3a5c85c97cb3127ULL;
301 static const uint64_t k1 = 0xb492b66fbe98f273ULL;
302 static const uint64_t k2 = 0x9ae16a3b2f90404fULL;
303
304 // Magic numbers for 32-bit hashing. Copied from Murmur3.
305 static const uint32_t c1 = 0xcc9e2d51;
306 static const uint32_t c2 = 0x1b873593;
307
308 // A 32-bit to 32-bit integer hash copied from Murmur3.
fmix(uint32_t h)309 STATIC_INLINE uint32_t fmix(uint32_t h)
310 {
311 h ^= h >> 16;
312 h *= 0x85ebca6b;
313 h ^= h >> 13;
314 h *= 0xc2b2ae35;
315 h ^= h >> 16;
316 return h;
317 }
318
Mur(uint32_t a,uint32_t h)319 STATIC_INLINE uint32_t Mur(uint32_t a, uint32_t h) {
320 // Helper from Murmur3 for combining two 32-bit values.
321 a *= c1;
322 a = Rotate32(a, 17);
323 a *= c2;
324 h ^= a;
325 h = Rotate32(h, 19);
326 return h * 5 + 0xe6546b64;
327 }
328
DebugTweak(T x)329 template <typename T> STATIC_INLINE T DebugTweak(T x) {
330 if (debug_mode) {
331 if (sizeof(x) == 4) {
332 x = ~Bswap32(x * c1);
333 } else {
334 x = ~Bswap64(x * k1);
335 }
336 }
337 return x;
338 }
339
DebugTweak(uint128_t x)340 template <> uint128_t DebugTweak(uint128_t x) {
341 if (debug_mode) {
342 uint64_t y = DebugTweak(Uint128Low64(x));
343 uint64_t z = DebugTweak(Uint128High64(x));
344 y += z;
345 z += y;
346 x = Uint128(y, z * k1);
347 }
348 return x;
349 }
350
351 using namespace std;
352 namespace farmhashna {
353 #undef Fetch
354 #define Fetch Fetch64
355
356 #undef Rotate
357 #define Rotate Rotate64
358
359 #undef Bswap
360 #define Bswap Bswap64
361
ShiftMix(uint64_t val)362 STATIC_INLINE uint64_t ShiftMix(uint64_t val) {
363 return val ^ (val >> 47);
364 }
365
HashLen16(uint64_t u,uint64_t v)366 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v) {
367 return Hash128to64(Uint128(u, v));
368 }
369
HashLen16(uint64_t u,uint64_t v,uint64_t mul)370 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul) {
371 // Murmur-inspired hashing.
372 uint64_t a = (u ^ v) * mul;
373 a ^= (a >> 47);
374 uint64_t b = (v ^ a) * mul;
375 b ^= (b >> 47);
376 b *= mul;
377 return b;
378 }
379
HashLen0to16(const char * s,size_t len)380 STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len) {
381 if (len >= 8) {
382 uint64_t mul = k2 + len * 2;
383 uint64_t a = Fetch(s) + k2;
384 uint64_t b = Fetch(s + len - 8);
385 uint64_t c = Rotate(b, 37) * mul + a;
386 uint64_t d = (Rotate(a, 25) + b) * mul;
387 return HashLen16(c, d, mul);
388 }
389 if (len >= 4) {
390 uint64_t mul = k2 + len * 2;
391 uint64_t a = Fetch32(s);
392 return HashLen16(len + (a << 3), Fetch32(s + len - 4), mul);
393 }
394 if (len > 0) {
395 uint8_t a = s[0];
396 uint8_t b = s[len >> 1];
397 uint8_t c = s[len - 1];
398 uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
399 uint32_t z = len + (static_cast<uint32_t>(c) << 2);
400 return ShiftMix(y * k2 ^ z * k0) * k2;
401 }
402 return k2;
403 }
404
405 // This probably works well for 16-byte strings as well, but it may be overkill
406 // in that case.
HashLen17to32(const char * s,size_t len)407 STATIC_INLINE uint64_t HashLen17to32(const char *s, size_t len) {
408 uint64_t mul = k2 + len * 2;
409 uint64_t a = Fetch(s) * k1;
410 uint64_t b = Fetch(s + 8);
411 uint64_t c = Fetch(s + len - 8) * mul;
412 uint64_t d = Fetch(s + len - 16) * k2;
413 return HashLen16(Rotate(a + b, 43) + Rotate(c, 30) + d,
414 a + Rotate(b + k2, 18) + c, mul);
415 }
416
417 // Return a 16-byte hash for 48 bytes. Quick and dirty.
418 // Callers do best to use "random-looking" values for a and b.
WeakHashLen32WithSeeds(uint64_t w,uint64_t x,uint64_t y,uint64_t z,uint64_t a,uint64_t b)419 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
420 uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b) {
421 a += w;
422 b = Rotate(b + a + z, 21);
423 uint64_t c = a;
424 a += x;
425 a += y;
426 b += Rotate(a, 44);
427 return std::make_pair(a + z, b + c);
428 }
429
430 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
WeakHashLen32WithSeeds(const char * s,uint64_t a,uint64_t b)431 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
432 const char* s, uint64_t a, uint64_t b) {
433 return WeakHashLen32WithSeeds(Fetch(s),
434 Fetch(s + 8),
435 Fetch(s + 16),
436 Fetch(s + 24),
437 a,
438 b);
439 }
440
441 // Return an 8-byte hash for 33 to 64 bytes.
HashLen33to64(const char * s,size_t len)442 STATIC_INLINE uint64_t HashLen33to64(const char *s, size_t len) {
443 uint64_t mul = k2 + len * 2;
444 uint64_t a = Fetch(s) * k2;
445 uint64_t b = Fetch(s + 8);
446 uint64_t c = Fetch(s + len - 8) * mul;
447 uint64_t d = Fetch(s + len - 16) * k2;
448 uint64_t y = Rotate(a + b, 43) + Rotate(c, 30) + d;
449 uint64_t z = HashLen16(y, a + Rotate(b + k2, 18) + c, mul);
450 uint64_t e = Fetch(s + 16) * mul;
451 uint64_t f = Fetch(s + 24);
452 uint64_t g = (y + Fetch(s + len - 32)) * mul;
453 uint64_t h = (z + Fetch(s + len - 24)) * mul;
454 return HashLen16(Rotate(e + f, 43) + Rotate(g, 30) + h,
455 e + Rotate(f + a, 18) + g, mul);
456 }
457
Hash64(const char * s,size_t len)458 uint64_t Hash64(const char *s, size_t len) {
459 const uint64_t seed = 81;
460 if (len <= 32) {
461 if (len <= 16) {
462 return HashLen0to16(s, len);
463 } else {
464 return HashLen17to32(s, len);
465 }
466 } else if (len <= 64) {
467 return HashLen33to64(s, len);
468 }
469
470 // For strings over 64 bytes we loop. Internal state consists of
471 // 56 bytes: v, w, x, y, and z.
472 uint64_t x = seed;
473 uint64_t y = seed * k1 + 113;
474 uint64_t z = ShiftMix(y * k2 + 113) * k2;
475 pair<uint64_t, uint64_t> v = std::make_pair(0, 0);
476 pair<uint64_t, uint64_t> w = std::make_pair(0, 0);
477 x = x * k2 + Fetch(s);
478
479 // Set end so that after the loop we have 1 to 64 bytes left to process.
480 const char* end = s + ((len - 1) / 64) * 64;
481 const char* last64 = end + ((len - 1) & 63) - 63;
482 assert(s + len - 64 == last64);
483 do {
484 x = Rotate(x + y + v.first + Fetch(s + 8), 37) * k1;
485 y = Rotate(y + v.second + Fetch(s + 48), 42) * k1;
486 x ^= w.second;
487 y += v.first + Fetch(s + 40);
488 z = Rotate(z + w.first, 33) * k1;
489 v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first);
490 w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16));
491 std::swap(z, x);
492 s += 64;
493 } while (s != end);
494 uint64_t mul = k1 + ((z & 0xff) << 1);
495 // Make s point to the last 64 bytes of input.
496 s = last64;
497 w.first += ((len - 1) & 63);
498 v.first += w.first;
499 w.first += v.first;
500 x = Rotate(x + y + v.first + Fetch(s + 8), 37) * mul;
501 y = Rotate(y + v.second + Fetch(s + 48), 42) * mul;
502 x ^= w.second * 9;
503 y += v.first * 9 + Fetch(s + 40);
504 z = Rotate(z + w.first, 33) * mul;
505 v = WeakHashLen32WithSeeds(s, v.second * mul, x + w.first);
506 w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16));
507 std::swap(z, x);
508 return HashLen16(HashLen16(v.first, w.first, mul) + ShiftMix(y) * k0 + z,
509 HashLen16(v.second, w.second, mul) + x,
510 mul);
511 }
512
513 uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1);
514
Hash64WithSeed(const char * s,size_t len,uint64_t seed)515 uint64_t Hash64WithSeed(const char *s, size_t len, uint64_t seed) {
516 return Hash64WithSeeds(s, len, k2, seed);
517 }
518
Hash64WithSeeds(const char * s,size_t len,uint64_t seed0,uint64_t seed1)519 uint64_t Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1) {
520 return HashLen16(Hash64(s, len) - seed0, seed1);
521 }
522 } // namespace farmhashna
523 namespace farmhashmk {
524 #undef Fetch
525 #define Fetch Fetch32
526
527 #undef Rotate
528 #define Rotate Rotate32
529
530 #undef Bswap
531 #define Bswap Bswap32
532
Hash32Len13to24(const char * s,size_t len,uint32_t seed=0)533 STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len, uint32_t seed = 0) {
534 uint32_t a = Fetch(s - 4 + (len >> 1));
535 uint32_t b = Fetch(s + 4);
536 uint32_t c = Fetch(s + len - 8);
537 uint32_t d = Fetch(s + (len >> 1));
538 uint32_t e = Fetch(s);
539 uint32_t f = Fetch(s + len - 4);
540 uint32_t h = d * c1 + len + seed;
541 a = Rotate(a, 12) + f;
542 h = Mur(c, h) + a;
543 a = Rotate(a, 3) + c;
544 h = Mur(e, h) + a;
545 a = Rotate(a + f, 12) + d;
546 h = Mur(b ^ seed, h) + a;
547 return fmix(h);
548 }
549
Hash32Len0to4(const char * s,size_t len,uint32_t seed=0)550 STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len, uint32_t seed = 0) {
551 uint32_t b = seed;
552 uint32_t c = 9;
553 for (size_t i = 0; i < len; i++) {
554 signed char v = s[i];
555 b = b * c1 + v;
556 c ^= b;
557 }
558 return fmix(Mur(b, Mur(len, c)));
559 }
560
Hash32Len5to12(const char * s,size_t len,uint32_t seed=0)561 STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len, uint32_t seed = 0) {
562 uint32_t a = len, b = len * 5, c = 9, d = b + seed;
563 a += Fetch(s);
564 b += Fetch(s + len - 4);
565 c += Fetch(s + ((len >> 1) & 4));
566 return fmix(seed ^ Mur(c, Mur(b, Mur(a, d))));
567 }
568
Hash32(const char * s,size_t len)569 uint32_t Hash32(const char *s, size_t len) {
570 if (len <= 24) {
571 return len <= 12 ?
572 (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
573 Hash32Len13to24(s, len);
574 }
575
576 // len > 24
577 uint32_t h = len, g = c1 * len, f = g;
578 uint32_t a0 = Rotate(Fetch(s + len - 4) * c1, 17) * c2;
579 uint32_t a1 = Rotate(Fetch(s + len - 8) * c1, 17) * c2;
580 uint32_t a2 = Rotate(Fetch(s + len - 16) * c1, 17) * c2;
581 uint32_t a3 = Rotate(Fetch(s + len - 12) * c1, 17) * c2;
582 uint32_t a4 = Rotate(Fetch(s + len - 20) * c1, 17) * c2;
583 h ^= a0;
584 h = Rotate(h, 19);
585 h = h * 5 + 0xe6546b64;
586 h ^= a2;
587 h = Rotate(h, 19);
588 h = h * 5 + 0xe6546b64;
589 g ^= a1;
590 g = Rotate(g, 19);
591 g = g * 5 + 0xe6546b64;
592 g ^= a3;
593 g = Rotate(g, 19);
594 g = g * 5 + 0xe6546b64;
595 f += a4;
596 f = Rotate(f, 19) + 113;
597 size_t iters = (len - 1) / 20;
598 do {
599 uint32_t a = Fetch(s);
600 uint32_t b = Fetch(s + 4);
601 uint32_t c = Fetch(s + 8);
602 uint32_t d = Fetch(s + 12);
603 uint32_t e = Fetch(s + 16);
604 h += a;
605 g += b;
606 f += c;
607 h = Mur(d, h) + e;
608 g = Mur(c, g) + a;
609 f = Mur(b + e * c1, f) + d;
610 f += g;
611 g += f;
612 s += 20;
613 } while (--iters != 0);
614 g = Rotate(g, 11) * c1;
615 g = Rotate(g, 17) * c1;
616 f = Rotate(f, 11) * c1;
617 f = Rotate(f, 17) * c1;
618 h = Rotate(h + g, 19);
619 h = h * 5 + 0xe6546b64;
620 h = Rotate(h, 17) * c1;
621 h = Rotate(h + f, 19);
622 h = h * 5 + 0xe6546b64;
623 h = Rotate(h, 17) * c1;
624 return h;
625 }
626
Hash32WithSeed(const char * s,size_t len,uint32_t seed)627 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
628 if (len <= 24) {
629 if (len >= 13) return Hash32Len13to24(s, len, seed * c1);
630 else if (len >= 5) return Hash32Len5to12(s, len, seed);
631 else return Hash32Len0to4(s, len, seed);
632 }
633 uint32_t h = Hash32Len13to24(s, 24, seed ^ len);
634 return Mur(Hash32(s + 24, len - 24) + seed, h);
635 }
636 } // namespace farmhashmk
637 namespace farmhashsu {
638 #if !can_use_sse42 || !can_use_aesni
639
Hash32(const char * s,size_t len)640 uint32_t Hash32(const char *s, size_t len) {
641 FARMHASH_DIE_IF_MISCONFIGURED;
642 return s == nullptr ? 0 : len;
643 }
644
Hash32WithSeed(const char * s,size_t len,uint32_t seed)645 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
646 FARMHASH_DIE_IF_MISCONFIGURED;
647 return seed + Hash32(s, len);
648 }
649
650 #else
651
652 #undef Fetch
653 #define Fetch Fetch32
654
655 #undef Rotate
656 #define Rotate Rotate32
657
658 #undef Bswap
659 #define Bswap Bswap32
660
661 // Helpers for data-parallel operations (4x 32-bits).
662 STATIC_INLINE __m128i Add(__m128i x, __m128i y) { return _mm_add_epi32(x, y); }
663 STATIC_INLINE __m128i Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
664 STATIC_INLINE __m128i Or(__m128i x, __m128i y) { return _mm_or_si128(x, y); }
665 STATIC_INLINE __m128i Mul(__m128i x, __m128i y) { return _mm_mullo_epi32(x, y); }
666 STATIC_INLINE __m128i Mul5(__m128i x) { return Add(x, _mm_slli_epi32(x, 2)); }
667 STATIC_INLINE __m128i Rotate(__m128i x, int c) {
668 return Or(_mm_slli_epi32(x, c),
669 _mm_srli_epi32(x, 32 - c));
670 }
671 STATIC_INLINE __m128i Rot17(__m128i x) { return Rotate(x, 17); }
672 STATIC_INLINE __m128i Rot19(__m128i x) { return Rotate(x, 19); }
673 STATIC_INLINE __m128i Shuffle0321(__m128i x) {
674 return _mm_shuffle_epi32(x, (0 << 6) + (3 << 4) + (2 << 2) + (1 << 0));
675 }
676 STATIC_INLINE __m128i Shuffle2031(__m128i x) {
677 return _mm_shuffle_epi32(x, (2 << 6) + (0 << 4) + (3 << 2) + (1 << 0));
678 }
679
680 uint32_t Hash32(const char *s, size_t len) {
681 const uint32_t seed = 81;
682 if (len <= 24) {
683 return len <= 12 ?
684 (len <= 4 ?
685 farmhashmk::Hash32Len0to4(s, len) :
686 farmhashmk::Hash32Len5to12(s, len)) :
687 farmhashmk::Hash32Len13to24(s, len);
688 }
689
690 if (len < 40) {
691 uint32_t a = len, b = seed * c2, c = a + b;
692 a += Fetch(s + len - 4);
693 b += Fetch(s + len - 20);
694 c += Fetch(s + len - 16);
695 uint32_t d = a;
696 a = NAMESPACE_FOR_HASH_FUNCTIONS::Rotate32(a, 21);
697 a = Mur(a, Mur(b, _mm_crc32_u32(c, d)));
698 a += Fetch(s + len - 12);
699 b += Fetch(s + len - 8);
700 d += a;
701 a += d;
702 b = Mur(b, d) * c2;
703 a = _mm_crc32_u32(a, b + c);
704 return farmhashmk::Hash32Len13to24(s, (len + 1) / 2, a) + b;
705 }
706
707 #undef Mulc1
708 #define Mulc1(x) Mul((x), cc1)
709
710 #undef Mulc2
711 #define Mulc2(x) Mul((x), cc2)
712
713 #undef Murk
714 #define Murk(a, h) \
715 Add(k, \
716 Mul5( \
717 Rot19( \
718 Xor( \
719 Mulc2( \
720 Rot17( \
721 Mulc1(a))), \
722 (h)))))
723
724 const __m128i cc1 = _mm_set1_epi32(c1);
725 const __m128i cc2 = _mm_set1_epi32(c2);
726 __m128i h = _mm_set1_epi32(seed);
727 __m128i g = _mm_set1_epi32(c1 * seed);
728 __m128i f = g;
729 __m128i k = _mm_set1_epi32(0xe6546b64);
730 __m128i q;
731 if (len < 80) {
732 __m128i a = Load128(s);
733 __m128i b = Load128(s + 16);
734 __m128i c = Load128(s + (len - 15) / 2);
735 __m128i d = Load128(s + len - 32);
736 __m128i e = Load128(s + len - 16);
737 h = Add(h, a);
738 g = Add(g, b);
739 q = g;
740 g = Shuffle0321(g);
741 f = Add(f, c);
742 __m128i be = Add(b, Mulc1(e));
743 h = Add(h, f);
744 f = Add(f, h);
745 h = Add(Murk(d, h), e);
746 k = Xor(k, _mm_shuffle_epi8(g, f));
747 g = Add(Xor(c, g), a);
748 f = Add(Xor(be, f), d);
749 k = Add(k, be);
750 k = Add(k, _mm_shuffle_epi8(f, h));
751 f = Add(f, g);
752 g = Add(g, f);
753 g = Add(_mm_set1_epi32(len), Mulc1(g));
754 } else {
755 // len >= 80
756 // The following is loosely modelled after farmhashmk::Hash32.
757 size_t iters = (len - 1) / 80;
758 len -= iters * 80;
759
760 #undef Chunk
761 #define Chunk() do { \
762 __m128i a = Load128(s); \
763 __m128i b = Load128(s + 16); \
764 __m128i c = Load128(s + 32); \
765 __m128i d = Load128(s + 48); \
766 __m128i e = Load128(s + 64); \
767 h = Add(h, a); \
768 g = Add(g, b); \
769 g = Shuffle0321(g); \
770 f = Add(f, c); \
771 __m128i be = Add(b, Mulc1(e)); \
772 h = Add(h, f); \
773 f = Add(f, h); \
774 h = Add(h, d); \
775 q = Add(q, e); \
776 h = Rot17(h); \
777 h = Mulc1(h); \
778 k = Xor(k, _mm_shuffle_epi8(g, f)); \
779 g = Add(Xor(c, g), a); \
780 f = Add(Xor(be, f), d); \
781 std::swap(f, q); \
782 q = _mm_aesimc_si128(q); \
783 k = Add(k, be); \
784 k = Add(k, _mm_shuffle_epi8(f, h)); \
785 f = Add(f, g); \
786 g = Add(g, f); \
787 f = Mulc1(f); \
788 } while (0)
789
790 q = g;
791 while (iters-- != 0) {
792 Chunk();
793 s += 80;
794 }
795
796 if (len != 0) {
797 h = Add(h, _mm_set1_epi32(len));
798 s = s + len - 80;
799 Chunk();
800 }
801 }
802
803 g = Shuffle0321(g);
804 k = Xor(k, g);
805 k = Xor(k, q);
806 h = Xor(h, q);
807 f = Mulc1(f);
808 k = Mulc2(k);
809 g = Mulc1(g);
810 h = Mulc2(h);
811 k = Add(k, _mm_shuffle_epi8(g, f));
812 h = Add(h, f);
813 f = Add(f, h);
814 g = Add(g, k);
815 k = Add(k, g);
816 k = Xor(k, _mm_shuffle_epi8(f, h));
817 __m128i buf[4];
818 buf[0] = f;
819 buf[1] = g;
820 buf[2] = k;
821 buf[3] = h;
822 s = reinterpret_cast<char*>(buf);
823 uint32_t x = Fetch(s);
824 uint32_t y = Fetch(s+4);
825 uint32_t z = Fetch(s+8);
826 x = _mm_crc32_u32(x, Fetch(s+12));
827 y = _mm_crc32_u32(y, Fetch(s+16));
828 z = _mm_crc32_u32(z * c1, Fetch(s+20));
829 x = _mm_crc32_u32(x, Fetch(s+24));
830 y = _mm_crc32_u32(y * c1, Fetch(s+28));
831 uint32_t o = y;
832 z = _mm_crc32_u32(z, Fetch(s+32));
833 x = _mm_crc32_u32(x * c1, Fetch(s+36));
834 y = _mm_crc32_u32(y, Fetch(s+40));
835 z = _mm_crc32_u32(z * c1, Fetch(s+44));
836 x = _mm_crc32_u32(x, Fetch(s+48));
837 y = _mm_crc32_u32(y * c1, Fetch(s+52));
838 z = _mm_crc32_u32(z, Fetch(s+56));
839 x = _mm_crc32_u32(x, Fetch(s+60));
840 return (o - x + y - z) * c1;
841 }
842
843 #undef Chunk
844 #undef Murk
845 #undef Mulc2
846 #undef Mulc1
847
848 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
849 if (len <= 24) {
850 if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * c1);
851 else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
852 else return farmhashmk::Hash32Len0to4(s, len, seed);
853 }
854 uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
855 return _mm_crc32_u32(Hash32(s + 24, len - 24) + seed, h);
856 }
857
858 #endif
859 } // namespace farmhashsu
860 namespace farmhashns {
861 #if !can_use_sse42 || !can_use_aesni || !x86_64
862
Hash32(const char * s,size_t len)863 uint32_t Hash32(const char *s, size_t len) {
864 FARMHASH_DIE_IF_MISCONFIGURED;
865 return s == nullptr ? 0 : len;
866 }
867
Hash32WithSeed(const char * s,size_t len,uint32_t seed)868 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
869 FARMHASH_DIE_IF_MISCONFIGURED;
870 return seed + Hash32(s, len);
871 }
872
873 #else
874
875 uint32_t Hash32(const char *s, size_t len) {
876 return len <= 256 ?
877 static_cast<uint32_t>(farmhashna::Hash64(s, len)) :
878 farmhashsu::Hash32(s, len);
879 }
880
881 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
882 return len <= 256 ?
883 static_cast<uint32_t>(farmhashna::Hash64WithSeed(s, len, seed)) :
884 farmhashsu::Hash32WithSeed(s, len, seed);
885 }
886
887 #endif
888 } // namespace farmhashns
889 namespace farmhashsa {
890 #if !can_use_sse42
891
Hash32(const char * s,size_t len)892 uint32_t Hash32(const char *s, size_t len) {
893 FARMHASH_DIE_IF_MISCONFIGURED;
894 return s == nullptr ? 0 : len;
895 }
896
Hash32WithSeed(const char * s,size_t len,uint32_t seed)897 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
898 FARMHASH_DIE_IF_MISCONFIGURED;
899 return seed + Hash32(s, len);
900 }
901
902 #else
903
904 #undef Fetch
905 #define Fetch Fetch32
906
907 #undef Rotate
908 #define Rotate Rotate32
909
910 #undef Bswap
911 #define Bswap Bswap32
912
913 // Helpers for data-parallel operations (4x 32-bits).
914 STATIC_INLINE __m128i Add(__m128i x, __m128i y) { return _mm_add_epi32(x, y); }
915 STATIC_INLINE __m128i Xor(__m128i x, __m128i y) { return _mm_xor_si128(x, y); }
916 STATIC_INLINE __m128i Or(__m128i x, __m128i y) { return _mm_or_si128(x, y); }
917 STATIC_INLINE __m128i Mul(__m128i x, __m128i y) { return _mm_mullo_epi32(x, y); }
918 STATIC_INLINE __m128i Mul5(__m128i x) { return Add(x, _mm_slli_epi32(x, 2)); }
919 STATIC_INLINE __m128i Rotate(__m128i x, int c) {
920 return Or(_mm_slli_epi32(x, c),
921 _mm_srli_epi32(x, 32 - c));
922 }
923 STATIC_INLINE __m128i Rot17(__m128i x) { return Rotate(x, 17); }
924 STATIC_INLINE __m128i Rot19(__m128i x) { return Rotate(x, 19); }
925 STATIC_INLINE __m128i Shuffle0321(__m128i x) {
926 return _mm_shuffle_epi32(x, (0 << 6) + (3 << 4) + (2 << 2) + (1 << 0));
927 }
928
929 uint32_t Hash32(const char *s, size_t len) {
930 const uint32_t seed = 81;
931 if (len <= 24) {
932 return len <= 12 ?
933 (len <= 4 ?
934 farmhashmk::Hash32Len0to4(s, len) :
935 farmhashmk::Hash32Len5to12(s, len)) :
936 farmhashmk::Hash32Len13to24(s, len);
937 }
938
939 if (len < 40) {
940 uint32_t a = len, b = seed * c2, c = a + b;
941 a += Fetch(s + len - 4);
942 b += Fetch(s + len - 20);
943 c += Fetch(s + len - 16);
944 uint32_t d = a;
945 a = NAMESPACE_FOR_HASH_FUNCTIONS::Rotate32(a, 21);
946 a = Mur(a, Mur(b, Mur(c, d)));
947 a += Fetch(s + len - 12);
948 b += Fetch(s + len - 8);
949 d += a;
950 a += d;
951 b = Mur(b, d) * c2;
952 a = _mm_crc32_u32(a, b + c);
953 return farmhashmk::Hash32Len13to24(s, (len + 1) / 2, a) + b;
954 }
955
956 #undef Mulc1
957 #define Mulc1(x) Mul((x), cc1)
958
959 #undef Mulc2
960 #define Mulc2(x) Mul((x), cc2)
961
962 #undef Murk
963 #define Murk(a, h) \
964 Add(k, \
965 Mul5( \
966 Rot19( \
967 Xor( \
968 Mulc2( \
969 Rot17( \
970 Mulc1(a))), \
971 (h)))))
972
973 const __m128i cc1 = _mm_set1_epi32(c1);
974 const __m128i cc2 = _mm_set1_epi32(c2);
975 __m128i h = _mm_set1_epi32(seed);
976 __m128i g = _mm_set1_epi32(c1 * seed);
977 __m128i f = g;
978 __m128i k = _mm_set1_epi32(0xe6546b64);
979 if (len < 80) {
980 __m128i a = Load128(s);
981 __m128i b = Load128(s + 16);
982 __m128i c = Load128(s + (len - 15) / 2);
983 __m128i d = Load128(s + len - 32);
984 __m128i e = Load128(s + len - 16);
985 h = Add(h, a);
986 g = Add(g, b);
987 g = Shuffle0321(g);
988 f = Add(f, c);
989 __m128i be = Add(b, Mulc1(e));
990 h = Add(h, f);
991 f = Add(f, h);
992 h = Add(Murk(d, h), e);
993 k = Xor(k, _mm_shuffle_epi8(g, f));
994 g = Add(Xor(c, g), a);
995 f = Add(Xor(be, f), d);
996 k = Add(k, be);
997 k = Add(k, _mm_shuffle_epi8(f, h));
998 f = Add(f, g);
999 g = Add(g, f);
1000 g = Add(_mm_set1_epi32(len), Mulc1(g));
1001 } else {
1002 // len >= 80
1003 // The following is loosely modelled after farmhashmk::Hash32.
1004 size_t iters = (len - 1) / 80;
1005 len -= iters * 80;
1006
1007 #undef Chunk
1008 #define Chunk() do { \
1009 __m128i a = Load128(s); \
1010 __m128i b = Load128(s + 16); \
1011 __m128i c = Load128(s + 32); \
1012 __m128i d = Load128(s + 48); \
1013 __m128i e = Load128(s + 64); \
1014 h = Add(h, a); \
1015 g = Add(g, b); \
1016 g = Shuffle0321(g); \
1017 f = Add(f, c); \
1018 __m128i be = Add(b, Mulc1(e)); \
1019 h = Add(h, f); \
1020 f = Add(f, h); \
1021 h = Add(Murk(d, h), e); \
1022 k = Xor(k, _mm_shuffle_epi8(g, f)); \
1023 g = Add(Xor(c, g), a); \
1024 f = Add(Xor(be, f), d); \
1025 k = Add(k, be); \
1026 k = Add(k, _mm_shuffle_epi8(f, h)); \
1027 f = Add(f, g); \
1028 g = Add(g, f); \
1029 f = Mulc1(f); \
1030 } while (0)
1031
1032 while (iters-- != 0) {
1033 Chunk();
1034 s += 80;
1035 }
1036
1037 if (len != 0) {
1038 h = Add(h, _mm_set1_epi32(len));
1039 s = s + len - 80;
1040 Chunk();
1041 }
1042 }
1043
1044 g = Shuffle0321(g);
1045 k = Xor(k, g);
1046 f = Mulc1(f);
1047 k = Mulc2(k);
1048 g = Mulc1(g);
1049 h = Mulc2(h);
1050 k = Add(k, _mm_shuffle_epi8(g, f));
1051 h = Add(h, f);
1052 f = Add(f, h);
1053 g = Add(g, k);
1054 k = Add(k, g);
1055 k = Xor(k, _mm_shuffle_epi8(f, h));
1056 __m128i buf[4];
1057 buf[0] = f;
1058 buf[1] = g;
1059 buf[2] = k;
1060 buf[3] = h;
1061 s = reinterpret_cast<char*>(buf);
1062 uint32_t x = Fetch(s);
1063 uint32_t y = Fetch(s+4);
1064 uint32_t z = Fetch(s+8);
1065 x = _mm_crc32_u32(x, Fetch(s+12));
1066 y = _mm_crc32_u32(y, Fetch(s+16));
1067 z = _mm_crc32_u32(z * c1, Fetch(s+20));
1068 x = _mm_crc32_u32(x, Fetch(s+24));
1069 y = _mm_crc32_u32(y * c1, Fetch(s+28));
1070 uint32_t o = y;
1071 z = _mm_crc32_u32(z, Fetch(s+32));
1072 x = _mm_crc32_u32(x * c1, Fetch(s+36));
1073 y = _mm_crc32_u32(y, Fetch(s+40));
1074 z = _mm_crc32_u32(z * c1, Fetch(s+44));
1075 x = _mm_crc32_u32(x, Fetch(s+48));
1076 y = _mm_crc32_u32(y * c1, Fetch(s+52));
1077 z = _mm_crc32_u32(z, Fetch(s+56));
1078 x = _mm_crc32_u32(x, Fetch(s+60));
1079 return (o - x + y - z) * c1;
1080 }
1081
1082 #undef Chunk
1083 #undef Murk
1084 #undef Mulc2
1085 #undef Mulc1
1086
1087 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1088 if (len <= 24) {
1089 if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * c1);
1090 else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
1091 else return farmhashmk::Hash32Len0to4(s, len, seed);
1092 }
1093 uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
1094 return _mm_crc32_u32(Hash32(s + 24, len - 24) + seed, h);
1095 }
1096
1097 #endif
1098 } // namespace farmhashsa
1099 namespace farmhashcc {
1100 // This file provides a 32-bit hash equivalent to CityHash32 (v1.1.1)
1101 // and a 128-bit hash equivalent to CityHash128 (v1.1.1). It also provides
1102 // a seeded 32-bit hash function similar to CityHash32.
1103
1104 #undef Fetch
1105 #define Fetch Fetch32
1106
1107 #undef Rotate
1108 #define Rotate Rotate32
1109
1110 #undef Bswap
1111 #define Bswap Bswap32
1112
Hash32Len13to24(const char * s,size_t len)1113 STATIC_INLINE uint32_t Hash32Len13to24(const char *s, size_t len) {
1114 uint32_t a = Fetch(s - 4 + (len >> 1));
1115 uint32_t b = Fetch(s + 4);
1116 uint32_t c = Fetch(s + len - 8);
1117 uint32_t d = Fetch(s + (len >> 1));
1118 uint32_t e = Fetch(s);
1119 uint32_t f = Fetch(s + len - 4);
1120 uint32_t h = len;
1121
1122 return fmix(Mur(f, Mur(e, Mur(d, Mur(c, Mur(b, Mur(a, h)))))));
1123 }
1124
Hash32Len0to4(const char * s,size_t len)1125 STATIC_INLINE uint32_t Hash32Len0to4(const char *s, size_t len) {
1126 uint32_t b = 0;
1127 uint32_t c = 9;
1128 for (size_t i = 0; i < len; i++) {
1129 signed char v = s[i];
1130 b = b * c1 + v;
1131 c ^= b;
1132 }
1133 return fmix(Mur(b, Mur(len, c)));
1134 }
1135
Hash32Len5to12(const char * s,size_t len)1136 STATIC_INLINE uint32_t Hash32Len5to12(const char *s, size_t len) {
1137 uint32_t a = len, b = len * 5, c = 9, d = b;
1138 a += Fetch(s);
1139 b += Fetch(s + len - 4);
1140 c += Fetch(s + ((len >> 1) & 4));
1141 return fmix(Mur(c, Mur(b, Mur(a, d))));
1142 }
1143
Hash32(const char * s,size_t len)1144 uint32_t Hash32(const char *s, size_t len) {
1145 if (len <= 24) {
1146 return len <= 12 ?
1147 (len <= 4 ? Hash32Len0to4(s, len) : Hash32Len5to12(s, len)) :
1148 Hash32Len13to24(s, len);
1149 }
1150
1151 // len > 24
1152 uint32_t h = len, g = c1 * len, f = g;
1153 uint32_t a0 = Rotate(Fetch(s + len - 4) * c1, 17) * c2;
1154 uint32_t a1 = Rotate(Fetch(s + len - 8) * c1, 17) * c2;
1155 uint32_t a2 = Rotate(Fetch(s + len - 16) * c1, 17) * c2;
1156 uint32_t a3 = Rotate(Fetch(s + len - 12) * c1, 17) * c2;
1157 uint32_t a4 = Rotate(Fetch(s + len - 20) * c1, 17) * c2;
1158 h ^= a0;
1159 h = Rotate(h, 19);
1160 h = h * 5 + 0xe6546b64;
1161 h ^= a2;
1162 h = Rotate(h, 19);
1163 h = h * 5 + 0xe6546b64;
1164 g ^= a1;
1165 g = Rotate(g, 19);
1166 g = g * 5 + 0xe6546b64;
1167 g ^= a3;
1168 g = Rotate(g, 19);
1169 g = g * 5 + 0xe6546b64;
1170 f += a4;
1171 f = Rotate(f, 19);
1172 f = f * 5 + 0xe6546b64;
1173 size_t iters = (len - 1) / 20;
1174 do {
1175 uint32_t a0 = Rotate(Fetch(s) * c1, 17) * c2;
1176 uint32_t a1 = Fetch(s + 4);
1177 uint32_t a2 = Rotate(Fetch(s + 8) * c1, 17) * c2;
1178 uint32_t a3 = Rotate(Fetch(s + 12) * c1, 17) * c2;
1179 uint32_t a4 = Fetch(s + 16);
1180 h ^= a0;
1181 h = Rotate(h, 18);
1182 h = h * 5 + 0xe6546b64;
1183 f += a1;
1184 f = Rotate(f, 19);
1185 f = f * c1;
1186 g += a2;
1187 g = Rotate(g, 18);
1188 g = g * 5 + 0xe6546b64;
1189 h ^= a3 + a1;
1190 h = Rotate(h, 19);
1191 h = h * 5 + 0xe6546b64;
1192 g ^= a4;
1193 g = Bswap(g) * 5;
1194 h += a4 * 5;
1195 h = Bswap(h);
1196 f += a0;
1197 PERMUTE3(f, h, g);
1198 s += 20;
1199 } while (--iters != 0);
1200 g = Rotate(g, 11) * c1;
1201 g = Rotate(g, 17) * c1;
1202 f = Rotate(f, 11) * c1;
1203 f = Rotate(f, 17) * c1;
1204 h = Rotate(h + g, 19);
1205 h = h * 5 + 0xe6546b64;
1206 h = Rotate(h, 17) * c1;
1207 h = Rotate(h + f, 19);
1208 h = h * 5 + 0xe6546b64;
1209 h = Rotate(h, 17) * c1;
1210 return h;
1211 }
1212
Hash32WithSeed(const char * s,size_t len,uint32_t seed)1213 uint32_t Hash32WithSeed(const char *s, size_t len, uint32_t seed) {
1214 if (len <= 24) {
1215 if (len >= 13) return farmhashmk::Hash32Len13to24(s, len, seed * c1);
1216 else if (len >= 5) return farmhashmk::Hash32Len5to12(s, len, seed);
1217 else return farmhashmk::Hash32Len0to4(s, len, seed);
1218 }
1219 uint32_t h = farmhashmk::Hash32Len13to24(s, 24, seed ^ len);
1220 return Mur(Hash32(s + 24, len - 24) + seed, h);
1221 }
1222
1223 #undef Fetch
1224 #define Fetch Fetch64
1225
1226 #undef Rotate
1227 #define Rotate Rotate64
1228
1229 #undef Bswap
1230 #define Bswap Bswap64
1231
ShiftMix(uint64_t val)1232 STATIC_INLINE uint64_t ShiftMix(uint64_t val) {
1233 return val ^ (val >> 47);
1234 }
1235
HashLen16(uint64_t u,uint64_t v)1236 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v) {
1237 return Hash128to64(Uint128(u, v));
1238 }
1239
HashLen16(uint64_t u,uint64_t v,uint64_t mul)1240 STATIC_INLINE uint64_t HashLen16(uint64_t u, uint64_t v, uint64_t mul) {
1241 // Murmur-inspired hashing.
1242 uint64_t a = (u ^ v) * mul;
1243 a ^= (a >> 47);
1244 uint64_t b = (v ^ a) * mul;
1245 b ^= (b >> 47);
1246 b *= mul;
1247 return b;
1248 }
1249
HashLen0to16(const char * s,size_t len)1250 STATIC_INLINE uint64_t HashLen0to16(const char *s, size_t len) {
1251 if (len >= 8) {
1252 uint64_t mul = k2 + len * 2;
1253 uint64_t a = Fetch(s) + k2;
1254 uint64_t b = Fetch(s + len - 8);
1255 uint64_t c = Rotate(b, 37) * mul + a;
1256 uint64_t d = (Rotate(a, 25) + b) * mul;
1257 return HashLen16(c, d, mul);
1258 }
1259 if (len >= 4) {
1260 uint64_t mul = k2 + len * 2;
1261 uint64_t a = Fetch32(s);
1262 return HashLen16(len + (a << 3), Fetch32(s + len - 4), mul);
1263 }
1264 if (len > 0) {
1265 uint8_t a = s[0];
1266 uint8_t b = s[len >> 1];
1267 uint8_t c = s[len - 1];
1268 uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
1269 uint32_t z = len + (static_cast<uint32_t>(c) << 2);
1270 return ShiftMix(y * k2 ^ z * k0) * k2;
1271 }
1272 return k2;
1273 }
1274
1275 // Return a 16-byte hash for 48 bytes. Quick and dirty.
1276 // Callers do best to use "random-looking" values for a and b.
WeakHashLen32WithSeeds(uint64_t w,uint64_t x,uint64_t y,uint64_t z,uint64_t a,uint64_t b)1277 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
1278 uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b) {
1279 a += w;
1280 b = Rotate(b + a + z, 21);
1281 uint64_t c = a;
1282 a += x;
1283 a += y;
1284 b += Rotate(a, 44);
1285 return std::make_pair(a + z, b + c);
1286 }
1287
1288 // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
WeakHashLen32WithSeeds(const char * s,uint64_t a,uint64_t b)1289 STATIC_INLINE pair<uint64_t, uint64_t> WeakHashLen32WithSeeds(
1290 const char* s, uint64_t a, uint64_t b) {
1291 return WeakHashLen32WithSeeds(Fetch(s),
1292 Fetch(s + 8),
1293 Fetch(s + 16),
1294 Fetch(s + 24),
1295 a,
1296 b);
1297 }
1298
1299
1300
1301 // A subroutine for CityHash128(). Returns a decent 128-bit hash for strings
1302 // of any length representable in signed long. Based on City and Murmur.
CityMurmur(const char * s,size_t len,uint128_t seed)1303 STATIC_INLINE uint128_t CityMurmur(const char *s, size_t len, uint128_t seed) {
1304 uint64_t a = Uint128Low64(seed);
1305 uint64_t b = Uint128High64(seed);
1306 uint64_t c = 0;
1307 uint64_t d = 0;
1308 signed long l = len - 16;
1309 if (l <= 0) { // len <= 16
1310 a = ShiftMix(a * k1) * k1;
1311 c = b * k1 + HashLen0to16(s, len);
1312 d = ShiftMix(a + (len >= 8 ? Fetch(s) : c));
1313 } else { // len > 16
1314 c = HashLen16(Fetch(s + len - 8) + k1, a);
1315 d = HashLen16(b + len, c + Fetch(s + len - 16));
1316 a += d;
1317 do {
1318 a ^= ShiftMix(Fetch(s) * k1) * k1;
1319 a *= k1;
1320 b ^= a;
1321 c ^= ShiftMix(Fetch(s + 8) * k1) * k1;
1322 c *= k1;
1323 d ^= c;
1324 s += 16;
1325 l -= 16;
1326 } while (l > 0);
1327 }
1328 a = HashLen16(a, c);
1329 b = HashLen16(d, b);
1330 return uint128_t(a ^ b, HashLen16(b, a));
1331 }
1332
CityHash128WithSeed(const char * s,size_t len,uint128_t seed)1333 uint128_t CityHash128WithSeed(const char *s, size_t len, uint128_t seed) {
1334 if (len < 128) {
1335 return CityMurmur(s, len, seed);
1336 }
1337
1338 // We expect len >= 128 to be the common case. Keep 56 bytes of state:
1339 // v, w, x, y, and z.
1340 pair<uint64_t, uint64_t> v, w;
1341 uint64_t x = Uint128Low64(seed);
1342 uint64_t y = Uint128High64(seed);
1343 uint64_t z = len * k1;
1344 v.first = Rotate(y ^ k1, 49) * k1 + Fetch(s);
1345 v.second = Rotate(v.first, 42) * k1 + Fetch(s + 8);
1346 w.first = Rotate(y + z, 35) * k1 + x;
1347 w.second = Rotate(x + Fetch(s + 88), 53) * k1;
1348
1349 // This is the same inner loop as CityHash64(), manually unrolled.
1350 do {
1351 x = Rotate(x + y + v.first + Fetch(s + 8), 37) * k1;
1352 y = Rotate(y + v.second + Fetch(s + 48), 42) * k1;
1353 x ^= w.second;
1354 y += v.first + Fetch(s + 40);
1355 z = Rotate(z + w.first, 33) * k1;
1356 v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first);
1357 w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16));
1358 std::swap(z, x);
1359 s += 64;
1360 x = Rotate(x + y + v.first + Fetch(s + 8), 37) * k1;
1361 y = Rotate(y + v.second + Fetch(s + 48), 42) * k1;
1362 x ^= w.second;
1363 y += v.first + Fetch(s + 40);
1364 z = Rotate(z + w.first, 33) * k1;
1365 v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first);
1366 w = WeakHashLen32WithSeeds(s + 32, z + w.second, y + Fetch(s + 16));
1367 std::swap(z, x);
1368 s += 64;
1369 len -= 128;
1370 } while (LIKELY(len >= 128));
1371 x += Rotate(v.first + z, 49) * k0;
1372 y = y * k0 + Rotate(w.second, 37);
1373 z = z * k0 + Rotate(w.first, 27);
1374 w.first *= 9;
1375 v.first *= k0;
1376 // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s.
1377 for (size_t tail_done = 0; tail_done < len; ) {
1378 tail_done += 32;
1379 y = Rotate(x + y, 42) * k0 + v.second;
1380 w.first += Fetch(s + len - tail_done + 16);
1381 x = x * k0 + w.first;
1382 z += w.second + Fetch(s + len - tail_done);
1383 w.second += v.first;
1384 v = WeakHashLen32WithSeeds(s + len - tail_done, v.first + z, v.second);
1385 v.first *= k0;
1386 }
1387 // At this point our 56 bytes of state should contain more than
1388 // enough information for a strong 128-bit hash. We use two
1389 // different 56-byte-to-8-byte hashes to get a 16-byte final result.
1390 x = HashLen16(x, v.first);
1391 y = HashLen16(y + z, w.first);
1392 return uint128_t(HashLen16(x + v.second, w.second) + y,
1393 HashLen16(x + w.second, y + v.second));
1394 }
1395
CityHash128(const char * s,size_t len)1396 STATIC_INLINE uint128_t CityHash128(const char *s, size_t len) {
1397 return len >= 16 ?
1398 CityHash128WithSeed(s + 16, len - 16,
1399 uint128_t(Fetch(s), Fetch(s + 8) + k0)) :
1400 CityHash128WithSeed(s, len, uint128_t(k0, k1));
1401 }
1402
Fingerprint128(const char * s,size_t len)1403 uint128_t Fingerprint128(const char* s, size_t len) {
1404 return CityHash128(s, len);
1405 }
1406 } // namespace farmhashcc
1407
1408 // BASIC STRING HASHING
1409
1410 // Hash function for a byte array. See also Hash(), below.
1411 // May change from time to time, may differ on different platforms, may differ
1412 // depending on NDEBUG.
Hash32(const char * s,size_t len)1413 uint32_t Hash32(const char* s, size_t len) {
1414 if (can_use_sse42 & can_use_aesni & x86_64)
1415 return DebugTweak(farmhashns::Hash32(s, len));
1416
1417 return DebugTweak(
1418 (can_use_sse42 & can_use_aesni) ?
1419 farmhashsu::Hash32(s, len) :
1420 can_use_sse42 ?
1421 farmhashsa::Hash32(s, len) :
1422 farmhashmk::Hash32(s, len));
1423 }
1424
1425 // Hash function for a byte array. For convenience, a 32-bit seed is also
1426 // hashed into the result.
1427 // May change from time to time, may differ on different platforms, may differ
1428 // depending on NDEBUG.
Hash32WithSeed(const char * s,size_t len,uint32_t seed)1429 uint32_t Hash32WithSeed(const char* s, size_t len, uint32_t seed) {
1430 if (can_use_sse42 & can_use_aesni & x86_64)
1431 return DebugTweak(farmhashns::Hash32WithSeed(s, len, seed));
1432
1433 return DebugTweak(
1434 (can_use_sse42 & can_use_aesni) ?
1435 farmhashsu::Hash32WithSeed(s, len, seed) :
1436 can_use_sse42 ?
1437 farmhashsa::Hash32WithSeed(s, len, seed) :
1438 farmhashmk::Hash32WithSeed(s, len, seed));
1439 }
1440
1441 // Hash function for a byte array. For convenience, a 64-bit seed is also
1442 // hashed into the result. See also Hash(), below.
1443 // May change from time to time, may differ on different platforms, may differ
1444 // depending on NDEBUG.
Hash64(const char * s,size_t len)1445 uint64_t Hash64(const char* s, size_t len) {
1446 return DebugTweak(farmhashna::Hash64(s, len));
1447 }
1448
1449 // Hash function for a byte array.
1450 // May change from time to time, may differ on different platforms, may differ
1451 // depending on NDEBUG.
Hash(const char * s,size_t len)1452 size_t Hash(const char* s, size_t len) {
1453 return sizeof(size_t) == 8 ? Hash64(s, len) : Hash32(s, len);
1454 }
1455
1456 // Hash function for a byte array. For convenience, a 64-bit seed is also
1457 // hashed into the result.
1458 // May change from time to time, may differ on different platforms, may differ
1459 // depending on NDEBUG.
Hash64WithSeed(const char * s,size_t len,uint64_t seed)1460 uint64_t Hash64WithSeed(const char* s, size_t len, uint64_t seed) {
1461 return DebugTweak(farmhashna::Hash64WithSeed(s, len, seed));
1462 }
1463
1464 // Hash function for a byte array. For convenience, two seeds are also
1465 // hashed into the result.
1466 // May change from time to time, may differ on different platforms, may differ
1467 // depending on NDEBUG.
Hash64WithSeeds(const char * s,size_t len,uint64_t seed0,uint64_t seed1)1468 uint64_t Hash64WithSeeds(const char* s, size_t len, uint64_t seed0, uint64_t seed1) {
1469 return DebugTweak(farmhashna::Hash64WithSeeds(s, len, seed0, seed1));
1470 }
1471
1472 // Hash function for a byte array.
1473 // May change from time to time, may differ on different platforms, may differ
1474 // depending on NDEBUG.
Hash128(const char * s,size_t len)1475 uint128_t Hash128(const char* s, size_t len) {
1476 return DebugTweak(farmhashcc::Fingerprint128(s, len));
1477 }
1478
1479 // Hash function for a byte array. For convenience, a 128-bit seed is also
1480 // hashed into the result.
1481 // May change from time to time, may differ on different platforms, may differ
1482 // depending on NDEBUG.
Hash128WithSeed(const char * s,size_t len,uint128_t seed)1483 uint128_t Hash128WithSeed(const char* s, size_t len, uint128_t seed) {
1484 return DebugTweak(farmhashcc::CityHash128WithSeed(s, len, seed));
1485 }
1486
1487 // BASIC NON-STRING HASHING
1488
1489 // FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
1490
1491 // Fingerprint function for a byte array. Most useful in 32-bit binaries.
Fingerprint32(const char * s,size_t len)1492 uint32_t Fingerprint32(const char* s, size_t len) {
1493 return farmhashmk::Hash32(s, len);
1494 }
1495
1496 // Fingerprint function for a byte array.
Fingerprint64(const char * s,size_t len)1497 uint64_t Fingerprint64(const char* s, size_t len) {
1498 return farmhashna::Hash64(s, len);
1499 }
1500
1501 // Fingerprint function for a byte array.
Fingerprint128(const char * s,size_t len)1502 uint128_t Fingerprint128(const char* s, size_t len) {
1503 return farmhashcc::Fingerprint128(s, len);
1504 }
1505
1506 } // namespace NAMESPACE_FOR_HASH_FUNCTIONS
1507
1508 #if FARMHASHSELFTEST
1509
1510 #ifndef FARMHASH_SELF_TEST_GUARD
1511 #define FARMHASH_SELF_TEST_GUARD
1512 #include <string.h>
1513 #include <cstdio>
1514 #include <iostream>
1515
1516 using std::cout;
1517 using std::cerr;
1518 using std::endl;
1519 using std::hex;
1520
1521 static const uint64_t kSeed0 = 1234567;
1522 static const uint64_t kSeed1 = k0;
1523 static const int kDataSize = 1 << 20;
1524 static const int kTestSize = 300;
1525 #define kSeed128 Uint128(kSeed0, kSeed1)
1526
1527 static char data[kDataSize];
1528
1529 static int completed_self_tests = 0;
1530 static int errors = 0;
1531
1532 // Initialize data to pseudorandom values.
Setup()1533 void Setup() {
1534 if (completed_self_tests == 0) {
1535 uint64_t a = 9;
1536 uint64_t b = 777;
1537 for (int i = 0; i < kDataSize; i++) {
1538 a += b;
1539 b += a;
1540 a = (a ^ (a >> 41)) * k0;
1541 b = (b ^ (b >> 41)) * k0 + i;
1542 uint8_t u = b >> 37;
1543 memcpy(data + i, &u, 1); // uint8_t -> char
1544 }
1545 }
1546 }
1547
NoteErrors()1548 int NoteErrors() {
1549 #define NUM_SELF_TESTS 6
1550 if (++completed_self_tests == NUM_SELF_TESTS)
1551 std::exit(errors > 0);
1552 return errors;
1553 }
1554
IsNonZero(T x)1555 template <typename T> inline bool IsNonZero(T x) {
1556 return x != 0;
1557 }
1558
IsNonZero(uint128_t x)1559 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
1560 return x != Uint128(0, 0);
1561 }
1562
1563 #endif // FARMHASH_SELF_TEST_GUARD
1564
1565 namespace farmhashccTest {
1566
CreateSeed(int offset,int salt)1567 uint32_t CreateSeed(int offset, int salt) {
1568 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
1569 h = h * c1;
1570 h ^= (h >> 17);
1571 h = h * c1;
1572 h ^= (h >> 17);
1573 h = h * c1;
1574 h ^= (h >> 17);
1575 h += static_cast<uint32_t>(offset & 0xffffffff);
1576 h = h * c1;
1577 h ^= (h >> 17);
1578 h = h * c1;
1579 h ^= (h >> 17);
1580 h = h * c1;
1581 h ^= (h >> 17);
1582 return h;
1583 }
1584
1585 #undef SEED
1586 #undef SEED1
1587 #undef SEED0
1588 #define SEED CreateSeed(offset, -1)
1589 #define SEED0 CreateSeed(offset, 0)
1590 #define SEED1 CreateSeed(offset, 1)
1591
1592 #undef TESTING
1593 #define TESTING 1
1594 #if TESTING
1595 uint32_t expected[] = {
1596 4223616069u,
1597 3696677242u,
1598 1039179260u, 1690343979u, 1018511555u, 2464489001u,
1599 20368522u, 2663783964u, 175201532u, 1619210592u,
1600 4081014168u,
1601 2576519988u,
1602 3285042206u, 502478099u, 739479538u, 1500332790u,
1603 13754768u, 3789353455u, 3473868058u, 1909255088u,
1604 2212771159u,
1605 1112731063u,
1606 826915357u, 2893489933u, 118369799u, 1848668220u,
1607 1308219822u, 249416982u, 64306364u, 4221800195u,
1608 1020067935u,
1609 3955445564u,
1610 563346294u, 550236731u, 2339016688u, 1826259714u,
1611 3872358639u, 2295981050u, 1870005390u, 4015628802u,
1612 1451961420u,
1613 653440099u,
1614 1292493871u, 164377749u, 1717712483u, 463414587u,
1615 3924343675u, 1050492084u, 3566618804u, 2046983362u,
1616 31917516u,
1617 2957164615u,
1618 230718965u, 999595115u, 3534822176u, 2175709186u,
1619 965707431u, 441796222u, 2481718051u, 1827777486u,
1620 2590087362u,
1621 3879448744u,
1622 3515079898u, 1601433082u, 982764532u, 254808716u,
1623 1293372530u, 4205605817u, 947001462u, 1138890052u,
1624 176305566u,
1625 2447367541u,
1626 2973802542u, 4123621138u, 3083865840u, 1706367795u,
1627 792114347u, 2880110657u, 440613768u, 195054868u,
1628 1359016305u,
1629 3363804638u,
1630 649488537u, 1624045597u, 1441938215u, 3147758996u,
1631 3199173578u, 2597283203u, 2191333609u, 3763129144u,
1632 1117290165u,
1633 1062549743u,
1634 2565615889u, 1046361554u, 1581968261u, 1058773671u,
1635 1123053168u, 3807622275u, 1486749916u, 3900816089u,
1636 2437877004u,
1637 1894455839u,
1638 1912520953u, 1914997013u, 561048608u, 1643267444u,
1639 3671572006u, 194811086u, 1468911468u, 2179206286u,
1640 673206794u,
1641 3486923651u,
1642 3741426466u, 3292160512u, 697001377u, 1900763774u,
1643 3726097344u, 629282039u, 3578723715u, 2868028489u,
1644 3269862919u,
1645 2303349487u,
1646 3643953525u, 2307255916u, 849996280u, 732080434u,
1647 909961480u, 3542445214u, 2628347095u, 4236856917u,
1648 1380660650u,
1649 2631821908u,
1650 2007289004u, 3509705198u, 3788541675u, 789457322u,
1651 3090670546u, 638977894u, 3503881773u, 947102987u,
1652 1525325287u,
1653 1816697045u,
1654 2706647405u, 288763142u, 3505438495u, 481308609u,
1655 2882636782u, 3745162621u, 3503467033u, 428247823u,
1656 176408838u,
1657 333551502u,
1658 1001068721u, 1681483651u, 75380831u, 4191469679u,
1659 3627361839u, 2736617386u, 3120737438u, 1297502456u,
1660 864896482u,
1661 85674920u,
1662 2886047255u, 4119881331u, 2496990525u, 3442502055u,
1663 1806582817u, 3186345024u, 4099591287u, 2560171465u,
1664 3489229104u,
1665 3065015872u,
1666 2755089808u, 3098442882u, 378524719u, 2664097023u,
1667 1771960725u, 2901182183u, 55258521u, 1266621443u,
1668 581644891u,
1669 37790450u,
1670 1800731704u, 3601350920u, 53428754u, 2759476837u,
1671 3391093099u, 1496510311u, 2511119507u, 2636877410u,
1672 631613207u,
1673 1573846064u,
1674 260484875u, 1088212603u, 2369525206u, 322522428u,
1675 3191396600u, 2076543340u, 1552496658u, 2739811558u,
1676 3867875546u,
1677 2051584261u,
1678 2126250818u, 901517871u, 3651631165u, 1323139145u,
1679 1521111765u, 477802997u, 3508559783u, 383954241u,
1680 3804516756u,
1681 4250206331u,
1682 2655954340u, 2484996477u, 1417544845u, 1520282298u,
1683 2745204366u, 2869345147u, 1872738335u, 2592877343u,
1684 1619744564u,
1685 1804962124u,
1686 3458679890u, 423948620u, 273645618u, 4187865426u,
1687 376057175u, 2943431463u, 3581950599u, 1035398331u,
1688 1088213445u,
1689 861988903u,
1690 1323370244u, 777069428u, 506235917u, 369720851u,
1691 2789995854u, 230915180u, 1505086948u, 940361236u,
1692 3727873235u,
1693 1159167499u,
1694 1860302871u, 3456858862u, 3923555152u, 2131072714u,
1695 2910461068u, 3671950363u, 2010742682u, 4088068851u,
1696 3616470388u,
1697 2087714788u,
1698 221675509u, 1230154072u, 3450704646u, 1463226695u,
1699 1998357699u, 266026801u, 619568740u, 3560427266u,
1700 4148162586u,
1701 3150417316u,
1702 1356375822u, 2056097622u, 627905802u, 3881675638u,
1703 2309738053u, 971916703u, 3447805361u, 1673575328u,
1704 673084328u,
1705 3317849401u,
1706 2836362782u, 2377208890u, 3275350588u, 158350552u,
1707 2553241779u, 2497264995u, 3262882649u, 3897937187u,
1708 1598963653u,
1709 3068514414u,
1710 601541505u, 374517071u, 3380795976u, 235752573u,
1711 284670003u, 2990192160u, 904937105u, 2306579150u,
1712 2117362589u,
1713 1635274830u,
1714 3355572906u, 170799903u, 1226685528u, 664567688u,
1715 413219134u, 878324258u, 4026159448u, 3620649295u,
1716 1823625377u,
1717 3175888439u,
1718 1759344347u, 2640637095u, 3549558u, 2192984935u,
1719 978623493u, 804017880u, 3877562323u, 3843116489u,
1720 1641748342u,
1721 1853539444u,
1722 3001178468u, 3443560727u, 2685426077u, 1653064722u,
1723 349231508u, 2726789654u, 3136215581u, 768402830u,
1724 269384321u,
1725 531936536u,
1726 2592883487u, 1343156334u, 3628619802u, 1477143570u,
1727 4269458419u, 3285611028u, 959104925u, 2712290710u,
1728 3480237248u,
1729 835796333u,
1730 2020636251u, 1191914589u, 126521603u, 4288023938u,
1731 3731699932u, 2136758855u, 985780142u, 193807575u,
1732 1850544433u,
1733 653947619u,
1734 3929316796u, 381871169u, 950486363u, 1787262279u,
1735 360480382u, 1800636585u, 1039258631u, 3682073259u,
1736 1262819303u,
1737 1786000319u,
1738 1570627191u, 893065837u, 301304916u, 1478469809u,
1739 623018819u, 2742232545u, 2058913014u, 1706060059u,
1740 2421125401u,
1741 1315829592u,
1742 3208766775u, 1805586156u, 575853086u, 3085025513u,
1743 4010908260u, 2344058256u, 3814407434u, 1458485673u,
1744 2474514786u,
1745 3581895658u,
1746 2710719679u, 190812706u, 2135454262u, 2620080728u,
1747 3400757986u, 1669914857u, 1559978393u, 1629811331u,
1748 3096616493u,
1749 1391424435u,
1750 4158376003u, 1015657076u, 794783832u, 479952178u,
1751 1150290207u, 2497437906u, 231815090u, 755078067u,
1752 3832053281u,
1753 63649475u,
1754 2415822606u, 4105027719u, 1706992318u, 1106598740u,
1755 3941945667u, 1271300761u, 505882259u, 760186809u,
1756 2657183368u,
1757 1925422058u,
1758 1039773764u, 880219458u, 4275949176u, 1556833823u,
1759 925882132u, 4216310340u, 757497522u, 461833914u,
1760 3884002070u,
1761 2790957660u,
1762 2100050089u, 651959176u, 1380301291u, 1289124125u,
1763 452314403u, 226156280u, 3306924715u, 1750807758u,
1764 2290180542u,
1765 1953760569u,
1766 2253069096u, 3960924806u, 1786291620u, 60736185u,
1767 2569018293u, 3870479674u, 2247005661u, 2239850953u,
1768 4261808536u,
1769 3282975782u,
1770 780945879u, 3349849383u, 1579362556u, 2265045884u,
1771 905088740u, 725212379u, 3156479246u, 2501620391u,
1772 3062836263u,
1773 4070422690u,
1774 996797869u, 4082582315u, 976105756u, 303983602u,
1775 1862104804u, 3864508254u, 3383979677u, 2835500286u,
1776 2798364010u,
1777 519359476u,
1778 3447342725u, 194373889u, 3313466630u, 232399983u,
1779 2841787856u, 1672751454u, 3345183154u, 1805381384u,
1780 2226129336u,
1781 2847829057u,
1782 2350774567u, 2838540121u, 2757948482u, 1017002062u,
1783 2329150951u, 2171488196u, 3668619047u, 3874977844u,
1784 3287966998u,
1785 262346753u,
1786 2493054715u, 2298644430u, 2926101182u, 1528457638u,
1787 598656233u, 2615845874u, 989110727u, 820441411u,
1788 253617372u,
1789 2201077208u,
1790 2047569338u, 3114356329u, 3335563734u, 2967673540u,
1791 768438341u, 1417708203u, 3873718246u, 1538441843u,
1792 1279167650u,
1793 3917966776u,
1794 2218481734u, 1015935150u, 1957845042u, 1318150213u,
1795 3146423971u, 4218994877u, 1162470863u, 1519718292u,
1796 2594658906u,
1797 665870414u,
1798 3430347817u, 3933868731u, 1597041394u, 3138684682u,
1799 3398212027u, 1064647658u, 1576321132u, 14792918u,
1800 224938029u,
1801 3706456050u,
1802 847274786u, 2645698692u, 1743374687u, 2343133224u,
1803 3066596790u, 2857270120u, 200596308u, 452055528u,
1804 2319312082u,
1805 3488655402u,
1806 4146865894u, 608206438u, 2699777051u, 3687240713u,
1807 327957508u, 3664730153u, 568134564u, 2993484554u,
1808 4159860363u,
1809 4274533921u,
1810 1079994063u, 2360220210u, 3609597760u, 3639708902u,
1811 2836180437u, 1069910270u, 1892427666u, 1874729790u,
1812 1267712826u,
1813 121886940u,
1814 3572289214u, 2475945610u, 783779452u, 588827737u,
1815 1531395014u, 2085084212u, 2219189792u, 3981444548u,
1816 2218885336u,
1817 1691622694u,
1818 2053232885u, 1386558530u, 2182946189u, 2365247285u,
1819 1871081313u, 2935751853u, 38413723u, 543465863u,
1820 900691890u,
1821 2899905665u,
1822 575120562u, 93133904u, 457154948u, 2983705792u,
1823 4232229200u, 2038565963u, 614693984u, 3405328302u,
1824 4083090010u,
1825 2088004171u,
1826 244031209u, 1861889294u, 2417109253u, 3299562328u,
1827 4158642443u, 4199064449u, 3161611046u, 885015950u,
1828 3677904099u,
1829 2969861785u,
1830 772348805u, 1712263832u, 3219357614u, 484271305u,
1831 3645706114u, 2059620251u, 409557488u, 2278896731u,
1832 224475749u,
1833 3523022952u,
1834 2057140088u, 449131785u, 1149879244u, 4255363996u,
1835 3602720135u, 1690010854u, 2503998822u, 2750828466u,
1836 3340671802u,
1837 1447583863u,
1838 2649684943u, 2764747249u, 3046070595u, 3441726138u,
1839 3840332559u, 3156747501u, 1288666680u, 1472744459u,
1840 3452391933u,
1841 1617542784u,
1842 217869690u, 3718469527u, 348639731u, 590532355u,
1843 43789787u, 22606314u, 1621559290u, 2231743261u,
1844 2234620879u,
1845 544748955u,
1846 3169387920u, 203343594u, 3272552527u, 1078282365u,
1847 809576321u, 854207584u, 3625491053u, 1193737267u,
1848 1628966807u,
1849 2661421060u,
1850 2433442061u, 3886639039u, 2149304418u, 303000565u,
1851 1432830882u, 137378235u, 1135974068u, 318705754u,
1852 2491227157u,
1853 2627534472u,
1854 3520352233u, 2488397682u, 3969194920u, 3843962181u,
1855 2135981459u, 2611933220u, 799460731u, 2300968851u,
1856 3412851628u,
1857 3070914013u,
1858 3555224260u, 4125937572u, 240359903u, 722496673u,
1859 2061023600u, 3843919221u, 2759960043u, 1191155322u,
1860 1504041490u,
1861 3735253656u,
1862 1773124736u, 101110011u, 1627699578u, 2645634551u,
1863 263603947u, 1388368439u, 677146538u, 1644201982u,
1864 2625699644u,
1865 2403862553u,
1866 2426069017u, 3613511705u, 915141802u, 2981654265u,
1867 3474818167u, 2611101773u, 627891434u, 762754924u,
1868 2143021902u,
1869 51067670u,
1870 4017746573u, 2269879853u, 3037857950u, 2388899692u,
1871 582729171u, 1886116725u, 2281219772u, 264704948u,
1872 3509984037u,
1873 4078683368u,
1874 2172959411u, 1807195632u, 3357092302u, 2253764928u,
1875 2320369390u, 3076335959u, 2623583210u, 168378015u,
1876 1435562650u,
1877 1100977467u,
1878 3160490319u, 2550328495u, 2396855930u, 1347823908u,
1879 1617990918u, 3849653099u, 3224111576u, 1681539821u,
1880 4171542880u,
1881 552200045u,
1882 3562947778u, 1676237880u, 3747732307u, 2453332913u,
1883 865530667u, 3566636849u, 3485502777u, 336779723u,
1884 2535942410u,
1885 1685000184u,
1886 820545711u, 1893670486u, 1273910461u, 1193758569u,
1887 970365241u, 381205962u, 3612810852u, 1160577445u,
1888 541488143u,
1889 4005031080u,
1890 2333965236u, 2419855455u, 3484533538u, 3073937876u,
1891 908466956u, 661391539u, 2342122412u, 1467049112u,
1892 1785800827u,
1893 135343033u,
1894 139643209u, 2438375667u, 974654058u, 3216478230u,
1895 3807620420u, 779043363u, 2812846449u, 333254784u,
1896 1025244024u,
1897 2242303095u,
1898 2476683742u, 350018683u, 174652916u, 933097576u,
1899 826905896u, 559603581u, 2777181260u, 164915169u,
1900 4070353203u,
1901 1459055748u,
1902 297303985u, 3103837241u, 3812514233u, 232265137u,
1903 2032819099u, 1523091376u, 3531238208u, 1403510182u,
1904 2886832080u,
1905 2599705941u,
1906 2789695716u, 68437968u, 3823813791u, 1040994569u,
1907 3024194990u, 2461740520u, 3735391266u, 2042207153u,
1908 2461678616u,
1909 3519231840u,
1910 1344224923u, 411442756u, 1179779351u, 7661528u,
1911 778352196u, 3288808867u, 589356197u, 2627504511u,
1912 3374744599u,
1913 3312172905u,
1914 357423007u, 3539567796u, 4044452215u, 1445118403u,
1915 2937983820u, 184089910u, 346201845u, 2427295202u,
1916 1345448010u,
1917 2884434843u,
1918 3085001879u, 2640105409u, 315310640u, 3530289798u,
1919 3362974764u, 963602652u, 75228477u, 3509381180u,
1920 4012777756u,
1921 2380345941u,
1922 1073137836u, 2083960378u, 1220315185u, 3628720934u,
1923 3508867818u, 67148343u, 3558085158u, 1753943368u,
1924 863309561u,
1925 2844713625u,
1926 441921850u, 854732254u, 816793316u, 2555428747u,
1927 3440623414u, 1707304366u, 3189874375u, 1623229221u,
1928 1220335976u,
1929 806745430u,
1930 3909262947u, 1680369031u, 2926179486u, 3410391660u,
1931 3991630434u, 2876458763u, 1179167079u, 536360759u,
1932 1592117159u,
1933 1514343977u,
1934 1032622306u, 2057494855u, 784938958u, 178402996u,
1935 1152907972u, 2326185495u, 2939973666u, 4181120253u,
1936 552831733u,
1937 664251856u,
1938 1297139539u, 1969357631u, 1474065957u, 3055419017u,
1939 3395829380u, 3316562752u, 2168409017u, 614624786u,
1940 3585854336u,
1941 668291094u,
1942 1162889217u, 3773171307u, 2263271126u, 355089668u,
1943 3195850578u, 3396793277u, 3519870267u, 527857605u,
1944 3972392320u,
1945 2224315010u,
1946 4047225561u, 3271434798u, 3192704713u, 2798505213u,
1947 3932215896u, 3792924012u, 3796843756u, 453872975u,
1948 4050552799u,
1949 1056432676u,
1950 928166947u, 121311642u, 930989547u, 2087070683u,
1951 1288978057u, 1556325239u, 1812435626u, 1682385724u,
1952 1214364933u,
1953 904760776u,
1954 3957045528u, 3949822847u, 2411065880u, 3716420732u,
1955 3424837835u, 3833550693u, 1799375326u, 2012368921u,
1956 2768764136u,
1957 1786111037u,
1958 4055479315u, 3751639533u, 2808224623u, 3492656387u,
1959 1306824780u, 2624000170u, 3134795218u, 1778409297u,
1960 3900821801u,
1961 593336325u,
1962 2772069220u, 2980873673u, 3574497158u, 3994780459u,
1963 4246519854u, 3482758570u, 4228015183u, 33101083u,
1964 1769887734u,
1965 4158035314u,
1966 3690638998u, 1119035482u, 4134969651u, 2483207353u,
1967 3932823321u, 285829887u, 3485140138u, 1304815138u,
1968 995608264u,
1969 3133997465u,
1970 1195477617u, 2147693728u, 3506673112u, 4234467492u,
1971 1183174337u, 1395340482u, 769199343u, 193262308u,
1972 2798920256u,
1973 3827889422u,
1974 3399695609u, 3036045724u, 2999477386u, 3567001759u,
1975 2682864314u, 1414023907u, 3699872975u, 3369870701u,
1976 2662284872u,
1977 2179640019u,
1978 2485080099u, 3234415609u, 3755915606u, 1339453220u,
1979 1567403399u, 2076272391u, 293946298u, 3861962750u,
1980 1291949822u,
1981 2916864995u,
1982 132642326u, 2215117062u, 2205863575u, 2488805750u,
1983 405632860u, 3248129390u, 2952606864u, 896734759u,
1984 2047417173u,
1985 3865951392u,
1986 657296855u, 1328547532u, 3966511825u, 3959682388u,
1987 4171801020u, 2981416957u, 1868896247u, 790081075u,
1988 3143666398u,
1989 2950766549u,
1990 2065854887u, 2737081890u, 995061774u, 1510712611u,
1991 2865954809u, 565044286u, 1565631102u, 1500654931u,
1992 494822108u,
1993 2803515503u,
1994 1058154996u, 3506280187u, 856885925u, 4204610546u,
1995 800905649u, 1130711562u, 558146282u, 2053400666u,
1996 449794061u,
1997 2643520245u,
1998 2101248725u, 3123292429u, 3583524041u, 983372394u,
1999 1587743780u, 672870813u, 444833475u, 100741452u,
2000 366232251u,
2001 1717951248u,
2002 524144122u, 1362432726u, 1304947719u, 674306020u,
2003 405665887u, 4081931036u, 1580408204u, 2343242778u,
2004 3901654006u,
2005 2627173567u,
2006 3015148205u, 814686701u, 1327920712u, 1346494176u,
2007 2468632605u, 2259795544u, 2519278184u, 2129281928u,
2008 2860266380u,
2009 4001619412u,
2010 1154910973u, 2841022216u, 1199925485u, 1372200293u,
2011 2713179055u, 3609776550u, 2896463880u, 1056406892u,
2012 177413841u,
2013 40180172u,
2014 3274788406u, 660921784u, 1686225028u, 4003382965u,
2015 2532691887u, 4256809101u, 1186018983u, 667359096u,
2016 2375266493u,
2017 2760222015u,
2018 745187078u, 312264012u, 396822261u, 2588536966u,
2019 2026998998u, 1766454365u, 3218807676u, 3915487497u,
2020 2630550356u,
2021 4130063378u,
2022 4231937074u, 752212123u, 3085144349u, 3267186363u,
2023 4103872100u, 4193207863u, 1306401710u, 3014853131u,
2024 1067760598u,
2025 2306188342u,
2026 2437881506u, 4258185052u, 2506507580u, 130876929u,
2027 1076894205u, 4106981702u, 2799540844u, 945747327u,
2028 1436722291u,
2029 2499772225u,
2030 2571537041u, 2038830635u, 2066826058u, 2892892912u,
2031 524875858u, 3392572161u, 2869992096u, 1308273341u,
2032 923668994u,
2033 1980407857u,
2034 2275009652u, 240598096u, 2658376530u, 3505603048u,
2035 1022603789u, 582423424u, 846379327u, 4092636095u,
2036 4177298326u,
2037 1004173023u,
2038 2154027018u, 2993634669u, 1098364089u, 3035642175u,
2039 1335688126u, 1376393415u, 1252369770u, 3815033328u,
2040 1999309358u,
2041 1234054757u,
2042 1388595255u, 2859334775u, 366532860u, 3453410395u,
2043 4226967708u, 1321729870u, 2078463405u, 156766592u,
2044 3157683394u,
2045 3549293384u,
2046 3348214547u, 2879648344u, 1144813399u, 2758966254u,
2047 647753581u, 813615926u, 2035441590u, 1961053117u,
2048 600168686u,
2049 2192833387u,
2050 3156481401u, 3627320321u, 383550248u, 81209584u,
2051 2339331745u, 1284116690u, 1980144976u, 2955724163u,
2052 789301728u,
2053 3842040415u,
2054 1115881490u, 965249078u, 4098663322u, 1870257033u,
2055 2923150701u, 4217108433u, 183816559u, 2104089285u,
2056 2640095343u,
2057 3173757052u,
2058 927847464u, 2383114981u, 4287174363u, 1886129652u,
2059 70635161u, 1182924521u, 1121440038u, 4246220730u,
2060 3890583049u,
2061 975913757u,
2062 2436253031u, 1074894869u, 1301280627u, 992471939u,
2063 735658128u, 244441856u, 1541612456u, 3457776165u,
2064 3503534059u,
2065 1931651133u,
2066 349142786u, 3669028584u, 1828812038u, 99128389u,
2067 1364272849u, 1963678455u, 3971963311u, 2316950886u,
2068 1308901796u,
2069 2789591580u,
2070 1460494965u, 2380227479u, 1577190651u, 1755822080u,
2071 2911014607u, 859387544u, 13023113u, 2319243370u,
2072 2522582211u,
2073 2299110490u,
2074 3342378874u, 2589323490u, 1884430765u, 3739058655u,
2075 2419330954u, 355389916u, 273950915u, 3670136553u,
2076 410946824u,
2077 3174041420u,
2078 2609010298u, 3059091350u, 2300275014u, 725729828u,
2079 2548380995u, 1738849964u, 1257081412u, 79430455u,
2080 810321297u,
2081 3246190593u,
2082 1007937684u, 912115394u, 40880059u, 3450073327u,
2083 4289832174u, 2253485111u, 1065639151u, 2953189309u,
2084 124779113u,
2085 654299738u,
2086 115760833u, 1250932069u, 884995826u, 3998908281u,
2087 1382882981u, 1134187162u, 3202324501u, 487502928u,
2088 3032756345u,
2089 4057517628u,
2090 933197381u, 2319223127u, 2044528655u, 2554572663u,
2091 4049450620u, 1620812836u, 2832905391u, 2273005481u,
2092 1913090121u,
2093 1055456023u,
2094 510593296u, 3285343192u, 2912822536u, 1645225063u,
2095 638418430u, 452701300u, 1025483165u, 1639370512u,
2096 167948643u,
2097 2809842730u,
2098 2983135664u, 407521332u, 1543756616u, 3949773145u,
2099 4283462892u, 659962275u, 3878013463u, 1000748756u,
2100 4053212051u,
2101 4099239406u,
2102 3467581965u, 354635541u, 21301844u, 3831212473u,
2103 3189450571u, 2264401966u, 4096484849u, 1736448515u,
2104 3976926096u,
2105 3727194724u,
2106 2243487039u, 585209095u, 3143046007u, 969558123u,
2107 3037113502u, 3594170243u, 2835860223u, 3775493975u,
2108 2787220812u,
2109 2274252217u,
2110 2915380701u, 3077533278u, 1252871826u, 1519790952u,
2111 205297661u, 2950557658u, 3956882191u, 2724439401u,
2112 3694608025u,
2113 124028038u,
2114 216019153u, 1533010676u, 2259986336u, 2014061617u,
2115 2068617849u, 3078123052u, 2692046098u, 1582812948u,
2116 396916232u,
2117 1470894001u,
2118 1694309312u, 300268215u, 1553892743u, 671176040u,
2119 1544988994u, 2793402821u, 4194972569u, 2296476154u,
2120 748354332u,
2121 3491325898u,
2122 4261053291u, 1104998242u, 797816835u, 243564059u,
2123 2197717393u, 299029458u, 1675252188u, 3139770041u,
2124 583018574u,
2125 2532106100u,
2126 2099391658u, 3760526730u, 3422719327u, 3556917689u,
2127 2374009285u, 2130865894u, 3710563151u, 1437538307u,
2128 3938030842u,
2129 2006930694u,
2130 2151243336u, 1939741287u, 1957068175u, 2135147479u,
2131 649553342u, 1713643042u, 4188696599u, 1698739939u,
2132 3549427584u,
2133 1016382174u,
2134 322644378u, 2476164549u, 2037263020u, 88036019u,
2135 2548960923u, 539867919u, 2871157727u, 4031659929u,
2136 754087252u,
2137 972656559u,
2138 4246379429u, 3877308578u, 2059459630u, 3614934323u,
2139 1410565271u, 2102980459u, 215395636u, 1083393481u,
2140 3775523015u,
2141 2062750105u,
2142 2475645882u, 3041186774u, 3534315423u, 758607219u,
2143 1686100614u, 180500983u, 1155581185u, 1476664671u,
2144 2918661695u,
2145 3812731350u,
2146 4003853737u, 4148884881u, 1468469436u, 3278880418u,
2147 1045838071u, 1049161262u, 360450415u, 3158065524u,
2148 814443735u,
2149 3391401707u,
2150 729968410u, 738771593u, 3662738792u, 1672830580u,
2151 4199496163u, 188487238u, 219098233u, 2141731267u,
2152 3890250614u,
2153 2988780375u,
2154 4026279523u, 3489429375u, 2468433807u, 1178270701u,
2155 2685094218u, 2716621497u, 3718335529u, 2273344755u,
2156 701110882u,
2157 1925717409u,
2158 1515176562u, 2325460593u, 3954798930u, 784566105u,
2159 3769422266u, 1641530321u, 2703876862u, 2907480267u,
2160 1828076455u,
2161 1805635221u,
2162 3883381245u, 1476756210u, 2072514392u, 3658557081u,
2163 2003610746u, 2556845550u, 729594004u, 3303898266u,
2164 1968227254u,
2165 423204951u,
2166 231828688u, 4223697811u, 698619045u, 3636824418u,
2167 2738779239u, 2333529003u, 2833158642u, 580285428u,
2168 3038148234u,
2169 1012378004u,
2170 1113647298u, 1424593483u, 4053247723u, 1167152941u,
2171 2677383578u, 3419485379u, 2135673840u, 440478166u,
2172 1682229112u,
2173 3226724137u,
2174 1217439806u, 3828726923u, 3636576271u, 3467643156u,
2175 2005614908u, 2655346461u, 2345488441u, 1027557096u,
2176 3594084220u,
2177 1372306343u,
2178 2342583762u, 4291342905u, 4094931814u, 3254771759u,
2179 821978248u, 2404930117u, 1143937655u, 3156949255u,
2180 3460606610u,
2181 449701786u,
2182 3474906110u, 1932585294u, 2283357584u, 1808481478u,
2183 3522851029u, 3040164731u, 1530172182u, 2950426149u,
2184 1402416557u,
2185 756419859u,
2186 4132576145u, 724994790u, 2852015871u, 2177908339u,
2187 899914731u, 139675671u, 1423281870u, 3198458070u,
2188 807581308u,
2189 2021611521u,
2190 1801452575u, 1425984297u, 2833835949u, 1536827865u,
2191 3902351840u, 164546042u, 1872840974u, 3986194780u,
2192 792156290u,
2193 3378681896u,
2194 941547959u, 3931328334u, 3661060482u, 2386420777u,
2195 3920146272u, 3458621279u, 3348500844u, 2269586542u,
2196 797371473u,
2197 3188953649u,
2198 80514771u, 2913333490u, 1246325623u, 3253846094u,
2199 1723906239u, 1606413555u, 587500718u, 1412413859u,
2200 2310046829u,
2201 2113313263u,
2202 3855635608u, 47271944u, 1112281934u, 3440228404u,
2203 2633519166u, 425094457u, 307659635u, 67338587u,
2204 2412987939u,
2205 2363930989u,
2206 2853008596u, 2844637339u, 922568813u, 130379293u,
2207 2825204405u, 2904442145u, 1176875333u, 1511685505u,
2208 599177514u,
2209 1872681372u,
2210 682394826u, 1888849790u, 3635304282u, 1761257265u,
2211 1571292431u, 355247075u, 1177210823u, 1691529530u,
2212 3629531121u,
2213 3760474006u,
2214 1129340625u, 868116266u, 3908237785u, 1942124366u,
2215 1266630014u, 3214841995u, 334023850u, 1110037019u,
2216 369650727u,
2217 1288666741u,
2218 70535706u, 20230114u, 4284225520u, 727856157u,
2219 293696779u, 1244943770u, 3976592462u, 560421917u,
2220 4171688499u,
2221 2438786950u,
2222 1218144639u, 3809125983u, 1302395746u, 534542359u,
2223 2121993015u, 2899519374u, 3192177626u, 1761707794u,
2224 3101683464u,
2225 1555403906u,
2226 3225675390u, 1875263768u, 4278894569u, 651707603u,
2227 2111591484u, 3802716028u, 2900262228u, 1181469202u,
2228 3254743797u,
2229 1822684466u,
2230 860641829u, 3046128268u, 1284833012u, 1125261608u,
2231 461384524u, 2331344566u, 1274400010u, 990498321u,
2232 3462536298u,
2233 3796842585u,
2234 2346607194u, 279495949u, 3951194590u, 3522664971u,
2235 3169688303u, 726831706u, 1123875117u, 1816166599u,
2236 3759808754u,
2237 2918558151u,
2238 3713203220u, 3369939267u, 466047109u, 384042536u,
2239 587271104u, 2191634696u, 2449929095u, 1157932232u,
2240 2084466674u,
2241 841370485u,
2242 3241372562u, 4277738486u, 2150836793u, 1173569449u,
2243 778768930u, 2594706485u, 3065269405u, 3019263663u,
2244 2660146610u,
2245 2789946230u,
2246 77056913u, 728174395u, 3647185904u, 804562358u,
2247 2697276483u, 881311175u, 1178696435u, 2059173891u,
2248 2308303791u,
2249 221481230u,
2250 50241451u, 3689414100u, 1969074761u, 2732071529u,
2251 1900890356u, 840789500u, 2100609300u, 985565597u,
2252 1220850414u,
2253 2456636259u,
2254 223607678u, 1016310244u, 1937434395u, 85717256u,
2255 275058190u, 3712011133u, 171916016u, 2389569096u,
2256 3679765802u,
2257 3575358777u,
2258 3481108261u, 3178286380u, 2489642395u, 2931039055u,
2259 3086601621u, 3079518902u, 3027718495u, 2506894644u,
2260 2976869602u,
2261 2134336365u,
2262 2420172217u, 918054427u, 661522682u, 1403791357u,
2263 3587174388u, 2623673551u, 1355661457u, 4159477684u,
2264 1109013587u,
2265 3112183488u,
2266 2217849279u, 3500291996u, 2419603731u, 2929886201u,
2267 3854470013u, 1358382103u, 1357666555u, 21053566u,
2268 2716621233u,
2269 3094836862u,
2270 3309729704u, 57086558u, 839187419u, 2757944838u,
2271 3651040558u, 3607536716u, 3691257732u, 2312878285u,
2272 1202511724u,
2273 183479927u,
2274 2509829803u, 109313218u, 478173887u, 2072044014u,
2275 190631406u, 2495604975u, 1010416260u, 3679857586u,
2276 726566957u,
2277 258500881u,
2278 1805873908u, 3081447051u, 2352101327u, 534922207u,
2279 1584552873u, 813470716u, 255914637u, 249169434u,
2280 3193498057u,
2281 1038802706u,
2282 2590158653u, 3147907290u, 663060128u, 1156177857u,
2283 634616100u, 312879189u, 1545020368u, 2054634247u,
2284 3271451914u,
2285 3438291534u,
2286 2181454946u, 3864535432u, 2398586877u, 896491075u,
2287 2810631478u, 2770357487u, 3372930052u, 898070638u,
2288 2051007323u,
2289 392959778u,
2290 36645539u, 3743556044u, 4134529680u, 4124451188u,
2291 566806297u, 2936523982u, 1304761965u, 537399498u,
2292 1940818842u,
2293 40862381u,
2294 36288410u, 3063605629u, 2826611650u, 3961972098u,
2295 1871578006u, 2392095486u, 1136931591u, 513864488u,
2296 173276451u,
2297 3039055682u,
2298 3543322032u, 1943592006u, 657217094u, 1751698246u,
2299 2969618445u, 456616022u, 900309519u, 113892716u,
2300 1126392103u,
2301 1235651045u,
2302 1882073852u, 2136610853u, 2353639710u, 2819956700u,
2303 3980083530u, 828773559u, 224069850u, 902434120u,
2304 2802008036u,
2305 94358995u,
2306 2777723394u, 2812641403u, 2525832595u, 4157388110u,
2307 4235563782u, 937800324u, 141690749u, 568062536u,
2308 550123849u,
2309 1330316521u,
2310 1949488696u, 2296431366u, 1958465262u, 3564751729u,
2311 3748252207u, 120455129u, 1607318832u, 2525729790u,
2312 2640987481u,
2313 2332096657u,
2314 1775969159u, 1555085077u, 2913525137u, 1347085183u,
2315 2376253113u, 3194050574u, 1806090610u, 678641356u,
2316 1499146713u,
2317 383849715u,
2318 3299835823u, 2284860330u, 2614269636u, 3913628844u,
2319 2761334210u, 1959484587u, 529797021u, 239966995u,
2320 3102194829u,
2321 3602307804u,
2322 1122192627u, 3577510006u, 164486066u, 1680137310u,
2323 1473396395u, 1467801424u, 903493660u, 1185943071u,
2324 2798556505u,
2325 2306744492u,
2326 3167201310u, 3577947177u, 3067592134u, 2905506289u,
2327 1210366329u, 204484056u, 2347778932u, 3862374472u,
2328 3277439508u,
2329 4187414621u,
2330 1646699310u, 621385800u, 3934869089u, 3975491588u,
2331 3580085916u, 1925674500u, 2436305348u, 3983301539u,
2332 2739439523u,
2333 3291507446u,
2334 3395637920u, 3753389171u, 2955202032u, 2654255623u,
2335 3771089254u, 2140443405u, 2779834738u, 3261942805u,
2336 3526889244u,
2337 1842009139u,
2338 4048484340u, 2106218403u, 2161244271u, 772152700u,
2339 1158647659u, 3776791619u, 3882186721u, 699525237u,
2340 2954670460u,
2341 1007105869u,
2342 3359152025u, 1146388699u, 1401550303u, 2326582541u,
2343 4181783540u, 1085644043u, 1942143795u, 1038368308u,
2344 1526153809u,
2345 4042547244u,
2346 1891441000u, 2573991874u, 1281441253u, 3635098284u,
2347 1980545715u, 825985487u, 3934748116u, 4228386979u,
2348 1480870944u,
2349 1042194545u,
2350 2397771642u, 2248490001u, 3817869868u, 878654626u,
2351 3785629484u, 1672470870u, 3229367873u, 1894538933u,
2352 1010692731u,
2353 1733824268u,
2354 656620328u, 3048283803u, 3353340056u, 2324965120u,
2355 4192585951u, 2284524675u, 3483884368u, 1510168293u,
2356 1554942691u,
2357 1309709396u,
2358 1241133168u, 3162179280u, 4046378054u, 3171681593u,
2359 1165297136u, 3496703563u, 150437903u, 1948622072u,
2360 1076332463u,
2361 2292479143u,
2362 1464229958u, 3479738093u, 2328067598u, 2334503110u,
2363 833324834u, 3981605747u, 3002629155u, 2854644186u,
2364 2832201336u,
2365 95796957u,
2366 3269249397u, 2358313329u, 3411860910u, 4283292480u,
2367 2802208697u, 1305947955u, 2156803420u, 1991340283u,
2368 189678024u,
2369 447602599u,
2370 1055411517u, 1531748363u, 1555852656u, 412402681u,
2371 3774988152u, 20597551u, 2925024131u, 1423989620u,
2372 3749428061u,
2373 1541439448u,
2374 112270416u, 1936224776u, 132162941u, 3772011507u,
2375 3814102518u, 1908807815u, 444154079u, 823765347u,
2376 3362275567u,
2377 3419047430u,
2378 2108287005u, 2315102125u, 658593738u, 3195094029u,
2379 3721937534u, 3176229204u, 3398835373u, 1271898712u,
2380 1142546577u,
2381 3185986817u,
2382 3562705803u, 2046119567u, 912990621u, 1829977672u,
2383 3459576979u, 1118045834u, 1369529376u, 3320601076u,
2384 3954988953u,
2385 4002467635u,
2386 3359456351u, 1314849568u, 1766750942u, 2998874853u,
2387 1181800239u, 707328036u, 3314954697u, 2066721120u,
2388 598194215u,
2389 1124451278u,
2390 3156679616u, 3742684743u, 2960199690u, 2683497915u,
2391 2566077529u, 937014607u, 102095219u, 4262922475u,
2392 3132264275u,
2393 1262099830u,
2394 862722905u, 2717653494u, 3245583534u, 3427209989u,
2395 3220278124u, 85457091u, 2222333500u, 3513997967u,
2396 3522324951u,
2397 2830855552u,
2398 2215004781u, 3482411840u, 4227160614u, 2030964411u,
2399 1741393851u, 2643723748u, 942813508u, 403442675u,
2400 3112048748u,
2401 530556423u,
2402 3817755244u, 3543286628u, 2247276090u, 1532920842u,
2403 4101962711u, 1446540991u, 3297821473u, 1861255389u,
2404 1984398u,
2405 2366525138u,
2406 377589481u, 3549193828u, 1427765914u, 506831657u,
2407 277278988u, 1447652775u, 3214362239u, 3142198690u,
2408 2843087541u,
2409 468915015u,
2410 807895062u, 2198723907u, 4031145069u, 2417156212u,
2411 4027298697u, 637175947u, 1229254212u, 1773257887u,
2412 1659444818u,
2413 451148891u,
2414 2099741368u, 735351990u, 2534775713u, 3261804619u,
2415 712519954u, 3527962772u, 3758642738u, 4245823575u,
2416 1281314264u,
2417 1167866160u,
2418 1489546151u, 1197354389u, 1043278102u, 2563326586u,
2419 371937794u, 2320164817u, 3189512691u, 573685198u,
2420 4108603513u,
2421 3758899588u,
2422 3507030163u, 2947201212u, 2529492585u, 578234375u,
2423 3362349842u, 3318878925u, 3611203517u, 3059253190u,
2424 4270755916u,
2425 4291274625u,
2426 4237586791u, 4137422245u, 2927218651u, 2444687041u,
2427 797128811u, 2043057612u, 396533859u, 2665256178u,
2428 3346510674u,
2429 1779586176u,
2430 3076562062u, 1882746214u, 921095362u, 2026988397u,
2431 514514911u, 3886379478u, 4218272420u, 1480386793u,
2432 3900160816u,
2433 2292273451u,
2434 1276138356u, 1125461821u, 1912885715u, 3365266013u,
2435 1333211627u, 4085009861u, 1390530102u, 3347984752u,
2436 2721771301u,
2437 1419492325u,
2438 4066766256u, 3250852311u, 820111852u, 1382201318u,
2439 2366036798u, 938032241u, 3100979439u, 487048687u,
2440 2292851045u,
2441 3241399180u,
2442 3912670510u, 2416437067u, 2973194517u, 3507707986u,
2443 1935099406u, 2533441488u, 104616731u, 2892622820u,
2444 3801190339u,
2445 4239188808u,
2446 807238241u, 3300121546u, 2249406147u, 4032114017u,
2447 3713738189u, 3324425575u, 4275607376u, 3663120298u,
2448 4173658372u,
2449 3984289690u,
2450 1827636846u, 3264588778u, 3297165529u, 558623533u,
2451 2728945672u, 1566297318u, 3447249966u, 481719551u,
2452 1596842050u,
2453 1838185946u,
2454 265271620u, 1050246315u, 4046655705u, 1844193138u,
2455 3807563245u, 1075384804u, 1292554949u, 1506525927u,
2456 2921816148u,
2457 2051885269u,
2458 1930534041u, 3872721086u, 1564489377u, 2272482181u,
2459 2849358683u, 589618304u, 2262072443u, 290363051u,
2460 299168363u,
2461 3867603931u,
2462 2868688756u, 2545263115u, 1092098533u, 3885725603u,
2463 2352430409u, 1981595469u, 2047946646u, 1332642839u,
2464 793806516u,
2465 214858837u,
2466 1061484659u, 3192394476u, 1115054785u, 3690637234u,
2467 996792368u, 2023479706u, 3046498231u, 4205835102u,
2468 3870714754u,
2469 257472875u,
2470 3549864599u, 2040276129u, 2414778670u, 812235477u,
2471 2674248196u, 1864096101u, 2257492689u, 1332556794u,
2472 1079540713u,
2473 465530720u,
2474 2304763972u, 830724724u, 3354588920u, 2510713652u,
2475 3103749409u, 468835585u, 1707620787u, 3038024846u,
2476 1000303198u,
2477 3462270146u,
2478 2748698899u, 2100348093u, 511537258u, 1237187486u,
2479 102049383u, 2268226698u, 3162251739u, 4219404629u,
2480 838822407u,
2481 1481440623u,
2482 2989224077u, 2676681975u, 3246551821u, 3812079906u,
2483 370572963u, 2283154352u, 3084789986u, 1961085583u,
2484 1955640586u,
2485 2409348147u,
2486 2284780581u, 1634818716u, 4018221729u, 2320761377u,
2487 3566831899u, 1799560520u, 91431959u, 1754113747u,
2488 1459430477u,
2489 3613658517u,
2490 924489906u, 3406317699u, 866289774u, 3924821603u,
2491 1265394945u, 1870668109u, 151949856u, 2747006534u,
2492 3111906201u,
2493 64039467u,
2494 2314447545u, 2600195638u, 4095795204u, 4162096026u,
2495 1026756826u, 2460047982u, 52686887u, 823198739u,
2496 1518045160u,
2497 2867527376u,
2498 566410761u, 2200433819u, 2114146405u, 2893790965u,
2499 881504901u, 974783212u, 490815659u, 937300283u,
2500 1523735309u,
2501 2511976468u,
2502 2634644947u, 355119367u, 1373773092u, 309232995u,
2503 3088671051u, 787126032u, 3442836843u, 4289194567u,
2504 2177850062u,
2505 1174136430u,
2506 3248982914u, 3129039732u, 1166851580u, 2196451882u,
2507 469595580u, 2130837700u, 3783349021u, 3745262548u,
2508 1236930515u,
2509 3032131496u,
2510 1525591437u, 1823628217u, 1939019255u, 1950270463u,
2511 3659899927u, 3688643445u, 3004399289u, 1155199552u,
2512 357547234u,
2513 2213110526u,
2514 3122658210u, 2667800490u, 2718690333u, 3512372076u,
2515 1098611683u, 2657518392u, 4248458835u, 3109874532u,
2516 1592908438u,
2517 2864927516u,
2518 3635248840u, 1251777186u, 3797340158u, 3508496870u,
2519 303354834u, 1482394062u, 2087100120u, 1595931912u,
2520 608574156u,
2521 723367884u,
2522 907938402u, 3357047807u, 1619629851u, 3092082995u,
2523 89030300u, 916336992u, 1861180168u, 3436334155u,
2524 1375000544u,
2525 3472936241u,
2526 1321217853u, 791356402u, 2872410224u, 2326250297u,
2527 2657644088u, 1748314108u, 4146771421u, 2913114440u,
2528 2924821844u,
2529 2101101496u,
2530 3268017251u, 2109603066u, 690665520u, 1830067573u,
2531 951427661u, 2982533150u, 3884512506u, 2358657479u,
2532 2833210784u,
2533 3419798214u,
2534 3785893994u, 2103940206u, 86759766u, 4031230616u,
2535 3745237192u, 2739453927u, 497038072u, 3303159408u,
2536 1251537249u,
2537 1993408196u,
2538 3185905715u, 2885948408u, 3154277110u, 2444150313u,
2539 2505582079u, 2120610195u, 3266465773u, 1814611964u,
2540 3080050407u,
2541 1079915522u,
2542 1819346505u, 2529946763u, 892097374u, 3740257161u,
2543 3618100441u, 1079900094u, 3607172225u, 737863389u,
2544 360704560u,
2545 3341993089u,
2546 1139047381u, 3132219631u, 1248981859u, 1109338159u,
2547 2004908615u, 4022302594u, 4166640860u, 2959140950u,
2548 3949235962u,
2549 2832278473u,
2550 2200524012u, 2634933043u, 2495844522u, 2613799818u,
2551 4034096813u, 683271795u, 1673546817u, 1363163726u,
2552 1805395136u,
2553 511749501u,
2554 1231032599u, 2305979751u, 345737783u, 3339868854u,
2555 2931857933u, 2323251738u, 1332068477u, 51846558u,
2556 3927238177u,
2557 1387182179u,
2558 1701238601u, 1419275173u, 2580882268u, 3357874599u,
2559 1726558907u, 1292901039u, 1371322339u, 1311713044u,
2560 3526735232u,
2561 4017884184u,
2562 3366093428u, 77140994u, 2128996229u, 1357915765u,
2563 4019691901u, 483989024u, 2390311750u, 2766065288u,
2564 3938587520u,
2565 3064810344u,
2566 1054589198u, 1274997019u, 4040589616u, 1277751144u,
2567 2274907047u, 4170399945u, 2886368209u, 4168922115u,
2568 3901237033u,
2569 3252972311u,
2570 2205185840u, 3403097556u, 3385493699u, 2809751370u,
2571 555319628u, 399539034u, 2998971454u, 1521596214u,
2572 178870216u,
2573 1471733541u,
2574 519629198u, 514159209u, 1500582242u, 1928616587u,
2575 2686427928u, 4133138798u, 1225914083u, 1432713584u,
2576 3559310915u,
2577 3925489366u,
2578 1055613123u, 4126676029u, 2723867653u, 3290604111u,
2579 1377022957u, 2373608155u, 3615237379u, 594338683u,
2580 2645257602u,
2581 2408427260u,
2582 917033274u, 750455097u, 625657657u, 121713200u,
2583 2191273413u, 4043949724u, 3293146785u, 3809297972u,
2584 3947296919u,
2585 115456894u,
2586 1529576616u, 1459278275u, 2157117997u, 1747859293u,
2587 4106665903u, 996939232u, 2007976332u, 4274649009u,
2588 1017725787u,
2589 4244666096u,
2590 1219631331u, 3072426253u, 3547691720u, 1620822012u,
2591 1397717508u, 2031597325u, 3345983430u, 2459068000u,
2592 3645130467u,
2593 2308642742u,
2594 359955852u, 1348467968u, 1133123059u, 2435919062u,
2595 2800365907u, 4213217210u, 4056565603u, 2811666556u,
2596 2318007236u,
2597 3823652401u,
2598 3654086429u, 1273260424u, 1591610446u, 943349350u,
2599 3441227678u, 3779964757u, 233818224u, 3469971032u,
2600 3764095096u,
2601 4009204587u,
2602 678472092u, 1990559652u, 2583121088u, 2978143652u,
2603 2496370864u, 2139539656u, 4287972050u, 295832576u,
2604 3536742861u,
2605 2257466133u,
2606 2738052161u, 1988611898u, 2466189642u, 3294419573u,
2607 2311186273u, 474374532u, 3081964174u, 2515138278u,
2608 835731677u,
2609 1178182694u,
2610 3352119543u, 2884763225u, 3462399574u, 2900817210u,
2611 1993698511u, 2868445043u, 2746444849u, 1205258179u,
2612 2353442946u,
2613 4079040070u,
2614 3624133102u, 2907136076u, 2902521697u, 426813211u,
2615 1418185512u, 3711189488u, 1351506552u, 1934749519u,
2616 46595543u,
2617 401688809u,
2618 3514602124u, 1396852607u, 1951477943u, 2502249173u,
2619 3199695820u, 2890250638u, 4205072507u, 1715623846u,
2620 3266686789u,
2621 3218688128u,
2622 1697759742u, 851227671u, 2358709645u, 4174233268u,
2623 500583683u, 3805940955u, 736234120u, 2710563712u,
2624 1949664540u,
2625 3139414003u,
2626 4293073253u, 1284406972u, 1785182449u, 1051548274u,
2627 2994248357u, 2499882522u, 717208669u, 2039517285u,
2628 518424929u,
2629 143136433u,
2630 2303774671u, 1272930860u, 2286410920u, 788459311u,
2631 273225293u, 2439291703u, 2254505236u, 3446287701u,
2632 3655156558u,
2633 1546628787u,
2634 340081500u, 3285722006u, 1324810435u, 1053980860u,
2635 1779472859u, 2700355724u, 686005017u, 3762376315u,
2636 3963193100u,
2637 1370881135u,
2638 661300087u, 1152753704u, 2349891598u, 3910051187u,
2639 2109444785u, 1311123870u, 2639837565u, 1896770931u,
2640 1081414128u,
2641 869877586u,
2642 4284220400u, 63045374u, 235968615u, 184451062u,
2643 1271099822u, 1319179857u, 3274963209u, 4172272710u,
2644 3388797445u,
2645 2965973320u,
2646 3793110097u, 3327241723u, 2991804005u, 1199544355u,
2647 771553759u, 2031749842u, 2596517372u, 1199888213u,
2648 858347951u,
2649 3340178832u,
2650 2903875412u, 763490382u, 76949161u, 2056544406u,
2651 1145227689u, 998233136u, 2354530024u, 427713587u,
2652 3537837347u,
2653 604661755u,
2654 923986833u, 1023730418u, 798294227u, 432557449u,
2655 801802449u, 1861313429u, 3899128441u, 4068407979u,
2656 2352677083u,
2657 3783539925u,
2658 10731973u, 3390767975u, 3949540249u, 1920121661u,
2659 3248580201u, 641956426u, 2104847395u, 604835744u,
2660 1491663404u,
2661 4255204651u,
2662 1520970746u, 2845653368u, 3247412938u, 3730629005u,
2663 855569514u, 3073294700u, 2429691698u, 3818342476u,
2664 3938869985u,
2665 2731201328u,
2666 2335202643u, 778117742u, 13298408u, 228780590u,
2667 2871715314u, 3253688653u, 4150999702u, 3846220408u,
2668 930808u,
2669 1397128726u,
2670 1964216488u, 2781092828u, 116285375u, 2271239476u,
2671 3724347554u, 2931203895u, 3893169206u, 1883912528u,
2672 2093892660u,
2673 3658787024u,
2674 3095016046u, 1094059199u, 3640239610u, 558564267u,
2675 2102812456u, 464734873u, 925262247u, 1609838036u,
2676 588364741u,
2677 1731409233u,
2678 1576165139u, 3933979268u, 375316394u, 4247099643u,
2679 3670508019u, 4080496835u, 2371248533u, 183762693u,
2680 2078935389u,
2681 2699810414u,
2682 1491815683u, 2999180789u, 1831158425u, 1603373553u,
2683 2006136905u, 3210230591u, 416748595u, 1536971415u,
2684 3271869367u,
2685 1266062739u,
2686 2138414557u, 3337114778u, 1634586826u, 36472629u,
2687 4482244u, 568009609u, 2721216780u, 4037289545u,
2688 2235138807u,
2689 1789351460u,
2690 4067539527u, 1323062829u, 3864620647u, 4192026301u,
2691 4278901241u, 1399025382u, 2826652805u, 1363860382u,
2692 1801770651u,
2693 1613381526u,
2694 1165249276u, 4046576622u, 2535596946u, 3260388176u,
2695 1078898578u, 2259750862u, 643387587u, 237144235u,
2696 4199571427u,
2697 3440917581u,
2698 3067939258u, 2018625455u, 1460528353u, 3138629939u,
2699 1666223528u, 3841139376u, 2528281125u, 885565193u,
2700 2609492686u,
2701 2517257479u,
2702 560864620u, 2261471820u, 3491559165u, 1329620416u,
2703 622383582u, 1759597655u, 2877873893u, 584692817u,
2704 1901728399u,
2705 2599000260u,
2706 3169771644u, 296332336u, 774719455u, 4175920823u,
2707 2287316070u, 4115615023u, 1073335619u, 4240292725u,
2708 1359158837u,
2709 1960974237u,
2710 3173724597u, 1619084286u, 2876340752u, 4065675347u,
2711 480741335u, 1237329941u, 701055566u, 3729009837u,
2712 1314736422u,
2713 4003180069u,
2714 3118519317u, 3035354420u, 3380357671u, 4020909015u,
2715 253958714u, 3545798863u, 3008185002u, 2624719888u,
2716 3219955575u,
2717 3060719376u,
2718 573101682u, 1580316843u, 2610493412u, 3490983536u,
2719 3601975611u, 851470366u, 635384901u, 3427048824u,
2720 1470002757u,
2721 3592460087u,
2722 2265226856u, 4124282457u, 2106385486u, 3334305617u,
2723 4208282753u, 3798749815u, 225396466u, 118791182u,
2724 2523395972u,
2725 194595464u,
2726 2563824631u, 2521301383u, 4224409406u, 468670274u,
2727 1761966400u, 1300908277u, 2570709228u, 1847901526u,
2728 1470099163u,
2729 2690466752u,
2730 1472536718u, 2399279735u, 4150607803u, 1775080054u,
2731 2082537685u, 4080034578u, 1256001880u, 392967725u,
2732 2055838940u,
2733 3349115816u,
2734 1745947263u, 2213925887u, 1836572741u, 2417722792u,
2735 636223705u, 2423329294u, 3960951311u, 1543591052u,
2736 1547914361u,
2737 2760945653u,
2738 3519014111u, 313543871u, 4119598884u, 1071003714u,
2739 2192556597u, 1526995535u, 3929839778u, 536388591u,
2740 3040873792u,
2741 3752682932u,
2742 1640614237u, 2432794021u, 385337403u, 2794410617u,
2743 2386128075u, 1055206708u, 1422747714u, 3759330929u,
2744 2533597496u,
2745 30440955u,
2746 1482899460u, 3350385050u, 616259409u, 3980103795u,
2747 1211364140u, 1040071544u, 594746920u, 1645973936u,
2748 2547331531u,
2749 1097726368u,
2750 700666526u, 2976247482u, 1144906608u, 996506677u,
2751 1997130756u, 800321417u, 1392942823u, 1601662248u,
2752 2079778663u,
2753 529512908u,
2754 2925120134u, 4106433085u, 630221833u, 2423086156u,
2755 1119859778u, 1726827981u, 1870859181u, 2559832707u,
2756 1792284257u,
2757 2059356387u,
2758 3572353364u, 3229407475u, 575621095u, 3221893291u,
2759 2372428048u, 2020123035u, 961449593u, 2243824063u,
2760 3803906611u,
2761 3735348189u,
2762 2981620804u, 4180681078u, 1555330629u, 230736535u,
2763 2075526640u, 749652975u, 713664372u, 2152096659u,
2764 2142067223u,
2765 3322302242u,
2766 1421646830u, 2092832615u, 1213735101u, 3192136753u,
2767 1106723940u, 3455398230u, 2541685524u, 2529956739u,
2768 3789430647u,
2769 1950084508u,
2770 2157395621u, 850457360u, 2758902426u, 2848030169u,
2771 6506379u, 1162213157u, 2981459221u, 272690871u,
2772 3059420255u,
2773 4242691285u,
2774 588065598u, 1206949936u, 3968214184u, 566348532u,
2775 126142880u, 1480567086u, 2959621988u, 2050218418u,
2776 2242731195u,
2777 3833514449u,
2778 1898070331u, 3687399477u, 3891859374u, 868185955u,
2779 2335308774u, 3676335246u, 3871121805u, 2189032743u,
2780 3275728647u,
2781 860492892u,
2782 1590764344u, 4130384758u, 262871548u, 3004764525u,
2783 2685542071u, 991231482u, 435122019u, 3031116998u,
2784 2898921700u,
2785 2917932604u,
2786 4238665148u, 2459072654u, 3444612545u, 4207731740u,
2787 1808564313u, 2798532269u, 3944553556u, 3926395409u,
2788 1633200670u,
2789 4138335224u,
2790 2524878605u, 4184292650u, 3563398268u, 4288943552u,
2791 3802121210u, 957502058u, 2410820887u, 4227117506u,
2792 4018625153u,
2793 4284329158u,
2794 530216712u, 2978986531u, 863452221u, 1910162118u,
2795 4088211378u, 4091971261u, 3150811451u, 4200871487u,
2796 3794038652u,
2797 3041564310u,
2798 2045287082u, 887805614u, 2889167251u, 4120352181u,
2799 1699912580u, 3478922097u, 3211994687u, 3136177842u,
2800 1500806861u,
2801 3211881347u,
2802 2147976385u, 3342722260u, 3359650541u, 4197378460u,
2803 781354073u, 1533623029u, 2204677828u, 3228172832u,
2804 3248592437u,
2805 3355841359u,
2806 560815159u, 1144951236u, 4027015711u, 2882625391u,
2807 339363613u, 2354572719u, 1769831876u, 4238589331u,
2808 1519732871u,
2809 2185834614u,
2810 1601096831u, 129709881u, 39655633u, 367604993u,
2811 1737681770u, 3259114599u, 2767070452u, 872365177u,
2812 1574125529u,
2813 3405020189u,
2814 4181346685u, 1134030380u, 403769171u, 2193351164u,
2815 1426232618u, 2885309450u, 3033612627u, 924948363u,
2816 935514094u,
2817 3202053329u,
2818 912294839u, 1618472324u, 4159158431u, 3744999487u,
2819 777064358u, 3974213124u, 1990246048u, 309725290u,
2820 2449849392u,
2821 1943692420u,
2822 2288635750u, 2433793635u, 2168904061u, 683315308u,
2823 3081493019u, 3477759434u, 3815496269u, 2823504699u,
2824 586945121u,
2825 3088963200u,
2826 3492287335u, 636875049u, 1111206944u, 2037346120u,
2827 1282050044u, 1409681512u, 1786128584u, 755810950u,
2828 2332676758u,
2829 2178142310u,
2830 957827166u, 1014983590u, 1888800725u, 3608595803u,
2831 3200072714u, 2534008478u, 659336139u, 1281728287u,
2832 4060560529u,
2833 2915575125u,
2834 3521503774u, 2926487340u, 1096297674u, 653489861u,
2835 2352326980u, 2561136777u, 1224141198u, 1250479629u,
2836 1297625391u,
2837 2409997371u,
2838 1942483722u, 2481835750u, 1394715707u, 1673070941u,
2839 2456039704u, 3980558014u, 3547934764u, 1882038812u,
2840 1078160498u,
2841 2488279087u,
2842 1848235245u, 1211914722u, 2264928765u, 2807773070u,
2843 270145554u, 583747883u, 3826009010u, 2996618216u,
2844 425727157u,
2845 992726957u,
2846 3384462280u, 726650661u, 1955043265u, 1923879512u,
2847 1854693773u, 2987614542u, 2660044993u, 2457260810u,
2848 426299370u,
2849 2671892900u,
2850 1827308087u, 3083953443u, 1791749638u, 3265087416u,
2851 2119752201u, 2547122538u, 3990783236u, 1912713468u,
2852 3688865211u,
2853 1815780016u,
2854 303699291u, 2416763742u, 2690891610u, 1535193548u,
2855 1107803989u, 1504143133u, 2235270371u, 2545884083u,
2856 2276278682u,
2857 411724404u,
2858 3416925704u, 2565792091u, 3383911757u, 546058824u,
2859 3374654444u, 2364630415u, 2693473470u, 2622125691u,
2860 261864817u,
2861 55682470u,
2862 857617568u, 141304067u, 1885488541u, 155368182u,
2863 1281949051u, 3384522408u, 3254816901u, 1959816782u,
2864 1452224057u,
2865 2830267691u,
2866 3709231247u, 58988202u, 4218130458u, 2984061349u,
2867 1888707848u, 4223605071u, 4241442486u, 375269213u,
2868 3208327038u,
2869 2199916493u,
2870 550337252u, 2855061437u, 276088636u, 114362204u,
2871 2321163647u, 2127813633u, 3289403024u, 2686973202u,
2872 2717376797u,
2873 3593428039u,
2874 3648831666u, 890925902u, 3289404818u, 3289516821u,
2875 4248913260u, 1858916580u, 3303932308u, 1752797086u,
2876 1628149686u,
2877 3245893605u,
2878 1568537311u, 2844194502u, 1593855770u, 2408174109u,
2879 124797514u, 2085649512u, 3188565660u, 2264996276u,
2880 1926696513u,
2881 3053957740u,
2882 2238806881u, 2189050973u, 203685243u, 379855590u,
2883 3920271562u, 1058600179u, 3698061923u, 4255106849u,
2884 608401664u,
2885 1598041932u,
2886 3318266418u, 2535016555u, 852760884u, 1918098822u,
2887 2200437599u, 1532285043u, 3425662132u, 3561293706u,
2888 2231633206u,
2889 4108785088u,
2890 3359152801u, 173534780u, 208383607u, 2862988169u,
2891 2406642243u, 426814583u, 2777335795u, 3322703596u,
2892 954190623u,
2893 615093090u,
2894 4179102978u, 2452847930u, 100239619u, 42471741u,
2895 818352432u, 2190624654u, 504379960u, 3631619975u,
2896 633412456u,
2897 1018421783u,
2898 842645419u, 711808707u, 3424580813u, 2132457941u,
2899 1158335882u, 3567952480u, 2302183699u, 1145788151u,
2900 3474264138u,
2901 3105085243u,
2902 3115506027u, 2783713015u, 3871785309u, 539583269u,
2903 1400252405u, 3857849984u, 4231186588u, 1278653799u,
2904 1760227022u,
2905 761044088u,
2906 3838185417u, 2439542532u, 585283357u, 2055995220u,
2907 937117124u, 3831944855u, 1823586038u, 3287917855u,
2908 485082427u,
2909 3209172809u,
2910 1984570176u, 2818337297u, 2691869057u, 3790476953u,
2911 839035557u, 3203129010u, 669981176u, 4121157385u,
2912 3519870450u,
2913 3792633352u,
2914 3017650322u, 1603459507u, 4225677666u, 376555451u,
2915 473780127u, 2018786277u, 3299822439u, 1010254499u,
2916 2383887565u,
2917 3155009499u,
2918 3108110655u, 2641738274u, 3684908622u, 1606463047u,
2919 3311068174u, 52708046u, 754181455u, 1018079176u,
2920 3915670272u,
2921 3366999425u,
2922 1012880204u, 1339439715u, 466437962u, 1402662350u,
2923 2504046911u, 736323938u, 2037800124u, 1725908589u,
2924 716341840u,
2925 1750123474u,
2926 3366342464u, 1743666195u, 2975303189u, 3821364027u,
2927 3253707772u, 3635548377u, 3840413796u, 1955642085u,
2928 1018315169u,
2929 1258092848u,
2930 2095540656u, 1076256607u, 117289557u, 1311658655u,
2931 2118301000u, 68721550u, 2886814107u, 2712432819u,
2932 4201862886u,
2933 753807148u,
2934 1940229047u, 731347296u, 1068901393u, 3873155894u,
2935 2852787666u, 1973464853u, 79735652u, 3966380587u,
2936 3245740712u,
2937 2525773438u,
2938 734938109u, 3045656416u, 3335746354u, 4099732691u,
2939 1911896517u, 1697006473u, 1145487066u, 1605663299u,
2940 3053606724u,
2941 2386289465u,
2942 3821211369u, 1006215345u, 1256304829u, 1053001668u,
2943 1289194958u, 118761054u, 1853688730u, 2803418011u,
2944 188650809u,
2945 3763686458u,
2946 1006829556u, 2961984133u, 3390525025u, 2061199893u,
2947 141792681u, 2439893463u, 2652982650u, 1804942682u,
2948 1546510005u,
2949 1246961405u,
2950 2407577046u, 565772575u, 3751844810u, 2943166103u,
2951 3750052451u, 3022527280u, 25162928u, 397381043u,
2952 1818337632u,
2953 3447363730u,
2954 3936437150u, 2569420703u, 2215592390u, 2171555672u,
2955 3665571006u, 4021712412u, 2939158353u, 4057813172u,
2956 1823237318u,
2957 103999245u,
2958 3251978010u, 3591914940u, 3582495283u, 2519035265u,
2959 3905726135u, 3180393349u, 2743117123u, 55247368u,
2960 3325286701u,
2961 705195946u,
2962 1857526853u, 1480518550u, 3809990433u, 1398189338u,
2963 3126362926u, 3959531492u, 1503658285u, 1977847740u,
2964 3043964489u,
2965 2613086143u,
2966 1518119282u, 4238434900u, 3905746486u, 3064949667u,
2967 1028122931u, 3309119457u, 4071194920u, 3096098907u,
2968 4137180520u,
2969 494467959u,
2970 1231408687u, 1691606157u, 1793452569u, 2722196118u,
2971 3478603952u, 1059665738u, 2282032278u, 3990268388u,
2972 1719514651u,
2973 4248311578u,
2974 3799146721u, 898026304u, 3367808954u, 4162472815u,
2975 170495870u, 1308116609u, 3428285344u, 1714716475u,
2976 395576794u,
2977 4153638621u,
2978 2999745812u, 3483315953u, 304980828u, 595337120u,
2979 3486516729u, 2331563143u, 2583609459u, 1885928417u,
2980 3834283777u,
2981 979337825u,
2982 932057378u, 3124081189u, 1930356777u, 3865887996u,
2983 4178282217u, 4214219408u, 3669465884u, 1472413856u,
2984 3356866587u,
2985 1012769806u,
2986 3043639963u, 996996396u, 207308216u, 982967331u,
2987 2991319933u, 318066902u, 721489670u, 1249967713u,
2988 749240921u,
2989 591392325u,
2990 2379365192u, 2250868849u, 2163259329u, 143191325u,
2991 3778285606u, 982149096u, 3536906200u, 2244353244u,
2992 1443862317u,
2993 3161549210u,
2994 2183127464u, 2015409516u, 547003700u, 2032484282u,
2995 523677821u, 4275663308u, 3827205526u, 3903778273u,
2996 2444530525u,
2997 2543645801u,
2998 1173958423u, 784740616u, 2878693675u, 3127696736u,
2999 3832037316u, 3161002398u, 4084166400u, 4213346853u,
3000 223390424u,
3001 4273380883u,
3002 2130315482u, 3429606032u, 3367732613u, 1912357694u,
3003 422632590u, 1266957023u, 3437535648u, 736404240u,
3004 2281709372u,
3005 415859912u,
3006 212948797u, 351612650u, 3920561440u, 112963586u,
3007 2230727543u, 2851076612u, 1990662634u, 2264296857u,
3008 3131463650u,
3009 2704034623u,
3010 3541637839u, 2954232792u, 533986918u, 4158757533u,
3011 65174248u, 4232639593u, 865906667u, 1948225652u,
3012 779656112u,
3013 3873989249u,
3014 2372984749u, 2346988193u, 1104345713u, 1165654138u,
3015 4045762610u, 3588205178u, 461363991u, 1111215752u,
3016 1389675192u,
3017 2404325151u,
3018 2152228101u, 3808973622u, 1901235912u, 3458690696u,
3019 314513238u, 2539459143u, 2847998873u, 952026138u,
3020 2325705328u,
3021 407844712u,
3022 3727960715u, 2996448351u, 2374336760u, 3138756390u,
3023 2600015243u, 539980418u, 1876285352u, 1670330799u,
3024 1709360377u,
3025 2868531654u,
3026 494777964u, 2773053597u, 599486162u, 3962209577u,
3027 1871328846u, 2171933018u, 110279472u, 384074780u,
3028 4147021936u,
3029 2333589647u,
3030 4251778066u, 40493468u, 3099342316u, 4108779767u,
3031 2812424588u, 954542332u, 2040682331u, 2251152306u,
3032 45915516u,
3033 259525626u,
3034 1045384743u, 4134656562u, 749389261u, 874399445u,
3035 616549904u, 2200447504u, 436024539u, 78972290u,
3036 3210485762u,
3037 1907985531u,
3038 3013721395u, 4214533685u, 4198804243u, 534879265u,
3039 1517190881u, 3756787754u, 1152563554u, 1718750948u,
3040 777737463u,
3041 1402478860u,
3042 1824562784u, 1879401449u, 3515818786u, 513165201u,
3043 1423491227u, 2103067918u, 2291777410u, 1097943000u,
3044 };
3045
3046 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)3047 bool Test(int offset, int len = 0) {
3048 #undef Check
3049 #undef IsAlive
3050
3051 #define Check(x) do { \
3052 bool ok = expected[index++] == (x); \
3053 assert(ok); \
3054 errors += !ok; \
3055 } while (0)
3056
3057 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
3058
3059 // After the following line is where the uses of "Check" and such will go.
3060 static int index = 0;
3061 if (offset == -1) { int alive = 0; IsAlive(farmhashcc::Hash32WithSeed(data, len++, SEED)); IsAlive(farmhashcc::Hash32(data, len++)); { uint128_t u = farmhashcc::Fingerprint128(data, len++); uint64_t h = Uint128Low64(u); IsAlive(h >> 32); IsAlive((h << 32) >> 32); h = Uint128High64(u); IsAlive(h >> 32); IsAlive((h << 32) >> 32); } len -= 3; return alive > 0; }
3062 Check(farmhashcc::Hash32WithSeed(data + offset, len, SEED));
3063 Check(farmhashcc::Hash32(data + offset, len));
3064 { uint128_t u = farmhashcc::Fingerprint128(data + offset, len); uint64_t h = Uint128Low64(u); Check(h >> 32); Check((h << 32) >> 32); h = Uint128High64(u); Check(h >> 32); Check((h << 32) >> 32); }
3065 { uint128_t u = farmhashcc::CityHash128WithSeed(data + offset, len, Uint128(SEED0, SEED1)); uint64_t h = Uint128Low64(u); Check(h >> 32); Check((h << 32) >> 32); h = Uint128High64(u); Check(h >> 32); Check((h << 32) >> 32); }
3066
3067 return true;
3068 #undef Check
3069 #undef IsAlive
3070 }
3071
RunTest()3072 int RunTest() {
3073 Setup();
3074 int i = 0;
3075 cout << "Running farmhashccTest";
3076 if (!Test(-1)) {
3077 cout << "... Unavailable\n";
3078 return NoteErrors();
3079 }
3080 // Good. The function is attempting to hash, so run the full test.
3081 int errors_prior_to_test = errors;
3082 for ( ; i < kTestSize - 1; i++) {
3083 Test(i * i, i);
3084 }
3085 for ( ; i < kDataSize; i += i / 7) {
3086 Test(0, i);
3087 }
3088 Test(0, kDataSize);
3089 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
3090 return NoteErrors();
3091 }
3092
3093 #else
3094
3095 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)3096 void Dump(int offset, int len) {
3097 cout << farmhashcc::Hash32WithSeed(data + offset, len, SEED) << "u," << endl;
3098 cout << farmhashcc::Hash32(data + offset, len) << "u," << endl;
3099 { uint128_t u = farmhashcc::Fingerprint128(data + offset, len); uint64_t h = Uint128Low64(u); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u, "; h = Uint128High64(u); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u," << endl; }
3100 { uint128_t u = farmhashcc::CityHash128WithSeed(data + offset, len, Uint128(SEED0, SEED1)); uint64_t h = Uint128Low64(u); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u, "; h = Uint128High64(u); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u," << endl; }
3101 }
3102
3103 #endif
3104
3105 #undef SEED
3106 #undef SEED1
3107 #undef SEED0
3108
3109 } // namespace farmhashccTest
3110
3111 #if TESTING
3112
3113 static int farmhashccTestResult = farmhashccTest::RunTest();
3114
3115 #else
main(int argc,char ** argv)3116 int main(int argc, char** argv) {
3117 Setup();
3118 cout << "uint32_t expected[] = {\n";
3119 int i = 0;
3120 for ( ; i < kTestSize - 1; i++) {
3121 farmhashccTest::Dump(i * i, i);
3122 }
3123 for ( ; i < kDataSize; i += i / 7) {
3124 farmhashccTest::Dump(0, i);
3125 }
3126 farmhashccTest::Dump(0, kDataSize);
3127 cout << "};\n";
3128 }
3129 #endif
3130 #ifndef FARMHASH_SELF_TEST_GUARD
3131 #define FARMHASH_SELF_TEST_GUARD
3132 #include <string.h>
3133 #include <cstdio>
3134 #include <iostream>
3135
3136 using std::cout;
3137 using std::cerr;
3138 using std::endl;
3139 using std::hex;
3140
3141 static const uint64_t kSeed0 = 1234567;
3142 static const uint64_t kSeed1 = k0;
3143 static const int kDataSize = 1 << 20;
3144 static const int kTestSize = 300;
3145 #define kSeed128 Uint128(kSeed0, kSeed1)
3146
3147 static char data[kDataSize];
3148
3149 static int completed_self_tests = 0;
3150 static int errors = 0;
3151
3152 // Initialize data to pseudorandom values.
Setup()3153 void Setup() {
3154 if (completed_self_tests == 0) {
3155 uint64_t a = 9;
3156 uint64_t b = 777;
3157 for (int i = 0; i < kDataSize; i++) {
3158 a += b;
3159 b += a;
3160 a = (a ^ (a >> 41)) * k0;
3161 b = (b ^ (b >> 41)) * k0 + i;
3162 uint8_t u = b >> 37;
3163 memcpy(data + i, &u, 1); // uint8_t -> char
3164 }
3165 }
3166 }
3167
NoteErrors()3168 int NoteErrors() {
3169 #define NUM_SELF_TESTS 6
3170 if (++completed_self_tests == NUM_SELF_TESTS)
3171 std::exit(errors > 0);
3172 return errors;
3173 }
3174
IsNonZero(T x)3175 template <typename T> inline bool IsNonZero(T x) {
3176 return x != 0;
3177 }
3178
IsNonZero(uint128_t x)3179 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
3180 return x != Uint128(0, 0);
3181 }
3182
3183 #endif // FARMHASH_SELF_TEST_GUARD
3184
3185 namespace farmhashmkTest {
3186
CreateSeed(int offset,int salt)3187 uint32_t CreateSeed(int offset, int salt) {
3188 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
3189 h = h * c1;
3190 h ^= (h >> 17);
3191 h = h * c1;
3192 h ^= (h >> 17);
3193 h = h * c1;
3194 h ^= (h >> 17);
3195 h += static_cast<uint32_t>(offset & 0xffffffff);
3196 h = h * c1;
3197 h ^= (h >> 17);
3198 h = h * c1;
3199 h ^= (h >> 17);
3200 h = h * c1;
3201 h ^= (h >> 17);
3202 return h;
3203 }
3204
3205 #undef SEED
3206 #undef SEED1
3207 #undef SEED0
3208 #define SEED CreateSeed(offset, -1)
3209 #define SEED0 CreateSeed(offset, 0)
3210 #define SEED1 CreateSeed(offset, 1)
3211
3212 #undef TESTING
3213 #define TESTING 1
3214 #if TESTING
3215 uint32_t expected[] = {
3216 4223616069u,
3217 3696677242u,
3218 4081014168u,
3219 2576519988u,
3220 2212771159u,
3221 1112731063u,
3222 1020067935u,
3223 3955445564u,
3224 1451961420u,
3225 653440099u,
3226 31917516u,
3227 2957164615u,
3228 2590087362u,
3229 3879448744u,
3230 176305566u,
3231 2447367541u,
3232 1359016305u,
3233 3363804638u,
3234 1117290165u,
3235 1062549743u,
3236 2437877004u,
3237 1894455839u,
3238 673206794u,
3239 3486923651u,
3240 3269862919u,
3241 2303349487u,
3242 1380660650u,
3243 595525107u,
3244 1525325287u,
3245 2025609358u,
3246 176408838u,
3247 1592885012u,
3248 864896482u,
3249 2101378090u,
3250 3489229104u,
3251 2118965695u,
3252 581644891u,
3253 2718789079u,
3254 631613207u,
3255 4228658372u,
3256 3867875546u,
3257 3531368319u,
3258 3804516756u,
3259 3317755099u,
3260 1619744564u,
3261 2884717286u,
3262 1088213445u,
3263 2667691076u,
3264 3727873235u,
3265 2330406762u,
3266 3616470388u,
3267 967660719u,
3268 4148162586u,
3269 315219121u,
3270 673084328u,
3271 3047602355u,
3272 1598963653u,
3273 1267826661u,
3274 2117362589u,
3275 2861192253u,
3276 1823625377u,
3277 1380350078u,
3278 1641748342u,
3279 1176094482u,
3280 269384321u,
3281 2178982315u,
3282 3480237248u,
3283 2660755208u,
3284 1850544433u,
3285 3429699438u,
3286 1262819303u,
3287 640556464u,
3288 2421125401u,
3289 2188368608u,
3290 2612932825u,
3291 1474432581u,
3292 173790449u,
3293 2124882189u,
3294 831272654u,
3295 622960146u,
3296 4238751051u,
3297 3250317967u,
3298 2120810248u,
3299 1948231495u,
3300 1389029321u,
3301 2200398357u,
3302 2134232963u,
3303 2948072329u,
3304 617717625u,
3305 681164587u,
3306 114859387u,
3307 430545646u,
3308 57239089u,
3309 3163338012u,
3310 3482496399u,
3311 557662576u,
3312 1102441413u,
3313 2670159360u,
3314 991116729u,
3315 846014240u,
3316 4233741566u,
3317 1802317242u,
3318 3129528802u,
3319 1459456375u,
3320 1305643039u,
3321 3258671612u,
3322 1578285833u,
3323 868590079u,
3324 1631034517u,
3325 1695432937u,
3326 561078856u,
3327 1004115553u,
3328 3086090507u,
3329 3818348650u,
3330 731596645u,
3331 780926790u,
3332 2544205955u,
3333 158479164u,
3334 3983514188u,
3335 2004735250u,
3336 3436218400u,
3337 673684751u,
3338 1463431419u,
3339 2880490219u,
3340 3223748024u,
3341 2218318859u,
3342 1474466194u,
3343 2636437533u,
3344 2206794961u,
3345 140995728u,
3346 1186394086u,
3347 1805716888u,
3348 1640037724u,
3349 3942729099u,
3350 1944727013u,
3351 918951560u,
3352 498666871u,
3353 3486974657u,
3354 2967205462u,
3355 1167253804u,
3356 1884281041u,
3357 2866015002u,
3358 4158319270u,
3359 2627220079u,
3360 3733319624u,
3361 3317092271u,
3362 438323662u,
3363 3195868065u,
3364 3426606709u,
3365 360708338u,
3366 1905491012u,
3367 650004803u,
3368 1351266252u,
3369 3133279000u,
3370 3722811115u,
3371 2722412434u,
3372 918432408u,
3373 3678271248u,
3374 269599647u,
3375 621514057u,
3376 3117077855u,
3377 1545425390u,
3378 2597567410u,
3379 1221437820u,
3380 3493254589u,
3381 102787342u,
3382 918861168u,
3383 348795089u,
3384 3439883229u,
3385 2353641807u,
3386 2209585469u,
3387 4035884492u,
3388 2686995435u,
3389 1649888022u,
3390 3852893848u,
3391 3042700028u,
3392 314103172u,
3393 726977769u,
3394 2489830276u,
3395 2872753660u,
3396 1316214989u,
3397 1488801501u,
3398 1811420390u,
3399 639581627u,
3400 2362837215u,
3401 3634581834u,
3402 3648576802u,
3403 1257314182u,
3404 762118371u,
3405 4268447045u,
3406 730167096u,
3407 755561509u,
3408 882614845u,
3409 3696972894u,
3410 228263661u,
3411 1478636142u,
3412 2767751651u,
3413 1532617116u,
3414 3838657661u,
3415 1944359935u,
3416 1401102137u,
3417 3772933173u,
3418 1050098254u,
3419 1658079354u,
3420 1846025728u,
3421 2204244794u,
3422 2017217424u,
3423 1275162853u,
3424 1429816745u,
3425 2175565479u,
3426 1716109139u,
3427 1187506761u,
3428 2434641075u,
3429 2725597783u,
3430 1795687662u,
3431 1393312782u,
3432 3511565397u,
3433 627885430u,
3434 4145733164u,
3435 2519005353u,
3436 231414775u,
3437 1242015635u,
3438 2760723497u,
3439 2185540568u,
3440 727314436u,
3441 2358790354u,
3442 1186393454u,
3443 4234795645u,
3444 350567813u,
3445 866773875u,
3446 3145590392u,
3447 1158374055u,
3448 3903123687u,
3449 1862119793u,
3450 2204587556u,
3451 4266276976u,
3452 4151548555u,
3453 915250402u,
3454 2874695320u,
3455 2360311410u,
3456 1099212769u,
3457 1271542714u,
3458 3473148363u,
3459 1637325418u,
3460 1807795989u,
3461 2493819794u,
3462 3800917924u,
3463 4001205856u,
3464 2582153621u,
3465 3365872040u,
3466 2890146216u,
3467 2626363824u,
3468 3133351295u,
3469 4046827296u,
3470 3053118771u,
3471 4113026751u,
3472 884356716u,
3473 3828347401u,
3474 10608262u,
3475 830987972u,
3476 1841080500u,
3477 3202717763u,
3478 3561778749u,
3479 1906000052u,
3480 3058284660u,
3481 1432904514u,
3482 2567431677u,
3483 2550162530u,
3484 665557986u,
3485 936887821u,
3486 2101205308u,
3487 4253535847u,
3488 1662043545u,
3489 1253611611u,
3490 2091370094u,
3491 2635077370u,
3492 2602176041u,
3493 3624115809u,
3494 748442714u,
3495 2709749154u,
3496 1023493343u,
3497 860291012u,
3498 3924715584u,
3499 1536436740u,
3500 2551145800u,
3501 2391782865u,
3502 1467705048u,
3503 2583909796u,
3504 3616666170u,
3505 1162857372u,
3506 4228631071u,
3507 1510132376u,
3508 2739165009u,
3509 2656606142u,
3510 3454996358u,
3511 3155038853u,
3512 1022087316u,
3513 100044110u,
3514 494208296u,
3515 2746186477u,
3516 4216782431u,
3517 225448834u,
3518 3728320521u,
3519 335282866u,
3520 3148194874u,
3521 953503703u,
3522 1293353960u,
3523 202372387u,
3524 1326119870u,
3525 4045123735u,
3526 3819994846u,
3527 1629004186u,
3528 1081099186u,
3529 3591584153u,
3530 1670825804u,
3531 3404257979u,
3532 3262192301u,
3533 2572846095u,
3534 3714992543u,
3535 4264142572u,
3536 529616678u,
3537 2882154574u,
3538 3006354178u,
3539 3865969421u,
3540 2007174907u,
3541 308283107u,
3542 2629833703u,
3543 3159124075u,
3544 1146492131u,
3545 494104332u,
3546 493149727u,
3547 1342910585u,
3548 521642387u,
3549 2201695937u,
3550 2517980959u,
3551 2426821287u,
3552 777374655u,
3553 2228189792u,
3554 4027055486u,
3555 228976000u,
3556 3842083468u,
3557 1723920223u,
3558 1192126094u,
3559 787744493u,
3560 2740368380u,
3561 2284153001u,
3562 2773829458u,
3563 442000614u,
3564 387830783u,
3565 2169780670u,
3566 2253144627u,
3567 3532502484u,
3568 1969684059u,
3569 1165351416u,
3570 3055056536u,
3571 3582324253u,
3572 231419363u,
3573 770979865u,
3574 3213983597u,
3575 3690452836u,
3576 935794639u,
3577 3230602762u,
3578 2841762457u,
3579 407598927u,
3580 1164479891u,
3581 3721799696u,
3582 354738136u,
3583 1801566618u,
3584 3206038542u,
3585 2621379981u,
3586 1943487262u,
3587 3534745636u,
3588 1074424589u,
3589 1304517521u,
3590 4133400969u,
3591 2339317978u,
3592 2135116860u,
3593 4180643791u,
3594 2415309340u,
3595 1855926417u,
3596 3418648630u,
3597 1968113037u,
3598 597304222u,
3599 3668824865u,
3600 3810008716u,
3601 3014702569u,
3602 3151212026u,
3603 156057449u,
3604 373134533u,
3605 2068234004u,
3606 191580563u,
3607 3832754488u,
3608 2924104199u,
3609 2026044494u,
3610 4065780435u,
3611 122565840u,
3612 4194985167u,
3613 2744823717u,
3614 2494098735u,
3615 3753793370u,
3616 1885739217u,
3617 2488161225u,
3618 3643797615u,
3619 2653367310u,
3620 2494061477u,
3621 189968132u,
3622 899646597u,
3623 392100396u,
3624 4012318310u,
3625 3855777086u,
3626 3566860954u,
3627 2698574996u,
3628 2414249905u,
3629 1330623339u,
3630 1263222732u,
3631 1277741760u,
3632 2194959402u,
3633 1629656136u,
3634 120494320u,
3635 1072368005u,
3636 1084245077u,
3637 4011372748u,
3638 1366613353u,
3639 3108643228u,
3640 3332219532u,
3641 2114746095u,
3642 3964007334u,
3643 371687128u,
3644 1084813876u,
3645 126459896u,
3646 4292782331u,
3647 321283184u,
3648 398168499u,
3649 3604983506u,
3650 560701543u,
3651 2073961354u,
3652 4240841868u,
3653 4151211362u,
3654 1338986875u,
3655 4093476832u,
3656 2269279497u,
3657 3500846299u,
3658 2510225147u,
3659 598000444u,
3660 1330391422u,
3661 1432533385u,
3662 4171226231u,
3663 426821154u,
3664 2932270996u,
3665 3378981077u,
3666 2217871549u,
3667 1619647984u,
3668 4051608043u,
3669 3180237819u,
3670 12919578u,
3671 1375401767u,
3672 371320427u,
3673 2986640571u,
3674 2336669859u,
3675 3796464715u,
3676 1892383284u,
3677 306814912u,
3678 2125823211u,
3679 1863678891u,
3680 3249703818u,
3681 3840225752u,
3682 281579900u,
3683 264680257u,
3684 4266359110u,
3685 4182229890u,
3686 2239659703u,
3687 3627947372u,
3688 2373929191u,
3689 224082765u,
3690 4053639058u,
3691 1862360303u,
3692 3187739624u,
3693 3392706679u,
3694 948039509u,
3695 817505760u,
3696 1215842393u,
3697 3462222651u,
3698 536021853u,
3699 182346832u,
3700 2731944883u,
3701 2346674384u,
3702 2640961678u,
3703 3446695687u,
3704 2271722179u,
3705 1301069656u,
3706 2803881468u,
3707 2832614405u,
3708 1691544398u,
3709 698756814u,
3710 3980620906u,
3711 3565421410u,
3712 754769376u,
3713 4115923404u,
3714 3909962218u,
3715 2747614077u,
3716 2888289845u,
3717 1016920862u,
3718 2790946178u,
3719 3067070960u,
3720 3173251481u,
3721 1572132982u,
3722 255048203u,
3723 2996538818u,
3724 3405398987u,
3725 136106013u,
3726 3581605228u,
3727 4277437977u,
3728 2147300534u,
3729 3728426265u,
3730 3483629996u,
3731 1478452694u,
3732 20756076u,
3733 2774992067u,
3734 432987927u,
3735 1516771026u,
3736 3511588664u,
3737 2130994978u,
3738 509385406u,
3739 873090347u,
3740 2163904107u,
3741 4192239086u,
3742 2532489989u,
3743 1090772651u,
3744 3910797408u,
3745 3710882132u,
3746 155010959u,
3747 1369823531u,
3748 1599664937u,
3749 4035593587u,
3750 1212746925u,
3751 795822552u,
3752 116689518u,
3753 3674240941u,
3754 1135576664u,
3755 756750261u,
3756 1027431362u,
3757 390555140u,
3758 2228460216u,
3759 1506940482u,
3760 3733857700u,
3761 3048762971u,
3762 2511703196u,
3763 548609887u,
3764 1607354252u,
3765 659053982u,
3766 259884450u,
3767 1793130460u,
3768 4083364495u,
3769 3148555881u,
3770 1764350138u,
3771 2436485683u,
3772 4031563025u,
3773 3261860724u,
3774 2475833430u,
3775 2101726086u,
3776 3191176464u,
3777 2646658847u,
3778 2127042126u,
3779 771316100u,
3780 2115922959u,
3781 3208515045u,
3782 2355437783u,
3783 3621147793u,
3784 1580163615u,
3785 3211555675u,
3786 3299188490u,
3787 191613920u,
3788 466733956u,
3789 2939029038u,
3790 1509152039u,
3791 130591314u,
3792 1892874677u,
3793 1646908044u,
3794 3452406523u,
3795 3998376606u,
3796 1199243832u,
3797 2187108812u,
3798 3189230066u,
3799 4161151481u,
3800 3371454980u,
3801 3681788646u,
3802 180842187u,
3803 3685022399u,
3804 3058749895u,
3805 3250165163u,
3806 2895367943u,
3807 2627101723u,
3808 771755098u,
3809 1332921024u,
3810 3638871848u,
3811 514215135u,
3812 3591227378u,
3813 2300310870u,
3814 3689533503u,
3815 851607114u,
3816 114330368u,
3817 2709027386u,
3818 1743034877u,
3819 1013693860u,
3820 288169008u,
3821 3545190686u,
3822 1052165084u,
3823 3995862307u,
3824 96902755u,
3825 1097819851u,
3826 2645431442u,
3827 2184148618u,
3828 2151206566u,
3829 350979797u,
3830 3467920900u,
3831 421116779u,
3832 1246252u,
3833 4057835428u,
3834 329324407u,
3835 4104482417u,
3836 844624570u,
3837 3306265806u,
3838 3787625025u,
3839 4263241191u,
3840 3251413927u,
3841 2921204431u,
3842 2931915325u,
3843 992134330u,
3844 3986338354u,
3845 1327895216u,
3846 1458363596u,
3847 1480608532u,
3848 728594368u,
3849 3804366693u,
3850 794404223u,
3851 1643240863u,
3852 793417255u,
3853 4167916443u,
3854 2683488959u,
3855 3124925324u,
3856 4184843652u,
3857 3750971752u,
3858 308509829u,
3859 1054550805u,
3860 2797511972u,
3861 4043123412u,
3862 1587158240u,
3863 4050518606u,
3864 3030062190u,
3865 2589912753u,
3866 603440067u,
3867 937013191u,
3868 1071662315u,
3869 2100661456u,
3870 2602005741u,
3871 435516078u,
3872 2260470147u,
3873 1256268350u,
3874 3612035u,
3875 3368856141u,
3876 151516099u,
3877 3081868591u,
3878 3363755681u,
3879 2049963149u,
3880 2885320434u,
3881 84682005u,
3882 2411758308u,
3883 2695174275u,
3884 3099904644u,
3885 1787308684u,
3886 1132379308u,
3887 564634346u,
3888 510236510u,
3889 2804443681u,
3890 3931864252u,
3891 2064427949u,
3892 1893979229u,
3893 2916544974u,
3894 1885887717u,
3895 2978018250u,
3896 494192125u,
3897 2642662373u,
3898 901112508u,
3899 636035003u,
3900 1658643797u,
3901 172746975u,
3902 517504890u,
3903 3440019372u,
3904 4144498044u,
3905 1854755456u,
3906 3672653905u,
3907 4176892856u,
3908 382159097u,
3909 282871690u,
3910 3629300472u,
3911 2500754041u,
3912 1677659759u,
3913 1067175061u,
3914 161654075u,
3915 1672575536u,
3916 346120493u,
3917 2730229631u,
3918 203466442u,
3919 1244549529u,
3920 199761971u,
3921 2744895408u,
3922 3195315331u,
3923 2124618519u,
3924 3261045496u,
3925 985339699u,
3926 3385585455u,
3927 1545740710u,
3928 3636652160u,
3929 2167020081u,
3930 1207897204u,
3931 28752417u,
3932 2895834146u,
3933 3640845375u,
3934 3750293073u,
3935 548997850u,
3936 4207814196u,
3937 4183030708u,
3938 2462810989u,
3939 3929965401u,
3940 };
3941
3942 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)3943 bool Test(int offset, int len = 0) {
3944 #undef Check
3945 #undef IsAlive
3946
3947 #define Check(x) do { \
3948 bool ok = expected[index++] == (x); \
3949 assert(ok); \
3950 errors += !ok; \
3951 } while (0)
3952
3953 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
3954
3955 // After the following line is where the uses of "Check" and such will go.
3956 static int index = 0;
3957 if (offset == -1) { int alive = 0; IsAlive(farmhashmk::Hash32WithSeed(data, len++, SEED)); IsAlive(farmhashmk::Hash32(data, len++)); IsAlive(farmhashmk::Hash32(data, len++)); len -= 3; return alive > 0; }
3958 Check(farmhashmk::Hash32WithSeed(data + offset, len, SEED));
3959 Check(farmhashmk::Hash32(data + offset, len));
3960
3961 return true;
3962 #undef Check
3963 #undef IsAlive
3964 }
3965
RunTest()3966 int RunTest() {
3967 Setup();
3968 int i = 0;
3969 cout << "Running farmhashmkTest";
3970 if (!Test(-1)) {
3971 cout << "... Unavailable\n";
3972 return NoteErrors();
3973 }
3974 // Good. The function is attempting to hash, so run the full test.
3975 int errors_prior_to_test = errors;
3976 for ( ; i < kTestSize - 1; i++) {
3977 Test(i * i, i);
3978 }
3979 for ( ; i < kDataSize; i += i / 7) {
3980 Test(0, i);
3981 }
3982 Test(0, kDataSize);
3983 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
3984 return NoteErrors();
3985 }
3986
3987 #else
3988
3989 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)3990 void Dump(int offset, int len) {
3991 cout << farmhashmk::Hash32WithSeed(data + offset, len, SEED) << "u," << endl;
3992 cout << farmhashmk::Hash32(data + offset, len) << "u," << endl;
3993 }
3994
3995 #endif
3996
3997 #undef SEED
3998 #undef SEED1
3999 #undef SEED0
4000
4001 } // namespace farmhashmkTest
4002
4003 #if TESTING
4004
4005 static int farmhashmkTestResult = farmhashmkTest::RunTest();
4006
4007 #else
main(int argc,char ** argv)4008 int main(int argc, char** argv) {
4009 Setup();
4010 cout << "uint32_t expected[] = {\n";
4011 int i = 0;
4012 for ( ; i < kTestSize - 1; i++) {
4013 farmhashmkTest::Dump(i * i, i);
4014 }
4015 for ( ; i < kDataSize; i += i / 7) {
4016 farmhashmkTest::Dump(0, i);
4017 }
4018 farmhashmkTest::Dump(0, kDataSize);
4019 cout << "};\n";
4020 }
4021 #endif
4022 #ifndef FARMHASH_SELF_TEST_GUARD
4023 #define FARMHASH_SELF_TEST_GUARD
4024 #include <string.h>
4025 #include <cstdio>
4026 #include <iostream>
4027
4028 using std::cout;
4029 using std::cerr;
4030 using std::endl;
4031 using std::hex;
4032
4033 static const uint64_t kSeed0 = 1234567;
4034 static const uint64_t kSeed1 = k0;
4035 static const int kDataSize = 1 << 20;
4036 static const int kTestSize = 300;
4037 #define kSeed128 Uint128(kSeed0, kSeed1)
4038
4039 static char data[kDataSize];
4040
4041 static int completed_self_tests = 0;
4042 static int errors = 0;
4043
4044 // Initialize data to pseudorandom values.
Setup()4045 void Setup() {
4046 if (completed_self_tests == 0) {
4047 uint64_t a = 9;
4048 uint64_t b = 777;
4049 for (int i = 0; i < kDataSize; i++) {
4050 a += b;
4051 b += a;
4052 a = (a ^ (a >> 41)) * k0;
4053 b = (b ^ (b >> 41)) * k0 + i;
4054 uint8_t u = b >> 37;
4055 memcpy(data + i, &u, 1); // uint8_t -> char
4056 }
4057 }
4058 }
4059
NoteErrors()4060 int NoteErrors() {
4061 #define NUM_SELF_TESTS 6
4062 if (++completed_self_tests == NUM_SELF_TESTS)
4063 std::exit(errors > 0);
4064 return errors;
4065 }
4066
IsNonZero(T x)4067 template <typename T> inline bool IsNonZero(T x) {
4068 return x != 0;
4069 }
4070
IsNonZero(uint128_t x)4071 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
4072 return x != Uint128(0, 0);
4073 }
4074
4075 #endif // FARMHASH_SELF_TEST_GUARD
4076
4077 namespace farmhashnaTest {
4078
CreateSeed(int offset,int salt)4079 uint32_t CreateSeed(int offset, int salt) {
4080 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
4081 h = h * c1;
4082 h ^= (h >> 17);
4083 h = h * c1;
4084 h ^= (h >> 17);
4085 h = h * c1;
4086 h ^= (h >> 17);
4087 h += static_cast<uint32_t>(offset & 0xffffffff);
4088 h = h * c1;
4089 h ^= (h >> 17);
4090 h = h * c1;
4091 h ^= (h >> 17);
4092 h = h * c1;
4093 h ^= (h >> 17);
4094 return h;
4095 }
4096
4097 #undef SEED
4098 #undef SEED1
4099 #undef SEED0
4100 #define SEED CreateSeed(offset, -1)
4101 #define SEED0 CreateSeed(offset, 0)
4102 #define SEED1 CreateSeed(offset, 1)
4103
4104 #undef TESTING
4105 #define TESTING 1
4106 #if TESTING
4107 uint32_t expected[] = {
4108 1140953930u, 861465670u,
4109 3277735313u, 2681724312u,
4110 2598464059u, 797982799u,
4111 890626835u, 800175912u,
4112 2603993599u, 921001710u,
4113 1410420968u, 2134990486u,
4114 3283896453u, 1867689945u,
4115 2914424215u, 2244477846u,
4116 255297188u, 2992121793u,
4117 1110588164u, 4186314283u,
4118 161451183u, 3943596029u,
4119 4019337850u, 452431531u,
4120 283198166u, 2741341286u,
4121 3379021470u, 2557197665u,
4122 299850021u, 2532580744u,
4123 452473466u, 1706958772u,
4124 1298374911u, 3099673830u,
4125 2199864459u, 3696623795u,
4126 236935126u, 2976578695u,
4127 4055299123u, 3281581178u,
4128 1053458494u, 1882212500u,
4129 2305012065u, 2169731866u,
4130 3456121707u, 275903667u,
4131 458884671u, 3033004529u,
4132 3058973506u, 2379411653u,
4133 1898235244u, 1402319660u,
4134 2700149065u, 2699376854u,
4135 147814787u, 720739346u,
4136 2433714046u, 4222949502u,
4137 4220361840u, 1712034059u,
4138 3425469811u, 3690733394u,
4139 4148372108u, 1330324210u,
4140 594028478u, 2921867846u,
4141 1635026870u, 192883107u,
4142 780716741u, 1728752234u,
4143 3280331829u, 326029180u,
4144 3969463346u, 1436364519u,
4145 393215742u, 3349570000u,
4146 3824583307u, 1612122221u,
4147 2859809759u, 3808705738u,
4148 1379537552u, 1646032583u,
4149 2233466664u, 1432476832u,
4150 4023053163u, 2650381482u,
4151 2052294713u, 3552092450u,
4152 1628777059u, 1499109081u,
4153 3476440786u, 3829307897u,
4154 2960536756u, 1554038301u,
4155 1145519619u, 3190844552u,
4156 2902102606u, 3600725550u,
4157 237495366u, 540224401u,
4158 65721842u, 489963606u,
4159 1448662590u, 397635823u,
4160 1596489240u, 1562872448u,
4161 1790705123u, 2128624475u,
4162 180854224u, 2604346966u,
4163 1435705557u, 1262831810u,
4164 155445229u, 1672724608u,
4165 1669465176u, 1341975128u,
4166 663607706u, 2077310004u,
4167 3610042449u, 1911523866u,
4168 1043692997u, 1454396064u,
4169 2563776023u, 294527927u,
4170 1099072299u, 1389770549u,
4171 703505868u, 678706990u,
4172 2952353448u, 2026137563u,
4173 3603803785u, 629449419u,
4174 1933894405u, 3043213226u,
4175 226132789u, 2489287368u,
4176 1552847036u, 645684964u,
4177 3828089804u, 3632594520u,
4178 187883449u, 230403464u,
4179 3151491850u, 3272648435u,
4180 3729087873u, 1303930448u,
4181 2002861219u, 165370827u,
4182 916494250u, 1230085527u,
4183 3103338579u, 3064290191u,
4184 3807265751u, 3628174014u,
4185 231181488u, 851743255u,
4186 2295806711u, 1781190011u,
4187 2988893883u, 1554380634u,
4188 1142264800u, 3667013118u,
4189 1968445277u, 315203929u,
4190 2638023604u, 2290487377u,
4191 732137533u, 1909203251u,
4192 440398219u, 1891630171u,
4193 1380301172u, 1498556724u,
4194 4072067757u, 4165088768u,
4195 4204318635u, 441430649u,
4196 3931792696u, 197618179u,
4197 956300927u, 914413116u,
4198 3010839769u, 2837339569u,
4199 2148126371u, 1913303225u,
4200 3074915312u, 3117299654u,
4201 4139181436u, 2993479124u,
4202 3178848746u, 1357272220u,
4203 1438494951u, 507436733u,
4204 667183474u, 2084369203u,
4205 3854939912u, 1413396341u,
4206 126024219u, 146044391u,
4207 1016656857u, 3022024459u,
4208 3254014218u, 429095991u,
4209 165589978u, 1578546616u,
4210 985653208u, 1718653828u,
4211 623071693u, 366414107u,
4212 249776086u, 1207522198u,
4213 3047342438u, 2991127487u,
4214 3120876698u, 1684583131u,
4215 46987739u, 1157614300u,
4216 863214540u, 1087193030u,
4217 199124911u, 520792961u,
4218 3614377032u, 586863115u,
4219 3331828431u, 1013201099u,
4220 1716848157u, 4033596884u,
4221 1164298657u, 4140791139u,
4222 1146169032u, 1434258493u,
4223 3824360466u, 3242407770u,
4224 3725511003u, 232064808u,
4225 872586426u, 762243036u,
4226 2736953692u, 816692935u,
4227 512845449u, 3748861010u,
4228 2266795890u, 3781899767u,
4229 4290630595u, 517646945u,
4230 22638523u, 648000590u,
4231 959214578u, 558910384u,
4232 1283799121u, 3047062993u,
4233 1024246061u, 4027776454u,
4234 3544509313u, 622325861u,
4235 834785312u, 382936554u,
4236 411505255u, 1973395102u,
4237 1825135056u, 2725923798u,
4238 580988377u, 2826990641u,
4239 3474970689u, 1029055034u,
4240 812546227u, 2506885666u,
4241 2584372201u, 1758123094u,
4242 589567754u, 325737734u,
4243 345313518u, 2022370576u,
4244 3886113119u, 3338548567u,
4245 257578986u, 3698087965u,
4246 1776047957u, 1771384107u,
4247 3604937815u, 3198590202u,
4248 2305332220u, 191910725u,
4249 4232136669u, 427759438u,
4250 4244322689u, 542201663u,
4251 3315355162u, 2135941665u,
4252 556609672u, 45845311u,
4253 1175961330u, 3948351189u,
4254 23075771u, 3252374102u,
4255 1634635545u, 4151937410u,
4256 713127376u, 1467786451u,
4257 663013031u, 3444053918u,
4258 2638154051u, 810082938u,
4259 3077742128u, 1062268187u,
4260 2115441882u, 4081398201u,
4261 3735739145u, 2794294783u,
4262 2335576331u, 2560479831u,
4263 1379288194u, 4225182569u,
4264 2442302747u, 3948961926u,
4265 3958366652u, 3067277639u,
4266 3667516477u, 1709989541u,
4267 1516711748u, 2339636583u,
4268 4188504038u, 59581167u,
4269 2725013602u, 3639843023u,
4270 2658147000u, 2643979752u,
4271 3758739543u, 4189944477u,
4272 2470483982u, 877580602u,
4273 2995362413u, 118817200u,
4274 3252925478u, 2062343506u,
4275 3981838403u, 3762572073u,
4276 1231633714u, 4168280671u,
4277 2931588131u, 3284356565u,
4278 1129162571u, 732225574u,
4279 4173605289u, 1407328702u,
4280 1677744031u, 3532596884u,
4281 3232041815u, 1652884780u,
4282 2256541290u, 3459463480u,
4283 3740979556u, 259034107u,
4284 2227121257u, 1426140634u,
4285 3606709555u, 3424793077u,
4286 315836068u, 3200749877u,
4287 1386256573u, 24035717u,
4288 2982018998u, 1811050648u,
4289 234531934u, 1115203611u,
4290 1598686658u, 3146815575u,
4291 1603559457u, 323296368u,
4292 2632963283u, 1778459926u,
4293 739944537u, 579625482u,
4294 3486330348u, 492621815u,
4295 1231665285u, 2457048126u,
4296 3903349120u, 389846205u,
4297 3355404249u, 3275550588u,
4298 1052645068u, 862072556u,
4299 2834153464u, 1481069623u,
4300 2657392572u, 4279236653u,
4301 1688445808u, 701920051u,
4302 3740748788u, 3388062747u,
4303 1873358321u, 2152785640u,
4304 883382081u, 1005815394u,
4305 1020177209u, 734239551u,
4306 2371453141u, 100326520u,
4307 3488500412u, 1279682138u,
4308 2610427744u, 49703572u,
4309 3026361211u, 605900428u,
4310 302392721u, 2509302188u,
4311 1416453607u, 2815915291u,
4312 1862819968u, 519710058u,
4313 2450888314u, 4017598378u,
4314 937074653u, 3035635454u,
4315 1590230729u, 3268013438u,
4316 2710029305u, 12886044u,
4317 3711259084u, 2627383582u,
4318 3895772404u, 648534979u,
4319 260307902u, 855990313u,
4320 3669691805u, 263366740u,
4321 2938543471u, 414331688u,
4322 3080542944u, 3405007814u,
4323 3565059103u, 1190977418u,
4324 390836981u, 1606450012u,
4325 2649808239u, 2514169310u,
4326 2747519432u, 4129538640u,
4327 1721522849u, 492099164u,
4328 792990594u, 3625507637u,
4329 2271095827u, 2993032712u,
4330 2302363854u, 4013112951u,
4331 1111617969u, 2183845740u,
4332 795918276u, 1116991810u,
4333 3110898804u, 3963062126u,
4334 2737064702u, 462795667u,
4335 937372240u, 1343017609u,
4336 1091041189u, 2790555455u,
4337 277024217u, 25485284u,
4338 1166522068u, 1623631848u,
4339 241727183u, 2836158787u,
4340 3112996740u, 573836428u,
4341 2721658101u, 1937681565u,
4342 4175169209u, 3190765433u,
4343 1970000788u, 1668258120u,
4344 114616703u, 954762543u,
4345 199237753u, 4094644498u,
4346 2522281978u, 732086117u,
4347 1756889687u, 2936126607u,
4348 2437031370u, 4103143808u,
4349 3883389541u, 3171090854u,
4350 2483004780u, 1927385370u,
4351 2360538162u, 2740855009u,
4352 4241185118u, 1492209542u,
4353 1672737098u, 2148675559u,
4354 1789864670u, 2434313103u,
4355 2319172611u, 2760941207u,
4356 2636210123u, 1338083267u,
4357 1128080590u, 822806371u,
4358 1199583556u, 314727461u,
4359 1335160250u, 2084630531u,
4360 1156261526u, 316766066u,
4361 112090465u, 3129033323u,
4362 2746885618u, 636616055u,
4363 2582210744u, 1721064910u,
4364 3468394263u, 470463518u,
4365 2076016059u, 408721884u,
4366 2121041886u, 378460278u,
4367 1915948002u, 357324860u,
4368 2301682622u, 2691859523u,
4369 1869756364u, 2429314418u,
4370 2193146527u, 1185564327u,
4371 2614088922u, 1975527044u,
4372 919067651u, 2855948894u,
4373 3662539576u, 1943802836u,
4374 3529473373u, 1490330107u,
4375 366036094u, 3384241033u,
4376 4276268604u, 448403661u,
4377 4271796078u, 1910401882u,
4378 3077107698u, 299427366u,
4379 2035665349u, 3201262636u,
4380 3738454258u, 2554452696u,
4381 3588997135u, 3363895827u,
4382 1267505995u, 1852004679u,
4383 2237827073u, 2803250686u,
4384 3468044908u, 2143572850u,
4385 1728158656u, 1022551180u,
4386 1996680960u, 839529273u,
4387 2400647871u, 2201096054u,
4388 3606433628u, 2597259793u,
4389 3544595875u, 3909443124u,
4390 819278607u, 3447346709u,
4391 806136613u, 2711436388u,
4392 3656063205u, 837475154u,
4393 694525336u, 4070212073u,
4394 4011303412u, 1068395209u,
4395 438095290u, 484603494u,
4396 2673730227u, 737767009u,
4397 642310823u, 3914002299u,
4398 308425103u, 268427550u,
4399 1334387085u, 4069797497u,
4400 4280783219u, 2914011058u,
4401 4243643405u, 2849988118u,
4402 2504230175u, 1817156623u,
4403 2804200483u, 3406991497u,
4404 2948254999u, 2102063419u,
4405 1071272117u, 514889942u,
4406 571972433u, 1246595599u,
4407 1735616066u, 1539151988u,
4408 1230831543u, 277987182u,
4409 4269526481u, 991511607u,
4410 95237878u, 2005032160u,
4411 1291113144u, 626619670u,
4412 3560835907u, 164940926u,
4413 1433635018u, 116647396u,
4414 3039097112u, 2868163232u,
4415 1141645918u, 1764165478u,
4416 881378302u, 2159170082u,
4417 2953647681u, 1011320066u,
4418 184856151u, 1723308975u,
4419 336034862u, 2017579106u,
4420 1476681709u, 147523618u,
4421 3896252223u, 2264728166u,
4422 944743644u, 1694443528u,
4423 2690700128u, 1947321519u,
4424 735478508u, 4058183171u,
4425 260177668u, 505662155u,
4426 2391691262u, 1920739747u,
4427 3216960415u, 1898176786u,
4428 3722741628u, 1511077569u,
4429 449636564u, 983350414u,
4430 2580237367u, 2055059789u,
4431 1103819072u, 2089123665u,
4432 3873755579u, 2718467458u,
4433 3124338704u, 3204250304u,
4434 2475035432u, 1120017626u,
4435 3873758287u, 1982999824u,
4436 2950794582u, 780634378u,
4437 2842141483u, 4029205195u,
4438 1656892865u, 3330993377u,
4439 80890710u, 1953796601u,
4440 3873078673u, 136118734u,
4441 2317676604u, 4199091610u,
4442 1864448181u, 3063437608u,
4443 1699452298u, 1403506686u,
4444 1513069466u, 2348491299u,
4445 4273657745u, 4055855649u,
4446 1805475756u, 2562064338u,
4447 973124563u, 4197091358u,
4448 172861513u, 2858726767u,
4449 4271866024u, 3071338162u,
4450 3590386266u, 2328277259u,
4451 1096050703u, 1189614342u,
4452 459509140u, 771592405u,
4453 817999971u, 3740825152u,
4454 520400189u, 1941874618u,
4455 185232757u, 4032960199u,
4456 3928245258u, 3527721294u,
4457 1301118856u, 752188080u,
4458 3512945009u, 308584855u,
4459 2105373972u, 752872278u,
4460 3823368815u, 3760952096u,
4461 4250142168u, 2565680167u,
4462 3646354146u, 1259957455u,
4463 1085857127u, 3471066607u,
4464 38924274u, 3770488806u,
4465 1083869477u, 3312508103u,
4466 71956383u, 3738784936u,
4467 3099963860u, 1255084262u,
4468 4286969992u, 3621849251u,
4469 1190908967u, 1831557743u,
4470 2363435042u, 54945052u,
4471 4059585566u, 4023974274u,
4472 1788578453u, 3442180039u,
4473 2534883189u, 2432427547u,
4474 3909757989u, 731996369u,
4475 4168347425u, 1356028512u,
4476 2741583197u, 1280920000u,
4477 312887059u, 3259015297u,
4478 3946278527u, 4135481831u,
4479 1281043691u, 1121403845u,
4480 3312292477u, 1819941269u,
4481 1741932545u, 3293015483u,
4482 2127558730u, 713121337u,
4483 2635469238u, 486003418u,
4484 4015067527u, 2976737859u,
4485 2108187161u, 927011680u,
4486 1970188338u, 4177613234u,
4487 1799789551u, 2118505126u,
4488 4134691985u, 1958963937u,
4489 1929210029u, 2555835851u,
4490 2768832862u, 910892050u,
4491 2567532373u, 4075249328u,
4492 86689814u, 3726640307u,
4493 1392137718u, 1240000030u,
4494 4104757832u, 3026358429u,
4495 313797689u, 1435798509u,
4496 3101500919u, 1241665335u,
4497 3573008472u, 3615577014u,
4498 3767659003u, 3134294021u,
4499 4063565523u, 2296824134u,
4500 1541946015u, 3087190425u,
4501 2693152531u, 2199672572u,
4502 2123763822u, 1034244398u,
4503 857839960u, 2515339233u,
4504 2228007483u, 1628096047u,
4505 2116502287u, 2502657424u,
4506 2809830736u, 460237542u,
4507 450205998u, 3646921704u,
4508 3818199357u, 1808504491u,
4509 1950698961u, 2069753399u,
4510 3657033172u, 3734547671u,
4511 4067859590u, 3292597295u,
4512 1106466069u, 356742959u,
4513 2469567432u, 3495418823u,
4514 183440071u, 3248055817u,
4515 3662626864u, 1750561299u,
4516 3926138664u, 4088592524u,
4517 567122118u, 3810297651u,
4518 992181339u, 3384018814u,
4519 3272124369u, 3177596743u,
4520 320086295u, 2316548367u,
4521 100741310u, 451656820u,
4522 4086604273u, 3759628395u,
4523 2553391092u, 1745659881u,
4524 3650357479u, 2390172694u,
4525 330172533u, 767377322u,
4526 526742034u, 4102497288u,
4527 2088767754u, 164402616u,
4528 2482632320u, 2352347393u,
4529 1873658044u, 3861555476u,
4530 2751052984u, 1767810825u,
4531 20037241u, 545143220u,
4532 2594532522u, 472304191u,
4533 3441135892u, 3323383489u,
4534 258785117u, 2977745165u,
4535 2781737565u, 2963590112u,
4536 2756998822u, 207428029u,
4537 2581558559u, 3824717027u,
4538 1258619503u, 3472047571u,
4539 2648427775u, 2360400900u,
4540 2393763818u, 2332399088u,
4541 3932701729u, 884421165u,
4542 1396468647u, 1377764574u,
4543 4061795938u, 1559119087u,
4544 3343596838u, 3604258095u,
4545 1435134775u, 1099809675u,
4546 908163739u, 1418405656u,
4547 368446627u, 3741651161u,
4548 3374512975u, 3542220540u,
4549 3244772570u, 200009340u,
4550 3198975081u, 2521038253u,
4551 4081637863u, 337070226u,
4552 3235259030u, 3897262827u,
4553 736956644u, 641040550u,
4554 644850146u, 1306761320u,
4555 4219448634u, 193750500u,
4556 3293278106u, 1383997679u,
4557 1242645122u, 4109252858u,
4558 450747727u, 3716617561u,
4559 362725793u, 2252520167u,
4560 3377483696u, 1788337208u,
4561 8130777u, 3226734120u,
4562 759239140u, 1012411364u,
4563 1658628529u, 2911512007u,
4564 1002580201u, 1681898320u,
4565 3039016929u, 4294520281u,
4566 367022558u, 3071359622u,
4567 3205848570u, 152989999u,
4568 3839042136u, 2357687350u,
4569 4273132307u, 3898950547u,
4570 1176841812u, 1314157485u,
4571 75443951u, 1027027239u,
4572 1858986613u, 2040551642u,
4573 36574105u, 2603059541u,
4574 3456147251u, 2137668425u,
4575 4077477194u, 3565689036u,
4576 491832241u, 363703593u,
4577 2579177168u, 3589545214u,
4578 265993036u, 1864569342u,
4579 4149035573u, 3189253455u,
4580 1072259310u, 3153745937u,
4581 923017956u, 490608221u,
4582 855846773u, 845706553u,
4583 1018226240u, 1604548872u,
4584 3833372385u, 3287246572u,
4585 2757959551u, 2452872151u,
4586 1553870564u, 1713154780u,
4587 2649450292u, 500120236u,
4588 84251717u, 661869670u,
4589 1444911517u, 2489716881u,
4590 2810524030u, 1561519055u,
4591 3884088359u, 2509890699u,
4592 4247155916u, 1005636939u,
4593 3224066062u, 2774151984u,
4594 2035978240u, 2514910366u,
4595 1478837908u, 3144450144u,
4596 2107011431u, 96459446u,
4597 3587732908u, 2389230590u,
4598 3287635953u, 250533792u,
4599 1235983679u, 4237425634u,
4600 3704645833u, 3882376657u,
4601 2976369049u, 1187061987u,
4602 276949224u, 4100839753u,
4603 1698347543u, 1629662314u,
4604 1556151829u, 3784939568u,
4605 427484362u, 4246879223u,
4606 3155311770u, 4285163791u,
4607 1693376813u, 124492786u,
4608 1858777639u, 3476334357u,
4609 1941442701u, 1121980173u,
4610 3485932087u, 820852908u,
4611 358032121u, 2511026735u,
4612 1873607283u, 2556067450u,
4613 2248275536u, 1528632094u,
4614 1535473864u, 556796152u,
4615 1499201704u, 1472623890u,
4616 1526518503u, 3692729434u,
4617 1476438092u, 2913077464u,
4618 335109599u, 2167614601u,
4619 4121131078u, 3158127917u,
4620 3051522276u, 4046477658u,
4621 2857717851u, 1863977403u,
4622 1341023343u, 692059110u,
4623 1802040304u, 990407433u,
4624 3285847572u, 319814144u,
4625 561105582u, 1540183799u,
4626 4052924496u, 2926590471u,
4627 2244539806u, 439121871u,
4628 3317903224u, 3178387550u,
4629 4265214507u, 82077489u,
4630 1978918971u, 4279668976u,
4631 128732476u, 2853224222u,
4632 464407878u, 4190838199u,
4633 997819001u, 3250520802u,
4634 2330081301u, 4095846095u,
4635 733509243u, 1583801700u,
4636 722314527u, 3552883023u,
4637 1403784280u, 432327540u,
4638 1877837196u, 3912423882u,
4639 505219998u, 696031431u,
4640 908238873u, 4189387259u,
4641 8759461u, 2540185277u,
4642 3385159748u, 381355877u,
4643 2519951681u, 1679786240u,
4644 2019419351u, 4051584612u,
4645 1933923923u, 3768201861u,
4646 1670133081u, 3454981037u,
4647 700836153u, 1675560450u,
4648 371560700u, 338262316u,
4649 847351840u, 2222395828u,
4650 3130433948u, 405251683u,
4651 3037574880u, 184098830u,
4652 453340528u, 1385561439u,
4653 2224044848u, 4071581802u,
4654 1431235296u, 5570097u,
4655 570114376u, 2287305551u,
4656 2272418128u, 803575837u,
4657 3943113491u, 414959787u,
4658 708083137u, 2452657767u,
4659 4019147902u, 3841480082u,
4660 3791794715u, 2965956183u,
4661 2763690963u, 2350937598u,
4662 3424361375u, 779434428u,
4663 1274947212u, 686105485u,
4664 3426668051u, 3692865672u,
4665 3057021940u, 2285701422u,
4666 349809124u, 1379278508u,
4667 3623750518u, 215970497u,
4668 1783152480u, 823305654u,
4669 216118434u, 1787189830u,
4670 3692048450u, 2272612521u,
4671 3032187389u, 4159715581u,
4672 1388133148u, 1611772864u,
4673 2544383526u, 552925303u,
4674 3420960112u, 3198900547u,
4675 3503230228u, 2603352423u,
4676 2318375898u, 4064071435u,
4677 3006227299u, 4194096960u,
4678 1283392422u, 1510460996u,
4679 174272138u, 3671038966u,
4680 1775955687u, 1719108984u,
4681 1763892006u, 1385029063u,
4682 4083790740u, 406757708u,
4683 684087286u, 531310503u,
4684 3329923157u, 3492083607u,
4685 1059031410u, 3037314475u,
4686 3105682208u, 3382290593u,
4687 2292208503u, 426380557u,
4688 97373678u, 3842309471u,
4689 777173623u, 3241407531u,
4690 303065016u, 1477104583u,
4691 4234905200u, 2512514774u,
4692 2649684057u, 1397502982u,
4693 1802596032u, 3973022223u,
4694 2543566442u, 3139578968u,
4695 3193669211u, 811750340u,
4696 4013496209u, 567361887u,
4697 4169410406u, 3622282782u,
4698 3403136990u, 2540585554u,
4699 895210040u, 3862229802u,
4700 1145435213u, 4146963980u,
4701 784952939u, 943914610u,
4702 573034522u, 464420660u,
4703 2356867109u, 3054347639u,
4704 3985088434u, 1911188923u,
4705 583391304u, 176468511u,
4706 2990150068u, 2338031599u,
4707 519948041u, 3181425568u,
4708 496106033u, 4110294665u,
4709 2736756930u, 1196757691u,
4710 1089679033u, 240953857u,
4711 3399092928u, 4040779538u,
4712 2843673626u, 240495962u,
4713 3017658263u, 3828377737u,
4714 4243717901u, 2448373688u,
4715 2759616657u, 2246245780u,
4716 308018483u, 4262383425u,
4717 2731780771u, 328023017u,
4718 2884443148u, 841480070u,
4719 3188015819u, 4051263539u,
4720 2298178908u, 2944209234u,
4721 1372958390u, 4164532914u,
4722 4074952232u, 1683612329u,
4723 2155036654u, 1872815858u,
4724 2041174279u, 2368092311u,
4725 206775997u, 2283918569u,
4726 645945606u, 115406202u,
4727 4206471368u, 3923500892u,
4728 2217060665u, 350160869u,
4729 706531239u, 2824302286u,
4730 509981657u, 1469342315u,
4731 140980u, 1891558063u,
4732 164887091u, 3094962711u,
4733 3437115622u, 13327420u,
4734 422986366u, 330624974u,
4735 3630863408u, 2425505046u,
4736 824008515u, 3543885677u,
4737 918718096u, 376390582u,
4738 3224043675u, 3724791476u,
4739 1837192976u, 2968738516u,
4740 3424344721u, 3187805406u,
4741 1550978788u, 1743089918u,
4742 4251270061u, 645016762u,
4743 3855037968u, 1928519266u,
4744 1373803416u, 2289007286u,
4745 1889218686u, 1610271373u,
4746 3059200728u, 2108753646u,
4747 582042641u, 812347242u,
4748 3188172418u, 191994904u,
4749 1343511943u, 2247006571u,
4750 463291708u, 2697254095u,
4751 1534175504u, 1106275740u,
4752 622521957u, 917121602u,
4753 4095777215u, 3955972648u,
4754 3852234638u, 2845309942u,
4755 3299763344u, 2864033668u,
4756 2554947496u, 799569078u,
4757 2551629074u, 1102873346u,
4758 2661022773u, 2006922227u,
4759 2900438444u, 1448194126u,
4760 1321567432u, 1983773590u,
4761 1237256330u, 3449066284u,
4762 1691553115u, 3274671549u,
4763 4271625619u, 2741371614u,
4764 3285899651u, 786322314u,
4765 1586632825u, 564385522u,
4766 2530557509u, 2974240289u,
4767 1244759631u, 3263135197u,
4768 3592389776u, 3570296884u,
4769 2749873561u, 521432811u,
4770 987586766u, 3206261120u,
4771 1327840078u, 4078716491u,
4772 1753812954u, 976892272u,
4773 1827135136u, 1781944746u,
4774 1328622957u, 1015377974u,
4775 3439601008u, 2209584557u,
4776 2482286699u, 1109175923u,
4777 874877499u, 2036083451u,
4778 483570344u, 1091877599u,
4779 4190721328u, 1129462471u,
4780 640035849u, 1867372700u,
4781 920761165u, 3273688770u,
4782 1623777358u, 3389003793u,
4783 3241132743u, 2734783008u,
4784 696674661u, 2502161880u,
4785 1646071378u, 1164309901u,
4786 350411888u, 1978005963u,
4787 2253937037u, 7371540u,
4788 989577914u, 3626554867u,
4789 3214796883u, 531343826u,
4790 398899695u, 1145247203u,
4791 1516846461u, 3656006011u,
4792 529303412u, 3318455811u,
4793 3062828129u, 1696355359u,
4794 3698796465u, 3155218919u,
4795 1457595996u, 3191404246u,
4796 1395609912u, 2917345728u,
4797 1237411891u, 1854985978u,
4798 1091884675u, 3504488111u,
4799 3109924189u, 1628881950u,
4800 3939149151u, 878608872u,
4801 778235395u, 1052990614u,
4802 903730231u, 2069566979u,
4803 2437686324u, 3163786257u,
4804 2257884264u, 2123173186u,
4805 939764916u, 2933010098u,
4806 1235300371u, 1256485167u,
4807 1950274665u, 2180372319u,
4808 2648400302u, 122035049u,
4809 1883344352u, 2083771672u,
4810 3712110541u, 321199441u,
4811 1896357377u, 508560958u,
4812 3066325351u, 2770847216u,
4813 3177982504u, 296902736u,
4814 1486926688u, 456842861u,
4815 601221482u, 3992583643u,
4816 2794121515u, 1533934172u,
4817 1706465470u, 4281971893u,
4818 2557027816u, 900741486u,
4819 227175484u, 550595824u,
4820 690918144u, 2825943628u,
4821 90375300u, 300318232u,
4822 1985329734u, 1440763373u,
4823 3670603707u, 2533900859u,
4824 3253901179u, 542270815u,
4825 3677388841u, 307706478u,
4826 2570910669u, 3320103693u,
4827 1273768482u, 1216399252u,
4828 1652924805u, 1043647584u,
4829 1120323676u, 639941430u,
4830 325675502u, 3652676161u,
4831 4241680335u, 1545838362u,
4832 1991398008u, 4100211814u,
4833 1097584090u, 3262252593u,
4834 2254324292u, 1765019121u,
4835 4060211241u, 2315856188u,
4836 3704419305u, 411263051u,
4837 238929055u, 3540688404u,
4838 3094544537u, 3250435765u,
4839 3460621305u, 1967599860u,
4840 2016157366u, 847389916u,
4841 1659615591u, 4020453639u,
4842 901109753u, 2682611693u,
4843 1661364280u, 177155177u,
4844 3210561911u, 3802058181u,
4845 797089608u, 3286110054u,
4846 2110358240u, 1353279028u,
4847 2479975820u, 471725410u,
4848 2219863904u, 3623364733u,
4849 3167128228u, 1052188336u,
4850 3656587111u, 721788662u,
4851 3061255808u, 1615375832u,
4852 924941453u, 2547780700u,
4853 3328169224u, 1310964134u,
4854 2701956286u, 4145497671u,
4855 1421461094u, 1221397398u,
4856 1589183618u, 1492533854u,
4857 449740816u, 2686506989u,
4858 3035198924u, 1682886232u,
4859 2529760244u, 3342031659u,
4860 1235084019u, 2151665147u,
4861 2315686577u, 3282027660u,
4862 1140138691u, 2754346599u,
4863 2091754612u, 1178454681u,
4864 4226896579u, 2942520471u,
4865 2122168506u, 3751680858u,
4866 3213794286u, 2601416506u,
4867 4142747914u, 3951404257u,
4868 4243249649u, 748595836u,
4869 4004834921u, 238887261u,
4870 1927321047u, 2217148444u,
4871 205977665u, 1885975275u,
4872 186020771u, 2367569534u,
4873 2941662631u, 2608559272u,
4874 3342096731u, 741809437u,
4875 1962659444u, 3539886328u,
4876 3036596491u, 2282550094u,
4877 2366462727u, 2748286642u,
4878 2144472852u, 1390394371u,
4879 1257385924u, 2205425874u,
4880 2119055686u, 46865323u,
4881 3597555910u, 3188438773u,
4882 2372320753u, 3641116924u,
4883 3116286108u, 2680722658u,
4884 3371014971u, 2058751609u,
4885 2966943726u, 2345078707u,
4886 2330535244u, 4013841927u,
4887 1169588594u, 857915866u,
4888 1875260989u, 3175831309u,
4889 3193475664u, 1955181430u,
4890 923161569u, 4068653043u,
4891 776445899u, 954196929u,
4892 61509556u, 4248237857u,
4893 3808667664u, 581227317u,
4894 2893240187u, 4159497403u,
4895 4212264930u, 3973886195u,
4896 2077539039u, 851579036u,
4897 2957587591u, 772351886u,
4898 1173659554u, 946748363u,
4899 2794103714u, 2094375930u,
4900 4234750213u, 3671645488u,
4901 2614250782u, 2620465358u,
4902 3122317317u, 2365436865u,
4903 3393973390u, 523513960u,
4904 3645735309u, 2766686992u,
4905 2023960931u, 2312244996u,
4906 1875932218u, 3253711056u,
4907 3622416881u, 3274929205u,
4908 612094988u, 1555465129u,
4909 2114270406u, 3553762793u,
4910 1832633644u, 1087551556u,
4911 3306195841u, 1702313921u,
4912 3675066046u, 1735998785u,
4913 1690923980u, 1482649756u,
4914 1171351291u, 2043136409u,
4915 1962596992u, 461214626u,
4916 3278253346u, 1392428048u,
4917 3744621107u, 1028502697u,
4918 3991171462u, 1014064003u,
4919 3642345425u, 3186995039u,
4920 6114625u, 3359104346u,
4921 414856965u, 2814387514u,
4922 3583605071u, 2497896367u,
4923 1024572712u, 1927582962u,
4924 2892797583u, 845302635u,
4925 328548052u, 1523379748u,
4926 3392622118u, 1347167673u,
4927 1012316581u, 37767602u,
4928 2647726017u, 1070326065u,
4929 2075035198u, 4202817168u,
4930 2502924707u, 2612406822u,
4931 2187115553u, 1180137213u,
4932 701024148u, 1481965992u,
4933 3223787553u, 2083541843u,
4934 203230202u, 3876887380u,
4935 1334816273u, 2870251538u,
4936 2186205850u, 3985213979u,
4937 333533378u, 806507642u,
4938 1010064531u, 713520765u,
4939 3084131515u, 2637421459u,
4940 1703168933u, 1517562266u,
4941 4089081247u, 3231042924u,
4942 3079916123u, 3154574447u,
4943 2253948262u, 1725190035u,
4944 2452539325u, 1343734533u,
4945 213706059u, 2519409656u,
4946 108055211u, 2916327746u,
4947 587001593u, 1917607088u,
4948 4202913084u, 926304016u,
4949 469255411u, 4042080256u,
4950 3498936874u, 246692543u,
4951 495780578u, 438717281u,
4952 2259272650u, 4011324645u,
4953 2836854664u, 2317249321u,
4954 946828752u, 1280403658u,
4955 1905648354u, 2034241661u,
4956 774652981u, 1285694082u,
4957 2200307766u, 2158671727u,
4958 1135162148u, 232040752u,
4959 397012087u, 1717527689u,
4960 1720414106u, 918797022u,
4961 2580119304u, 3568069742u,
4962 2904461070u, 3893453420u,
4963 973817938u, 667499332u,
4964 3785870412u, 2088861715u,
4965 1565179401u, 600903026u,
4966 591806775u, 3512242245u,
4967 997964515u, 2339605347u,
4968 1134342772u, 3234226304u,
4969 4084179455u, 302315791u,
4970 2445626811u, 2590372496u,
4971 345572299u, 2274770442u,
4972 3600587867u, 3706939009u,
4973 1430507980u, 2656330434u,
4974 1079209397u, 2122849632u,
4975 1423705223u, 3826321888u,
4976 3683385276u, 1057038163u,
4977 1242840526u, 3987000643u,
4978 2398253089u, 1538190921u,
4979 1295898647u, 3570196893u,
4980 3065138774u, 3111336863u,
4981 2524949549u, 4203895425u,
4982 3025864372u, 968800353u,
4983 1023721001u, 3763083325u,
4984 526350786u, 635552097u,
4985 2308118370u, 2166472723u,
4986 2196937373u, 2643841788u,
4987 3040011470u, 4010301879u,
4988 2782379560u, 3474682856u,
4989 4201389782u, 4223278891u,
4990 1457302296u, 2251842132u,
4991 1090062008u, 3188219189u,
4992 292733931u, 1424229089u,
4993 1590782640u, 1365212370u,
4994 3975957073u, 3982969588u,
4995 2927147928u, 1048291071u,
4996 2766680094u, 884908196u,
4997 35237839u, 2221180633u,
4998 2490333812u, 4098360768u,
4999 4029081103u, 3490831871u,
5000 2392516272u, 3455379186u,
5001 3948800722u, 335456628u,
5002 2105117968u, 4181629008u,
5003 1044201772u, 3335754111u,
5004 540133451u, 3313113759u,
5005 3786107905u, 2627207327u,
5006 3540337875u, 3473113388u,
5007 3430536378u, 2514123129u,
5008 2124531276u, 3872633376u,
5009 3272957388u, 3501994650u,
5010 2418881542u, 487365389u,
5011 3877672368u, 1512866656u,
5012 3486531087u, 2102955203u,
5013 1136054817u, 3004241477u,
5014 1549075351u, 1302002008u,
5015 3936430045u, 2258587644u,
5016 4109233936u, 3679809321u,
5017 3467083076u, 2484463221u,
5018 1594979755u, 529218470u,
5019 3527024461u, 1147434678u,
5020 106799023u, 1823161970u,
5021 1704656738u, 1675883700u,
5022 3308746763u, 1875093248u,
5023 1352868568u, 1898561846u,
5024 2508994984u, 3177750780u,
5025 4217929592u, 400784472u,
5026 80090315u, 3564414786u,
5027 3841585648u, 3379293868u,
5028 160353261u, 2413172925u,
5029 2378499279u, 673436726u,
5030 1505702418u, 1330977363u,
5031 1853298225u, 3201741245u,
5032 2135714208u, 4069554166u,
5033 3715612384u, 3692488887u,
5034 3680311316u, 4274382900u,
5035 914186796u, 2264886523u,
5036 3869634032u, 1254199592u,
5037 1131020455u, 194781179u,
5038 429923922u, 2763792336u,
5039 2052895198u, 3997373194u,
5040 3440090658u, 2165746386u,
5041 1575500242u, 3463310191u,
5042 2064974716u, 3779513671u,
5043 3106421434u, 880320527u,
5044 3281914119u, 286569042u,
5045 3909096631u, 122359727u,
5046 1429837716u, 252230074u,
5047 4111461225u, 762273136u,
5048 93658514u, 2766407143u,
5049 3623657004u, 3869801679u,
5050 3925695921u, 2390397316u,
5051 2499025338u, 2741806539u,
5052 2507199021u, 1659221866u,
5053 361292116u, 4048761557u,
5054 3797133396u, 1517903247u,
5055 3121647246u, 3884308578u,
5056 1697201500u, 1558800262u,
5057 4150812360u, 3161302278u,
5058 2610217849u, 641564641u,
5059 183814518u, 2075245419u,
5060 611996508u, 2223461433u,
5061 329123979u, 121860586u,
5062 860985829u, 1137889144u,
5063 4018949439u, 2904348960u,
5064 947795261u, 1992594155u,
5065 4255427501u, 2281583851u,
5066 2892637604u, 1478186924u,
5067 3050771207u, 2767035539u,
5068 373510582u, 1963520320u,
5069 3763848370u, 3756817798u,
5070 627269409u, 1806905031u,
5071 1814444610u, 3646665053u,
5072 1822693920u, 278515794u,
5073 584050483u, 4142579188u,
5074 2149745808u, 3193071606u,
5075 1179706341u, 2693495182u,
5076 3259749808u, 644172091u,
5077 880509048u, 3340630542u,
5078 3365160815u, 2384445068u,
5079 3053081915u, 2840648309u,
5080 1986990122u, 1084703471u,
5081 2370410550u, 1627743573u,
5082 2244943480u, 4057483496u,
5083 2611595995u, 2470013639u,
5084 4024732359u, 3987190386u,
5085 873421687u, 2447660175u,
5086 3226583022u, 767655877u,
5087 2528024413u, 1962070688u,
5088 1233635843u, 2163464207u,
5089 659054446u, 854207134u,
5090 258410943u, 4197831420u,
5091 2515400215u, 3100476924u,
5092 1961549594u, 2219491151u,
5093 3997658851u, 163850514u,
5094 470325051u, 2598261204u,
5095 3052145580u, 59836528u,
5096 1376188597u, 966733415u,
5097 850667549u, 3622479237u,
5098 1083731990u, 1525777459u,
5099 4005126532u, 1428155540u,
5100 2781907007u, 943739431u,
5101 1493961005u, 2839096988u,
5102 2000057832u, 1941829603u,
5103 1901484772u, 939810041u,
5104 3377407371u, 3090115837u,
5105 3310840540u, 2068409688u,
5106 3261383939u, 2212130277u,
5107 2594774045u, 2912652418u,
5108 4179816101u, 3534504531u,
5109 3349254805u, 2796552902u,
5110 1385421283u, 4259908631u,
5111 3714780837u, 3070073945u,
5112 3372846298u, 3835884044u,
5113 3047965714u, 3009018735u,
5114 744091167u, 1861124263u,
5115 2764936304u, 1338171648u,
5116 4222019554u, 1395200692u,
5117 1371426007u, 3338031581u,
5118 2525665319u, 4196233786u,
5119 2332743921u, 1474702008u,
5120 2274266301u, 4255175517u,
5121 2290169528u, 1793910997u,
5122 2188254024u, 354202001u,
5123 3864458796u, 4280290498u,
5124 1554419340u, 1733094688u,
5125 2010552302u, 1561807039u,
5126 664313606u, 2548990879u,
5127 1084699349u, 3233936866u,
5128 973895284u, 2386881969u,
5129 1831995860u, 2961465052u,
5130 1428704144u, 3269904970u,
5131 231648253u, 2602483763u,
5132 4125013173u, 3319187387u,
5133 3347011944u, 1892898231u,
5134 4019114049u, 868879116u,
5135 4085937045u, 2378411019u,
5136 1072588531u, 3547435717u,
5137 2208070766u, 1069899078u,
5138 3142980597u, 2337088907u,
5139 1593338562u, 919414554u,
5140 688077849u, 3625708135u,
5141 1472447348u, 1947711896u,
5142 3953006207u, 877438080u,
5143 845995820u, 3150361443u,
5144 3053496713u, 2484577841u,
5145 224271045u, 2914958001u,
5146 2682612949u, 806655563u,
5147 2436224507u, 1907729235u,
5148 2920583824u, 1251814062u,
5149 2070814520u, 4034325578u,
5150 497847539u, 2714317144u,
5151 385182008u, 640855184u,
5152 1327075087u, 1062468773u,
5153 1757405994u, 1374270191u,
5154 4263183176u, 3041193150u,
5155 1037871524u, 3633173991u,
5156 4231821821u, 2830131945u,
5157 3505072908u, 2830570613u,
5158 4195208715u, 575398021u,
5159 3992840257u, 3691788221u,
5160 1949847968u, 2999344380u,
5161 3183782163u, 3723754342u,
5162 759716128u, 3284107364u,
5163 1714496583u, 15918244u,
5164 820509475u, 2553936299u,
5165 2201876606u, 4237151697u,
5166 2605688266u, 3253705097u,
5167 1008333207u, 712158730u,
5168 1722280252u, 1933868287u,
5169 4152736859u, 2097020806u,
5170 584426382u, 2836501956u,
5171 2522777566u, 1996172430u,
5172 2122199776u, 1069285218u,
5173 1474209360u, 690831894u,
5174 107482532u, 3695525410u,
5175 670591796u, 768977505u,
5176 2412057331u, 3647886687u,
5177 3110327607u, 1072658422u,
5178 379861934u, 1557579480u,
5179 4124127129u, 2271365865u,
5180 3880613089u, 739218494u,
5181 547346027u, 388559045u,
5182 3147335977u, 176230425u,
5183 3094853730u, 2554321205u,
5184 1495176194u, 4093461535u,
5185 3521297827u, 4108148413u,
5186 1913727929u, 1177947623u,
5187 1911655402u, 1053371241u,
5188 3265708874u, 1266515850u,
5189 1045540427u, 3194420196u,
5190 3717104621u, 1144474110u,
5191 1464392345u, 52070157u,
5192 4144237690u, 3350490823u,
5193 4166253320u, 2747410691u,
5194 };
5195
5196 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)5197 bool Test(int offset, int len = 0) {
5198 #undef Check
5199 #undef IsAlive
5200
5201 #define Check(x) do { \
5202 bool ok = expected[index++] == (x); \
5203 assert(ok); \
5204 errors += !ok; \
5205 } while (0)
5206
5207 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
5208
5209 // After the following line is where the uses of "Check" and such will go.
5210 static int index = 0;
5211 if (offset == -1) { int alive = 0; { uint64_t h = farmhashna::Hash64WithSeeds(data, len++, SEED0, SEED1); IsAlive(h >> 32); IsAlive((h << 32) >> 32); } { uint64_t h = farmhashna::Hash64WithSeed(data, len++, SEED); IsAlive(h >> 32); IsAlive((h << 32) >> 32); } { uint64_t h = farmhashna::Hash64(data, len++); IsAlive(h >> 32); IsAlive((h << 32) >> 32); } len -= 3; return alive > 0; }
5212 { uint64_t h = farmhashna::Hash64WithSeeds(data + offset, len, SEED0, SEED1); Check(h >> 32); Check((h << 32) >> 32); }
5213 { uint64_t h = farmhashna::Hash64WithSeed(data + offset, len, SEED); Check(h >> 32); Check((h << 32) >> 32); }
5214 { uint64_t h = farmhashna::Hash64(data + offset, len); Check(h >> 32); Check((h << 32) >> 32); }
5215
5216 return true;
5217 #undef Check
5218 #undef IsAlive
5219 }
5220
RunTest()5221 int RunTest() {
5222 Setup();
5223 int i = 0;
5224 cout << "Running farmhashnaTest";
5225 if (!Test(-1)) {
5226 cout << "... Unavailable\n";
5227 return NoteErrors();
5228 }
5229 // Good. The function is attempting to hash, so run the full test.
5230 int errors_prior_to_test = errors;
5231 for ( ; i < kTestSize - 1; i++) {
5232 Test(i * i, i);
5233 }
5234 for ( ; i < kDataSize; i += i / 7) {
5235 Test(0, i);
5236 }
5237 Test(0, kDataSize);
5238 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
5239 return NoteErrors();
5240 }
5241
5242 #else
5243
5244 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)5245 void Dump(int offset, int len) {
5246 { uint64_t h = farmhashna::Hash64WithSeeds(data + offset, len, SEED0, SEED1); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u," << endl; }
5247 { uint64_t h = farmhashna::Hash64WithSeed(data + offset, len, SEED); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u," << endl; }
5248 { uint64_t h = farmhashna::Hash64(data + offset, len); cout << (h >> 32) << "u, " << ((h << 32) >> 32) << "u," << endl; }
5249 }
5250
5251 #endif
5252
5253 #undef SEED
5254 #undef SEED1
5255 #undef SEED0
5256
5257 } // namespace farmhashnaTest
5258
5259 #if TESTING
5260
5261 static int farmhashnaTestResult = farmhashnaTest::RunTest();
5262
5263 #else
main(int argc,char ** argv)5264 int main(int argc, char** argv) {
5265 Setup();
5266 cout << "uint32_t expected[] = {\n";
5267 int i = 0;
5268 for ( ; i < kTestSize - 1; i++) {
5269 farmhashnaTest::Dump(i * i, i);
5270 }
5271 for ( ; i < kDataSize; i += i / 7) {
5272 farmhashnaTest::Dump(0, i);
5273 }
5274 farmhashnaTest::Dump(0, kDataSize);
5275 cout << "};\n";
5276 }
5277 #endif
5278 #ifndef FARMHASH_SELF_TEST_GUARD
5279 #define FARMHASH_SELF_TEST_GUARD
5280 #include <string.h>
5281 #include <cstdio>
5282 #include <iostream>
5283
5284 using std::cout;
5285 using std::cerr;
5286 using std::endl;
5287 using std::hex;
5288
5289 static const uint64_t kSeed0 = 1234567;
5290 static const uint64_t kSeed1 = k0;
5291 static const int kDataSize = 1 << 20;
5292 static const int kTestSize = 300;
5293 #define kSeed128 Uint128(kSeed0, kSeed1)
5294
5295 static char data[kDataSize];
5296
5297 static int completed_self_tests = 0;
5298 static int errors = 0;
5299
5300 // Initialize data to pseudorandom values.
Setup()5301 void Setup() {
5302 if (completed_self_tests == 0) {
5303 uint64_t a = 9;
5304 uint64_t b = 777;
5305 for (int i = 0; i < kDataSize; i++) {
5306 a += b;
5307 b += a;
5308 a = (a ^ (a >> 41)) * k0;
5309 b = (b ^ (b >> 41)) * k0 + i;
5310 uint8_t u = b >> 37;
5311 memcpy(data + i, &u, 1); // uint8_t -> char
5312 }
5313 }
5314 }
5315
NoteErrors()5316 int NoteErrors() {
5317 #define NUM_SELF_TESTS 6
5318 if (++completed_self_tests == NUM_SELF_TESTS)
5319 std::exit(errors > 0);
5320 return errors;
5321 }
5322
IsNonZero(T x)5323 template <typename T> inline bool IsNonZero(T x) {
5324 return x != 0;
5325 }
5326
IsNonZero(uint128_t x)5327 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
5328 return x != Uint128(0, 0);
5329 }
5330
5331 #endif // FARMHASH_SELF_TEST_GUARD
5332
5333 namespace farmhashnsTest {
5334
CreateSeed(int offset,int salt)5335 uint32_t CreateSeed(int offset, int salt) {
5336 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
5337 h = h * c1;
5338 h ^= (h >> 17);
5339 h = h * c1;
5340 h ^= (h >> 17);
5341 h = h * c1;
5342 h ^= (h >> 17);
5343 h += static_cast<uint32_t>(offset & 0xffffffff);
5344 h = h * c1;
5345 h ^= (h >> 17);
5346 h = h * c1;
5347 h ^= (h >> 17);
5348 h = h * c1;
5349 h ^= (h >> 17);
5350 return h;
5351 }
5352
5353 #undef SEED
5354 #undef SEED1
5355 #undef SEED0
5356 #define SEED CreateSeed(offset, -1)
5357 #define SEED0 CreateSeed(offset, 0)
5358 #define SEED1 CreateSeed(offset, 1)
5359
5360 #undef TESTING
5361 #define TESTING 1
5362 #if TESTING
5363 uint32_t expected[] = {
5364 2681724312u,
5365 797982799u,
5366 921001710u,
5367 2134990486u,
5368 2244477846u,
5369 2992121793u,
5370 3943596029u,
5371 452431531u,
5372 2557197665u,
5373 2532580744u,
5374 3099673830u,
5375 3696623795u,
5376 3281581178u,
5377 1882212500u,
5378 275903667u,
5379 3033004529u,
5380 1402319660u,
5381 2699376854u,
5382 4222949502u,
5383 1712034059u,
5384 1330324210u,
5385 2921867846u,
5386 1728752234u,
5387 326029180u,
5388 3349570000u,
5389 1612122221u,
5390 1646032583u,
5391 1432476832u,
5392 3552092450u,
5393 1499109081u,
5394 1554038301u,
5395 3190844552u,
5396 540224401u,
5397 489963606u,
5398 1562872448u,
5399 2128624475u,
5400 1262831810u,
5401 1672724608u,
5402 2077310004u,
5403 1911523866u,
5404 294527927u,
5405 1389770549u,
5406 2026137563u,
5407 629449419u,
5408 2489287368u,
5409 645684964u,
5410 230403464u,
5411 3272648435u,
5412 165370827u,
5413 1230085527u,
5414 3628174014u,
5415 851743255u,
5416 1554380634u,
5417 3667013118u,
5418 2290487377u,
5419 1909203251u,
5420 1498556724u,
5421 4165088768u,
5422 197618179u,
5423 914413116u,
5424 1913303225u,
5425 3117299654u,
5426 1357272220u,
5427 507436733u,
5428 1413396341u,
5429 146044391u,
5430 429095991u,
5431 1578546616u,
5432 366414107u,
5433 1207522198u,
5434 1684583131u,
5435 1157614300u,
5436 520792961u,
5437 586863115u,
5438 4033596884u,
5439 4140791139u,
5440 3242407770u,
5441 232064808u,
5442 816692935u,
5443 3748861010u,
5444 517646945u,
5445 648000590u,
5446 3047062993u,
5447 4027776454u,
5448 382936554u,
5449 1973395102u,
5450 2826990641u,
5451 1029055034u,
5452 1758123094u,
5453 325737734u,
5454 3338548567u,
5455 3698087965u,
5456 3198590202u,
5457 191910725u,
5458 542201663u,
5459 2135941665u,
5460 3948351189u,
5461 3252374102u,
5462 1467786451u,
5463 3444053918u,
5464 1062268187u,
5465 4081398201u,
5466 2560479831u,
5467 4225182569u,
5468 3067277639u,
5469 1709989541u,
5470 59581167u,
5471 3639843023u,
5472 4189944477u,
5473 877580602u,
5474 2062343506u,
5475 3762572073u,
5476 3284356565u,
5477 732225574u,
5478 3532596884u,
5479 1652884780u,
5480 259034107u,
5481 1426140634u,
5482 3200749877u,
5483 24035717u,
5484 1115203611u,
5485 3146815575u,
5486 1778459926u,
5487 579625482u,
5488 2457048126u,
5489 389846205u,
5490 862072556u,
5491 1481069623u,
5492 701920051u,
5493 3388062747u,
5494 1005815394u,
5495 734239551u,
5496 1279682138u,
5497 49703572u,
5498 2509302188u,
5499 2815915291u,
5500 4017598378u,
5501 3035635454u,
5502 12886044u,
5503 2627383582u,
5504 855990313u,
5505 263366740u,
5506 3405007814u,
5507 1190977418u,
5508 2514169310u,
5509 4129538640u,
5510 3625507637u,
5511 2993032712u,
5512 2183845740u,
5513 1116991810u,
5514 462795667u,
5515 1343017609u,
5516 25485284u,
5517 1623631848u,
5518 573836428u,
5519 1937681565u,
5520 1668258120u,
5521 954762543u,
5522 732086117u,
5523 2936126607u,
5524 3171090854u,
5525 1927385370u,
5526 1492209542u,
5527 2148675559u,
5528 2760941207u,
5529 1338083267u,
5530 314727461u,
5531 2084630531u,
5532 3129033323u,
5533 636616055u,
5534 470463518u,
5535 408721884u,
5536 357324860u,
5537 2691859523u,
5538 1185564327u,
5539 1975527044u,
5540 1943802836u,
5541 1490330107u,
5542 448403661u,
5543 1910401882u,
5544 3201262636u,
5545 2554452696u,
5546 1852004679u,
5547 2803250686u,
5548 1022551180u,
5549 839529273u,
5550 2597259793u,
5551 3909443124u,
5552 2711436388u,
5553 837475154u,
5554 1068395209u,
5555 484603494u,
5556 3914002299u,
5557 268427550u,
5558 2914011058u,
5559 2849988118u,
5560 3406991497u,
5561 2102063419u,
5562 1246595599u,
5563 1539151988u,
5564 991511607u,
5565 2005032160u,
5566 164940926u,
5567 116647396u,
5568 1764165478u,
5569 2159170082u,
5570 1723308975u,
5571 2017579106u,
5572 2264728166u,
5573 1694443528u,
5574 4058183171u,
5575 505662155u,
5576 1898176786u,
5577 1511077569u,
5578 2055059789u,
5579 2089123665u,
5580 3204250304u,
5581 1120017626u,
5582 780634378u,
5583 4029205195u,
5584 1953796601u,
5585 136118734u,
5586 3063437608u,
5587 1403506686u,
5588 4055855649u,
5589 2562064338u,
5590 2858726767u,
5591 3071338162u,
5592 1189614342u,
5593 771592405u,
5594 1941874618u,
5595 4032960199u,
5596 752188080u,
5597 308584855u,
5598 3760952096u,
5599 2565680167u,
5600 3471066607u,
5601 3770488806u,
5602 3738784936u,
5603 1255084262u,
5604 1831557743u,
5605 54945052u,
5606 3442180039u,
5607 2432427547u,
5608 1356028512u,
5609 1280920000u,
5610 4135481831u,
5611 1121403845u,
5612 3293015483u,
5613 713121337u,
5614 2976737859u,
5615 927011680u,
5616 2118505126u,
5617 1958963937u,
5618 910892050u,
5619 4075249328u,
5620 1240000030u,
5621 3026358429u,
5622 1241665335u,
5623 3615577014u,
5624 2296824134u,
5625 3087190425u,
5626 1034244398u,
5627 2515339233u,
5628 2502657424u,
5629 460237542u,
5630 1808504491u,
5631 2069753399u,
5632 3292597295u,
5633 356742959u,
5634 3248055817u,
5635 1750561299u,
5636 3810297651u,
5637 3384018814u,
5638 2316548367u,
5639 451656820u,
5640 1745659881u,
5641 2390172694u,
5642 4102497288u,
5643 164402616u,
5644 3861555476u,
5645 1767810825u,
5646 472304191u,
5647 3323383489u,
5648 2963590112u,
5649 207428029u,
5650 3472047571u,
5651 2360400900u,
5652 884421165u,
5653 1377764574u,
5654 3604258095u,
5655 1099809675u,
5656 3741651161u,
5657 3542220540u,
5658 2521038253u,
5659 337070226u,
5660 641040550u,
5661 1306761320u,
5662 1383997679u,
5663 4109252858u,
5664 2252520167u,
5665 1788337208u,
5666 1012411364u,
5667 2911512007u,
5668 4294520281u,
5669 3071359622u,
5670 2357687350u,
5671 3898950547u,
5672 1027027239u,
5673 2040551642u,
5674 2137668425u,
5675 3565689036u,
5676 3589545214u,
5677 1864569342u,
5678 3153745937u,
5679 490608221u,
5680 1604548872u,
5681 3287246572u,
5682 1713154780u,
5683 500120236u,
5684 2489716881u,
5685 1561519055u,
5686 1005636939u,
5687 2774151984u,
5688 3144450144u,
5689 96459446u,
5690 250533792u,
5691 4237425634u,
5692 1187061987u,
5693 4100839753u,
5694 3784939568u,
5695 4246879223u,
5696 124492786u,
5697 3476334357u,
5698 820852908u,
5699 2511026735u,
5700 1528632094u,
5701 556796152u,
5702 3692729434u,
5703 2913077464u,
5704 3158127917u,
5705 4046477658u,
5706 692059110u,
5707 990407433u,
5708 1540183799u,
5709 2926590471u,
5710 3178387550u,
5711 82077489u,
5712 2853224222u,
5713 4190838199u,
5714 4095846095u,
5715 1583801700u,
5716 432327540u,
5717 3912423882u,
5718 4189387259u,
5719 2540185277u,
5720 1679786240u,
5721 4051584612u,
5722 3454981037u,
5723 1675560450u,
5724 2222395828u,
5725 405251683u,
5726 1385561439u,
5727 4071581802u,
5728 2287305551u,
5729 803575837u,
5730 2452657767u,
5731 3841480082u,
5732 2350937598u,
5733 779434428u,
5734 3692865672u,
5735 2285701422u,
5736 215970497u,
5737 823305654u,
5738 2272612521u,
5739 4159715581u,
5740 552925303u,
5741 3198900547u,
5742 4064071435u,
5743 4194096960u,
5744 3671038966u,
5745 1719108984u,
5746 406757708u,
5747 531310503u,
5748 3037314475u,
5749 3382290593u,
5750 3842309471u,
5751 3241407531u,
5752 2512514774u,
5753 1397502982u,
5754 3139578968u,
5755 811750340u,
5756 3622282782u,
5757 2540585554u,
5758 4146963980u,
5759 943914610u,
5760 3054347639u,
5761 1911188923u,
5762 2338031599u,
5763 3181425568u,
5764 1196757691u,
5765 240953857u,
5766 240495962u,
5767 3828377737u,
5768 2246245780u,
5769 4262383425u,
5770 841480070u,
5771 4051263539u,
5772 4164532914u,
5773 1683612329u,
5774 2368092311u,
5775 2283918569u,
5776 3923500892u,
5777 350160869u,
5778 1469342315u,
5779 1891558063u,
5780 13327420u,
5781 330624974u,
5782 3543885677u,
5783 376390582u,
5784 2968738516u,
5785 3187805406u,
5786 645016762u,
5787 1928519266u,
5788 1610271373u,
5789 2108753646u,
5790 191994904u,
5791 2247006571u,
5792 1106275740u,
5793 917121602u,
5794 2845309942u,
5795 2864033668u,
5796 1102873346u,
5797 2006922227u,
5798 1983773590u,
5799 3449066284u,
5800 2741371614u,
5801 786322314u,
5802 2974240289u,
5803 3263135197u,
5804 521432811u,
5805 3206261120u,
5806 976892272u,
5807 1781944746u,
5808 2209584557u,
5809 1109175923u,
5810 1091877599u,
5811 1129462471u,
5812 3273688770u,
5813 3389003793u,
5814 2502161880u,
5815 1164309901u,
5816 7371540u,
5817 3626554867u,
5818 1145247203u,
5819 3656006011u,
5820 1696355359u,
5821 3155218919u,
5822 2917345728u,
5823 1854985978u,
5824 1628881950u,
5825 878608872u,
5826 2069566979u,
5827 3163786257u,
5828 2933010098u,
5829 1256485167u,
5830 122035049u,
5831 2083771672u,
5832 508560958u,
5833 2770847216u,
5834 456842861u,
5835 3992583643u,
5836 4281971893u,
5837 900741486u,
5838 2825943628u,
5839 300318232u,
5840 2533900859u,
5841 542270815u,
5842 3320103693u,
5843 1216399252u,
5844 639941430u,
5845 3652676161u,
5846 4100211814u,
5847 3262252593u,
5848 2315856188u,
5849 411263051u,
5850 3250435765u,
5851 1967599860u,
5852 4020453639u,
5853 2682611693u,
5854 3802058181u,
5855 3286110054u,
5856 471725410u,
5857 3623364733u,
5858 721788662u,
5859 1615375832u,
5860 1310964134u,
5861 4145497671u,
5862 1492533854u,
5863 2686506989u,
5864 3342031659u,
5865 2151665147u,
5866 2754346599u,
5867 1178454681u,
5868 3751680858u,
5869 2601416506u,
5870 748595836u,
5871 238887261u,
5872 1885975275u,
5873 2367569534u,
5874 741809437u,
5875 3539886328u,
5876 2748286642u,
5877 1390394371u,
5878 3005091922u,
5879 793108368u,
5880 1529669805u,
5881 2332660395u,
5882 2217730223u,
5883 2634687611u,
5884 442806463u,
5885 1968135266u,
5886 454523002u,
5887 3177866230u,
5888 2808960136u,
5889 4259114138u,
5890 4103264843u,
5891 3103714075u,
5892 2462967542u,
5893 1466891491u,
5894 477973764u,
5895 834565647u,
5896 741089037u,
5897 218837573u,
5898 1710536528u,
5899 2469088212u,
5900 1229072375u,
5901 2828341u,
5902 176923431u,
5903 985763350u,
5904 4095477420u,
5905 1984145538u,
5906 1870791084u,
5907 674956677u,
5908 1978138947u,
5909 1296493993u,
5910 1818183554u,
5911 3443333721u,
5912 2124949983u,
5913 2549590262u,
5914 2700850794u,
5915 2662736367u,
5916 739638109u,
5917 4061447096u,
5918 2960078422u,
5919 2453781158u,
5920 929570940u,
5921 3200328383u,
5922 2406328791u,
5923 1419180666u,
5924 2152455739u,
5925 2805741044u,
5926 3305999074u,
5927 3183816361u,
5928 2303165050u,
5929 4922104u,
5930 63096005u,
5931 936656347u,
5932 3104453886u,
5933 1088673880u,
5934 1113407526u,
5935 1457890086u,
5936 453478383u,
5937 1107686695u,
5938 3626027824u,
5939 1159687359u,
5940 2248467888u,
5941 2004578380u,
5942 3274954621u,
5943 1787958646u,
5944 2628726704u,
5945 1138419798u,
5946 3735442315u,
5947 692385301u,
5948 313807213u,
5949 2329068673u,
5950 59375364u,
5951 3261084359u,
5952 2088644507u,
5953 2471153194u,
5954 788336435u,
5955 4024527246u,
5956 141504460u,
5957 2307553888u,
5958 1930559950u,
5959 48975711u,
5960 2745693338u,
5961 230161982u,
5962 3429230862u,
5963 1335968626u,
5964 609591304u,
5965 57435073u,
5966 4279281136u,
5967 3152151665u,
5968 3984484924u,
5969 3459883943u,
5970 397478330u,
5971 1738762229u,
5972 3033590066u,
5973 3611539498u,
5974 1363463523u,
5975 3319364965u,
5976 2671169141u,
5977 3819548561u,
5978 1691193757u,
5979 2423834608u,
5980 2820147055u,
5981 1378120632u,
5982 1240565187u,
5983 3180720050u,
5984 680831086u,
5985 3309658414u,
5986 1986166490u,
5987 762099827u,
5988 510883662u,
5989 2047373648u,
5990 3606742294u,
5991 3894965352u,
5992 2342078853u,
5993 1091255717u,
5994 776594727u,
5995 3217317445u,
5996 1574468485u,
5997 3844504016u,
5998 2819598918u,
5999 1037401010u,
6000 2550943503u,
6001 3867184001u,
6002 1687911772u,
6003 165313836u,
6004 1679575281u,
6005 2418947263u,
6006 2038774952u,
6007 3913543652u,
6008 3209155736u,
6009 149905221u,
6010 3859604717u,
6011 713919631u,
6012 4069810796u,
6013 1882959164u,
6014 1019939034u,
6015 2379867302u,
6016 3666323035u,
6017 1157389013u,
6018 2422300650u,
6019 3366777340u,
6020 2526452062u,
6021 1313747885u,
6022 1039617868u,
6023 1620553692u,
6024 2032976978u,
6025 578789528u,
6026 1592846839u,
6027 2270630604u,
6028 897850577u,
6029 1603294178u,
6030 3105664807u,
6031 1442670138u,
6032 1728019360u,
6033 79313861u,
6034 1683031101u,
6035 1913067024u,
6036 4070719870u,
6037 708986470u,
6038 2586453359u,
6039 3993348863u,
6040 3358251279u,
6041 3003552537u,
6042 750174793u,
6043 836888956u,
6044 4190747426u,
6045 4251291318u,
6046 4145164938u,
6047 1366883260u,
6048 1912910955u,
6049 510192669u,
6050 1851315039u,
6051 3574241274u,
6052 3220062924u,
6053 2821142039u,
6054 1317082195u,
6055 2274293302u,
6056 1839219569u,
6057 126586168u,
6058 3989293643u,
6059 2680178207u,
6060 347056948u,
6061 799681430u,
6062 2864517481u,
6063 3180404853u,
6064 213140045u,
6065 1956305184u,
6066 1474675286u,
6067 3085723423u,
6068 2841859626u,
6069 308421914u,
6070 3670309263u,
6071 1765052231u,
6072 245459238u,
6073 113434331u,
6074 4079521092u,
6075 2115235526u,
6076 2943408816u,
6077 1055476938u,
6078 1506442339u,
6079 2291296392u,
6080 3267864332u,
6081 1282145528u,
6082 3700108015u,
6083 1932843667u,
6084 2677701670u,
6085 6041177u,
6086 3889648557u,
6087 1461025478u,
6088 };
6089
6090 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)6091 bool Test(int offset, int len = 0) {
6092 #undef Check
6093 #undef IsAlive
6094
6095 #define Check(x) do { \
6096 bool ok = expected[index++] == (x); \
6097 assert(ok); \
6098 errors += !ok; \
6099 } while (0)
6100
6101 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
6102
6103 // After the following line is where the uses of "Check" and such will go.
6104 static int index = 0;
6105 if (offset == -1) { int alive = 0; IsAlive(farmhashns::Hash32WithSeed(data, len++, SEED)); IsAlive(farmhashns::Hash32(data, len++)); IsAlive(farmhashns::Hash32(data, len++)); len -= 3; return alive > 0; }
6106 Check(farmhashns::Hash32WithSeed(data + offset, len, SEED));
6107 Check(farmhashns::Hash32(data + offset, len));
6108
6109 return true;
6110 #undef Check
6111 #undef IsAlive
6112 }
6113
RunTest()6114 int RunTest() {
6115 Setup();
6116 int i = 0;
6117 cout << "Running farmhashnsTest";
6118 if (!Test(-1)) {
6119 cout << "... Unavailable\n";
6120 return NoteErrors();
6121 }
6122 // Good. The function is attempting to hash, so run the full test.
6123 int errors_prior_to_test = errors;
6124 for ( ; i < kTestSize - 1; i++) {
6125 Test(i * i, i);
6126 }
6127 for ( ; i < kDataSize; i += i / 7) {
6128 Test(0, i);
6129 }
6130 Test(0, kDataSize);
6131 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
6132 return NoteErrors();
6133 }
6134
6135 #else
6136
6137 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)6138 void Dump(int offset, int len) {
6139 cout << farmhashns::Hash32WithSeed(data + offset, len, SEED) << "u," << endl;
6140 cout << farmhashns::Hash32(data + offset, len) << "u," << endl;
6141 }
6142
6143 #endif
6144
6145 #undef SEED
6146 #undef SEED1
6147 #undef SEED0
6148
6149 } // namespace farmhashnsTest
6150
6151 #if TESTING
6152
6153 static int farmhashnsTestResult = farmhashnsTest::RunTest();
6154
6155 #else
main(int argc,char ** argv)6156 int main(int argc, char** argv) {
6157 Setup();
6158 cout << "uint32_t expected[] = {\n";
6159 int i = 0;
6160 for ( ; i < kTestSize - 1; i++) {
6161 farmhashnsTest::Dump(i * i, i);
6162 }
6163 for ( ; i < kDataSize; i += i / 7) {
6164 farmhashnsTest::Dump(0, i);
6165 }
6166 farmhashnsTest::Dump(0, kDataSize);
6167 cout << "};\n";
6168 }
6169 #endif
6170 #ifndef FARMHASH_SELF_TEST_GUARD
6171 #define FARMHASH_SELF_TEST_GUARD
6172 #include <string.h>
6173 #include <cstdio>
6174 #include <iostream>
6175
6176 using std::cout;
6177 using std::cerr;
6178 using std::endl;
6179 using std::hex;
6180
6181 static const uint64_t kSeed0 = 1234567;
6182 static const uint64_t kSeed1 = k0;
6183 static const int kDataSize = 1 << 20;
6184 static const int kTestSize = 300;
6185 #define kSeed128 Uint128(kSeed0, kSeed1)
6186
6187 static char data[kDataSize];
6188
6189 static int completed_self_tests = 0;
6190 static int errors = 0;
6191
6192 // Initialize data to pseudorandom values.
Setup()6193 void Setup() {
6194 if (completed_self_tests == 0) {
6195 uint64_t a = 9;
6196 uint64_t b = 777;
6197 for (int i = 0; i < kDataSize; i++) {
6198 a += b;
6199 b += a;
6200 a = (a ^ (a >> 41)) * k0;
6201 b = (b ^ (b >> 41)) * k0 + i;
6202 uint8_t u = b >> 37;
6203 memcpy(data + i, &u, 1); // uint8_t -> char
6204 }
6205 }
6206 }
6207
NoteErrors()6208 int NoteErrors() {
6209 #define NUM_SELF_TESTS 6
6210 if (++completed_self_tests == NUM_SELF_TESTS)
6211 std::exit(errors > 0);
6212 return errors;
6213 }
6214
IsNonZero(T x)6215 template <typename T> inline bool IsNonZero(T x) {
6216 return x != 0;
6217 }
6218
IsNonZero(uint128_t x)6219 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
6220 return x != Uint128(0, 0);
6221 }
6222
6223 #endif // FARMHASH_SELF_TEST_GUARD
6224
6225 namespace farmhashsaTest {
6226
CreateSeed(int offset,int salt)6227 uint32_t CreateSeed(int offset, int salt) {
6228 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
6229 h = h * c1;
6230 h ^= (h >> 17);
6231 h = h * c1;
6232 h ^= (h >> 17);
6233 h = h * c1;
6234 h ^= (h >> 17);
6235 h += static_cast<uint32_t>(offset & 0xffffffff);
6236 h = h * c1;
6237 h ^= (h >> 17);
6238 h = h * c1;
6239 h ^= (h >> 17);
6240 h = h * c1;
6241 h ^= (h >> 17);
6242 return h;
6243 }
6244
6245 #undef SEED
6246 #undef SEED1
6247 #undef SEED0
6248 #define SEED CreateSeed(offset, -1)
6249 #define SEED0 CreateSeed(offset, 0)
6250 #define SEED1 CreateSeed(offset, 1)
6251
6252 #undef TESTING
6253 #define TESTING 1
6254 #if TESTING
6255 uint32_t expected[] = {
6256 4223616069u,
6257 3696677242u,
6258 4081014168u,
6259 2576519988u,
6260 2212771159u,
6261 1112731063u,
6262 1020067935u,
6263 3955445564u,
6264 1451961420u,
6265 653440099u,
6266 31917516u,
6267 2957164615u,
6268 2590087362u,
6269 3879448744u,
6270 176305566u,
6271 2447367541u,
6272 1359016305u,
6273 3363804638u,
6274 1117290165u,
6275 1062549743u,
6276 2437877004u,
6277 1894455839u,
6278 673206794u,
6279 3486923651u,
6280 3269862919u,
6281 2303349487u,
6282 1380660650u,
6283 595525107u,
6284 1525325287u,
6285 2025609358u,
6286 176408838u,
6287 1592885012u,
6288 864896482u,
6289 2101378090u,
6290 3489229104u,
6291 2118965695u,
6292 581644891u,
6293 2718789079u,
6294 631613207u,
6295 4228658372u,
6296 3867875546u,
6297 3531368319u,
6298 3804516756u,
6299 3317755099u,
6300 1619744564u,
6301 2884717286u,
6302 1088213445u,
6303 2667691076u,
6304 3727873235u,
6305 2330406762u,
6306 858590707u,
6307 123802208u,
6308 4150036245u,
6309 182283099u,
6310 1478882570u,
6311 3282617403u,
6312 819171187u,
6313 1172627392u,
6314 4254302102u,
6315 2957028020u,
6316 437030323u,
6317 2452147680u,
6318 2868246750u,
6319 3530169402u,
6320 3154852132u,
6321 215019192u,
6322 357580983u,
6323 1354454461u,
6324 1108813287u,
6325 2324008118u,
6326 2315997713u,
6327 4181601562u,
6328 1360882441u,
6329 92423273u,
6330 3048866755u,
6331 3369188505u,
6332 3664371439u,
6333 2920710428u,
6334 1027891570u,
6335 2653166430u,
6336 3461888315u,
6337 1475780447u,
6338 292769636u,
6339 1737473313u,
6340 4064110516u,
6341 4170160075u,
6342 762850927u,
6343 3630603695u,
6344 2803307356u,
6345 844987665u,
6346 460980967u,
6347 3005635467u,
6348 2802568977u,
6349 588668033u,
6350 2148940781u,
6351 3239099984u,
6352 1266953698u,
6353 3197808789u,
6354 3519942533u,
6355 2511995334u,
6356 2553810188u,
6357 871667697u,
6358 1358675720u,
6359 1499319171u,
6360 2044931270u,
6361 1210355103u,
6362 807152540u,
6363 3262320756u,
6364 2810214575u,
6365 1813386141u,
6366 4089465863u,
6367 903928165u,
6368 1388899322u,
6369 3209183659u,
6370 834536144u,
6371 2733354550u,
6372 2742289921u,
6373 3689042563u,
6374 2655593281u,
6375 4169686303u,
6376 415985561u,
6377 138892376u,
6378 516115393u,
6379 65683883u,
6380 4162865100u,
6381 889944635u,
6382 313566528u,
6383 3346420907u,
6384 1504303591u,
6385 2256809275u,
6386 742243229u,
6387 779775302u,
6388 3140940172u,
6389 2312556111u,
6390 2304095772u,
6391 1151741606u,
6392 2194712422u,
6393 1714084652u,
6394 3272736835u,
6395 1311540658u,
6396 191179665u,
6397 3996605106u,
6398 1657345233u,
6399 4205442903u,
6400 1553339212u,
6401 2351843044u,
6402 1647502006u,
6403 2525516233u,
6404 292202846u,
6405 1498646290u,
6406 1429323381u,
6407 974274898u,
6408 3759331561u,
6409 2881238887u,
6410 826787221u,
6411 1069622448u,
6412 221991032u,
6413 1462969082u,
6414 2799661508u,
6415 364022781u,
6416 2594244377u,
6417 797773898u,
6418 4097839290u,
6419 1529150125u,
6420 2456805570u,
6421 541503425u,
6422 3936326142u,
6423 3112719954u,
6424 775223581u,
6425 3074018423u,
6426 3198488875u,
6427 1772191849u,
6428 2456535211u,
6429 3154686028u,
6430 1520862019u,
6431 4005829426u,
6432 1306433767u,
6433 1943028506u,
6434 2246000782u,
6435 1057766454u,
6436 3761996982u,
6437 3441075333u,
6438 898641979u,
6439 3450209088u,
6440 3941329307u,
6441 3289922449u,
6442 3085075827u,
6443 1814193220u,
6444 690422997u,
6445 2627846676u,
6446 2653520704u,
6447 3739145533u,
6448 3996776010u,
6449 2287072592u,
6450 1346671698u,
6451 3082629900u,
6452 2298811274u,
6453 3639722036u,
6454 1729419228u,
6455 1836765953u,
6456 3708118742u,
6457 213436u,
6458 950223749u,
6459 3734247682u,
6460 2924575678u,
6461 1382024841u,
6462 2431637732u,
6463 3448846682u,
6464 1341301397u,
6465 4206956590u,
6466 1730650902u,
6467 2581075456u,
6468 1542359141u,
6469 707222542u,
6470 2925350541u,
6471 3846303536u,
6472 3579103295u,
6473 3932175763u,
6474 1339615732u,
6475 848825750u,
6476 1070170828u,
6477 1964973818u,
6478 577060344u,
6479 607721296u,
6480 4031023048u,
6481 406883794u,
6482 3991905552u,
6483 1198544082u,
6484 872468460u,
6485 1044847096u,
6486 3159976313u,
6487 3020028266u,
6488 2108700400u,
6489 3373767922u,
6490 264431841u,
6491 2817097007u,
6492 3700061048u,
6493 1733731531u,
6494 3459415893u,
6495 80378591u,
6496 1479875104u,
6497 19735612u,
6498 1382658977u,
6499 3416562245u,
6500 1959852842u,
6501 2384002344u,
6502 124683828u,
6503 3725782174u,
6504 2300301222u,
6505 393852269u,
6506 1302492002u,
6507 3623776492u,
6508 3787086417u,
6509 1730024749u,
6510 1710531361u,
6511 443700716u,
6512 1461987482u,
6513 671998131u,
6514 3018380746u,
6515 2592292305u,
6516 3390799372u,
6517 3945101155u,
6518 3743494852u,
6519 3716045582u,
6520 996005166u,
6521 320698449u,
6522 3420221765u,
6523 1518157951u,
6524 2555810666u,
6525 3381929684u,
6526 2019638523u,
6527 3088262796u,
6528 2072178906u,
6529 3433649364u,
6530 203906916u,
6531 34663784u,
6532 290301305u,
6533 1188021504u,
6534 3754681145u,
6535 3920313139u,
6536 2840496520u,
6537 1656802962u,
6538 2288475489u,
6539 3399185138u,
6540 1296000826u,
6541 2362384746u,
6542 309633360u,
6543 2719851778u,
6544 776035930u,
6545 3200733043u,
6546 365690832u,
6547 3326378243u,
6548 1500331457u,
6549 1625708592u,
6550 4230903462u,
6551 715344888u,
6552 3363777768u,
6553 2243620288u,
6554 2890765789u,
6555 553154234u,
6556 4044100108u,
6557 4056887320u,
6558 1185656496u,
6559 3671476744u,
6560 1064586897u,
6561 1154949698u,
6562 3493481974u,
6563 1294573722u,
6564 1869224012u,
6565 2530084956u,
6566 995321553u,
6567 833419249u,
6568 563815282u,
6569 250258043u,
6570 2970801822u,
6571 441007535u,
6572 42246961u,
6573 2820426655u,
6574 2878882436u,
6575 2363245780u,
6576 2138489282u,
6577 2972360481u,
6578 2312619393u,
6579 3598664848u,
6580 3071556076u,
6581 776990325u,
6582 3220427357u,
6583 2257939577u,
6584 3817305903u,
6585 1502979698u,
6586 3159755934u,
6587 3955997276u,
6588 2423850008u,
6589 1959927572u,
6590 1219782288u,
6591 4119776679u,
6592 1124253854u,
6593 3678052422u,
6594 2620644947u,
6595 1262408666u,
6596 3480072280u,
6597 2627137665u,
6598 807538749u,
6599 3276646337u,
6600 518510128u,
6601 1137828655u,
6602 1498449110u,
6603 3031692317u,
6604 1125635969u,
6605 1130096111u,
6606 780007336u,
6607 3111856399u,
6608 1014917264u,
6609 780877352u,
6610 2909458336u,
6611 4235949214u,
6612 2423879289u,
6613 275888892u,
6614 3891926795u,
6615 3538163953u,
6616 54815161u,
6617 162228302u,
6618 258154068u,
6619 3554455591u,
6620 1801469029u,
6621 2801563220u,
6622 726560058u,
6623 2450221940u,
6624 3677582978u,
6625 440993800u,
6626 424762443u,
6627 2624525253u,
6628 2587715329u,
6629 2292264424u,
6630 1074856749u,
6631 3294752007u,
6632 3164112672u,
6633 2399146799u,
6634 1920182465u,
6635 3858835361u,
6636 193755240u,
6637 3333610311u,
6638 1757504059u,
6639 2576027039u,
6640 2775253365u,
6641 2939191561u,
6642 1046147275u,
6643 235149906u,
6644 4262218222u,
6645 2900542726u,
6646 2260154702u,
6647 1019551635u,
6648 1194720570u,
6649 3519118691u,
6650 3039483153u,
6651 84918216u,
6652 3053381097u,
6653 2572396843u,
6654 3849763371u,
6655 2782686780u,
6656 3710049554u,
6657 3403430713u,
6658 2346080784u,
6659 2496307442u,
6660 1597281872u,
6661 696018239u,
6662 704625714u,
6663 623026921u,
6664 3182413559u,
6665 3794540330u,
6666 305497722u,
6667 1592680199u,
6668 2377854072u,
6669 3060601746u,
6670 3953057908u,
6671 3941551588u,
6672 1033716182u,
6673 2765716854u,
6674 1309699058u,
6675 3519400181u,
6676 3073370877u,
6677 115583008u,
6678 4032909296u,
6679 2944563574u,
6680 3762753718u,
6681 192842727u,
6682 1711348701u,
6683 3086147235u,
6684 1658229443u,
6685 1479783872u,
6686 3839977157u,
6687 225619117u,
6688 1349684817u,
6689 1964813173u,
6690 565753187u,
6691 2530252046u,
6692 840014353u,
6693 1645183704u,
6694 3668429078u,
6695 3438418557u,
6696 639704059u,
6697 360837811u,
6698 2531807958u,
6699 1572353913u,
6700 2116037299u,
6701 1948437512u,
6702 744553393u,
6703 2380697034u,
6704 3775234105u,
6705 3816065157u,
6706 301868653u,
6707 2960939561u,
6708 3306528247u,
6709 2389296549u,
6710 805918610u,
6711 1759358265u,
6712 1760876328u,
6713 2827601706u,
6714 2944594708u,
6715 3313666458u,
6716 2022601495u,
6717 730938791u,
6718 193539397u,
6719 2026103244u,
6720 802928398u,
6721 2630934308u,
6722 782805818u,
6723 3499326016u,
6724 293509489u,
6725 3646131514u,
6726 3182478647u,
6727 854800333u,
6728 2284531628u,
6729 438528022u,
6730 2339298129u,
6731 1692289216u,
6732 2427728723u,
6733 46501288u,
6734 350652353u,
6735 1355971222u,
6736 889682372u,
6737 944799254u,
6738 2763906061u,
6739 2807550612u,
6740 2683762637u,
6741 100870317u,
6742 2449357318u,
6743 2638348436u,
6744 4206088869u,
6745 1788948473u,
6746 3537588549u,
6747 2782490204u,
6748 134406470u,
6749 2409190528u,
6750 2362439849u,
6751 1861661528u,
6752 2101513194u,
6753 1424834765u,
6754 3581765745u,
6755 3185999525u,
6756 2057487100u,
6757 2303941176u,
6758 3639628788u,
6759 1180265315u,
6760 230437935u,
6761 2108319366u,
6762 1131685143u,
6763 1055685292u,
6764 1509007009u,
6765 1258485140u,
6766 560525005u,
6767 3598799040u,
6768 3835680585u,
6769 1851859628u,
6770 332858996u,
6771 641769248u,
6772 4252450037u,
6773 865386707u,
6774 720719117u,
6775 3133612164u,
6776 3833045874u,
6777 3492515435u,
6778 2465970289u,
6779 4234420011u,
6780 573859916u,
6781 252532886u,
6782 870392318u,
6783 4051320920u,
6784 894929092u,
6785 3748361688u,
6786 699355960u,
6787 1885212350u,
6788 1609756949u,
6789 461896870u,
6790 1337065461u,
6791 1775211059u,
6792 1786193749u,
6793 2815154643u,
6794 2128729882u,
6795 969639529u,
6796 3960427545u,
6797 859416958u,
6798 2739758802u,
6799 2698032197u,
6800 2813292418u,
6801 1985467524u,
6802 396604317u,
6803 4122172759u,
6804 1201259789u,
6805 4282051702u,
6806 3270018895u,
6807 961215209u,
6808 961075860u,
6809 4211926998u,
6810 4088374597u,
6811 577510509u,
6812 3058349487u,
6813 4025377754u,
6814 2815478438u,
6815 471023164u,
6816 3947959608u,
6817 4161486934u,
6818 2299888461u,
6819 1103571511u,
6820 2450153872u,
6821 1839939275u,
6822 108299608u,
6823 858086440u,
6824 1030152945u,
6825 3895328530u,
6826 3009080718u,
6827 3690840454u,
6828 3847025277u,
6829 152331362u,
6830 161365689u,
6831 831319961u,
6832 2166017294u,
6833 3945322722u,
6834 4059970216u,
6835 1420824131u,
6836 2770648308u,
6837 1567250186u,
6838 2181067149u,
6839 1939743488u,
6840 3080158120u,
6841 3435218248u,
6842 2495237495u,
6843 3814085102u,
6844 3180983013u,
6845 3199054292u,
6846 2204745908u,
6847 1140337267u,
6848 2213569784u,
6849 1941879842u,
6850 2105562605u,
6851 3618835614u,
6852 2247103645u,
6853 2492473487u,
6854 856414299u,
6855 166022030u,
6856 4080104712u,
6857 3218935344u,
6858 3284220561u,
6859 4261581452u,
6860 1206944836u,
6861 3496705432u,
6862 2215996876u,
6863 3154627465u,
6864 3384005496u,
6865 742170556u,
6866 1333047620u,
6867 802680366u,
6868 156833431u,
6869 2682100354u,
6870 2493654830u,
6871 584848366u,
6872 1691693131u,
6873 2169934170u,
6874 779968026u,
6875 2099545800u,
6876 1423039695u,
6877 4292110968u,
6878 4266576788u,
6879 149142597u,
6880 748501873u,
6881 3865014822u,
6882 1913588198u,
6883 130285614u,
6884 3500768879u,
6885 915458923u,
6886 3071792750u,
6887 1339986633u,
6888 4143929149u,
6889 4048379479u,
6890 725193827u,
6891 1375113643u,
6892 2425277412u,
6893 4144659274u,
6894 465714768u,
6895 226991589u,
6896 2212127704u,
6897 3936145258u,
6898 2891024846u,
6899 3816000225u,
6900 979331165u,
6901 1749907536u,
6902 53847318u,
6903 1462525833u,
6904 2961425455u,
6905 368859113u,
6906 3572721452u,
6907 453048644u,
6908 1628629918u,
6909 3497673923u,
6910 3619079585u,
6911 139870565u,
6912 1518176798u,
6913 3933074281u,
6914 1878623729u,
6915 2074035641u,
6916 3016759257u,
6917 1313053591u,
6918 2557706970u,
6919 2348296582u,
6920 962370022u,
6921 2337285014u,
6922 1618936717u,
6923 1915877085u,
6924 2743743122u,
6925 3250783882u,
6926 1346652536u,
6927 143311109u,
6928 2443788461u,
6929 1048248964u,
6930 2806619339u,
6931 3263266976u,
6932 1668146349u,
6933 3397428868u,
6934 3276188862u,
6935 1774196343u,
6936 1993847813u,
6937 2771079610u,
6938 476672419u,
6939 2119050359u,
6940 2918326659u,
6941 2245402721u,
6942 2692910474u,
6943 2374383269u,
6944 342400227u,
6945 2961437795u,
6946 3899230368u,
6947 337787132u,
6948 3664444935u,
6949 1269451153u,
6950 2971526729u,
6951 1486511182u,
6952 791070133u,
6953 2570319890u,
6954 3482497490u,
6955 2134230518u,
6956 4273391202u,
6957 1825511330u,
6958 3947753714u,
6959 1389755724u,
6960 3995075516u,
6961 2081052615u,
6962 3626343470u,
6963 4213603435u,
6964 2137917278u,
6965 2898987303u,
6966 3059215715u,
6967 3383237881u,
6968 3003674434u,
6969 409174425u,
6970 1911915604u,
6971 2087728055u,
6972 2942005882u,
6973 3386522440u,
6974 714936074u,
6975 261924004u,
6976 3268784033u,
6977 1141188757u,
6978 2413217552u,
6979 1515163433u,
6980 };
6981
6982 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)6983 bool Test(int offset, int len = 0) {
6984 #undef Check
6985 #undef IsAlive
6986
6987 #define Check(x) do { \
6988 bool ok = expected[index++] == (x); \
6989 assert(ok); \
6990 errors += !ok; \
6991 } while (0)
6992
6993 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
6994
6995 // After the following line is where the uses of "Check" and such will go.
6996 static int index = 0;
6997 if (offset == -1) { int alive = 0; IsAlive(farmhashsa::Hash32WithSeed(data, len++, SEED)); IsAlive(farmhashsa::Hash32(data, len++)); IsAlive(farmhashsa::Hash32(data, len++)); len -= 3; return alive > 0; }
6998 Check(farmhashsa::Hash32WithSeed(data + offset, len, SEED));
6999 Check(farmhashsa::Hash32(data + offset, len));
7000
7001 return true;
7002 #undef Check
7003 #undef IsAlive
7004 }
7005
RunTest()7006 int RunTest() {
7007 Setup();
7008 int i = 0;
7009 cout << "Running farmhashsaTest";
7010 if (!Test(-1)) {
7011 cout << "... Unavailable\n";
7012 return NoteErrors();
7013 }
7014 // Good. The function is attempting to hash, so run the full test.
7015 int errors_prior_to_test = errors;
7016 for ( ; i < kTestSize - 1; i++) {
7017 Test(i * i, i);
7018 }
7019 for ( ; i < kDataSize; i += i / 7) {
7020 Test(0, i);
7021 }
7022 Test(0, kDataSize);
7023 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
7024 return NoteErrors();
7025 }
7026
7027 #else
7028
7029 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)7030 void Dump(int offset, int len) {
7031 cout << farmhashsa::Hash32WithSeed(data + offset, len, SEED) << "u," << endl;
7032 cout << farmhashsa::Hash32(data + offset, len) << "u," << endl;
7033 }
7034
7035 #endif
7036
7037 #undef SEED
7038 #undef SEED1
7039 #undef SEED0
7040
7041 } // namespace farmhashsaTest
7042
7043 #if TESTING
7044
7045 static int farmhashsaTestResult = farmhashsaTest::RunTest();
7046
7047 #else
main(int argc,char ** argv)7048 int main(int argc, char** argv) {
7049 Setup();
7050 cout << "uint32_t expected[] = {\n";
7051 int i = 0;
7052 for ( ; i < kTestSize - 1; i++) {
7053 farmhashsaTest::Dump(i * i, i);
7054 }
7055 for ( ; i < kDataSize; i += i / 7) {
7056 farmhashsaTest::Dump(0, i);
7057 }
7058 farmhashsaTest::Dump(0, kDataSize);
7059 cout << "};\n";
7060 }
7061 #endif
7062 #ifndef FARMHASH_SELF_TEST_GUARD
7063 #define FARMHASH_SELF_TEST_GUARD
7064 #include <string.h>
7065 #include <cstdio>
7066 #include <iostream>
7067
7068 using std::cout;
7069 using std::cerr;
7070 using std::endl;
7071 using std::hex;
7072
7073 static const uint64_t kSeed0 = 1234567;
7074 static const uint64_t kSeed1 = k0;
7075 static const int kDataSize = 1 << 20;
7076 static const int kTestSize = 300;
7077 #define kSeed128 Uint128(kSeed0, kSeed1)
7078
7079 static char data[kDataSize];
7080
7081 static int completed_self_tests = 0;
7082 static int errors = 0;
7083
7084 // Initialize data to pseudorandom values.
Setup()7085 void Setup() {
7086 if (completed_self_tests == 0) {
7087 uint64_t a = 9;
7088 uint64_t b = 777;
7089 for (int i = 0; i < kDataSize; i++) {
7090 a += b;
7091 b += a;
7092 a = (a ^ (a >> 41)) * k0;
7093 b = (b ^ (b >> 41)) * k0 + i;
7094 uint8_t u = b >> 37;
7095 memcpy(data + i, &u, 1); // uint8_t -> char
7096 }
7097 }
7098 }
7099
NoteErrors()7100 int NoteErrors() {
7101 #define NUM_SELF_TESTS 6
7102 if (++completed_self_tests == NUM_SELF_TESTS)
7103 std::exit(errors > 0);
7104 return errors;
7105 }
7106
IsNonZero(T x)7107 template <typename T> inline bool IsNonZero(T x) {
7108 return x != 0;
7109 }
7110
IsNonZero(uint128_t x)7111 template <> inline bool IsNonZero<uint128_t>(uint128_t x) {
7112 return x != Uint128(0, 0);
7113 }
7114
7115 #endif // FARMHASH_SELF_TEST_GUARD
7116
7117 namespace farmhashsuTest {
7118
CreateSeed(int offset,int salt)7119 uint32_t CreateSeed(int offset, int salt) {
7120 uint32_t h = static_cast<uint32_t>(salt & 0xffffffff);
7121 h = h * c1;
7122 h ^= (h >> 17);
7123 h = h * c1;
7124 h ^= (h >> 17);
7125 h = h * c1;
7126 h ^= (h >> 17);
7127 h += static_cast<uint32_t>(offset & 0xffffffff);
7128 h = h * c1;
7129 h ^= (h >> 17);
7130 h = h * c1;
7131 h ^= (h >> 17);
7132 h = h * c1;
7133 h ^= (h >> 17);
7134 return h;
7135 }
7136
7137 #undef SEED
7138 #undef SEED1
7139 #undef SEED0
7140 #define SEED CreateSeed(offset, -1)
7141 #define SEED0 CreateSeed(offset, 0)
7142 #define SEED1 CreateSeed(offset, 1)
7143
7144 #undef TESTING
7145 #define TESTING 1
7146 #if TESTING
7147 uint32_t expected[] = {
7148 4223616069u,
7149 3696677242u,
7150 4081014168u,
7151 2576519988u,
7152 2212771159u,
7153 1112731063u,
7154 1020067935u,
7155 3955445564u,
7156 1451961420u,
7157 653440099u,
7158 31917516u,
7159 2957164615u,
7160 2590087362u,
7161 3879448744u,
7162 176305566u,
7163 2447367541u,
7164 1359016305u,
7165 3363804638u,
7166 1117290165u,
7167 1062549743u,
7168 2437877004u,
7169 1894455839u,
7170 673206794u,
7171 3486923651u,
7172 3269862919u,
7173 2303349487u,
7174 1380660650u,
7175 595525107u,
7176 1525325287u,
7177 2025609358u,
7178 176408838u,
7179 1592885012u,
7180 864896482u,
7181 2101378090u,
7182 3489229104u,
7183 2118965695u,
7184 581644891u,
7185 2718789079u,
7186 631613207u,
7187 4228658372u,
7188 3867875546u,
7189 3531368319u,
7190 3804516756u,
7191 3317755099u,
7192 1619744564u,
7193 2884717286u,
7194 1088213445u,
7195 2667691076u,
7196 3727873235u,
7197 2330406762u,
7198 858590707u,
7199 457744844u,
7200 4150036245u,
7201 2000404290u,
7202 1478882570u,
7203 901678172u,
7204 819171187u,
7205 195942998u,
7206 4254302102u,
7207 3967266927u,
7208 437030323u,
7209 4018009204u,
7210 2868246750u,
7211 3540087514u,
7212 3154852132u,
7213 3319116625u,
7214 357580983u,
7215 3177665294u,
7216 1108813287u,
7217 1253366798u,
7218 2315997713u,
7219 510718750u,
7220 1360882441u,
7221 2770216279u,
7222 3048866755u,
7223 3406961221u,
7224 3664371439u,
7225 1151145514u,
7226 1027891570u,
7227 2699067992u,
7228 3461888315u,
7229 198061905u,
7230 292769636u,
7231 1106771795u,
7232 4064110516u,
7233 3258279756u,
7234 762850927u,
7235 1818699721u,
7236 2803307356u,
7237 3919169404u,
7238 460980967u,
7239 3125535078u,
7240 2802568977u,
7241 3582546426u,
7242 2148940781u,
7243 3963274378u,
7244 1266953698u,
7245 204185123u,
7246 1100034381u,
7247 3009193601u,
7248 4200651967u,
7249 274889605u,
7250 2700589508u,
7251 952511689u,
7252 3765324859u,
7253 3465498478u,
7254 4014967037u,
7255 2070988082u,
7256 2972423530u,
7257 3068638223u,
7258 4156773651u,
7259 489509804u,
7260 1323863238u,
7261 3731914806u,
7262 2846098469u,
7263 2728930632u,
7264 346814072u,
7265 848146907u,
7266 551160669u,
7267 4165126521u,
7268 2039095001u,
7269 4179859388u,
7270 2434936359u,
7271 2764414551u,
7272 238491210u,
7273 732483969u,
7274 3366512764u,
7275 478307468u,
7276 4124179572u,
7277 4142733597u,
7278 1953448206u,
7279 4199329278u,
7280 865077060u,
7281 2627662116u,
7282 2802499360u,
7283 3141206831u,
7284 1959218197u,
7285 911371451u,
7286 125987200u,
7287 2821366175u,
7288 2530992747u,
7289 2409206225u,
7290 117991880u,
7291 2133402461u,
7292 895510531u,
7293 428719601u,
7294 3036014536u,
7295 1223783733u,
7296 733793540u,
7297 970650405u,
7298 547701766u,
7299 570764615u,
7300 3224485368u,
7301 3192714940u,
7302 319942831u,
7303 3940200341u,
7304 362056204u,
7305 2832368105u,
7306 1853281226u,
7307 3296434636u,
7308 3752508307u,
7309 604292768u,
7310 2231940616u,
7311 1204094681u,
7312 866194005u,
7313 2405201650u,
7314 2466384396u,
7315 380829379u,
7316 230033818u,
7317 2783417588u,
7318 4249886729u,
7319 829569301u,
7320 2988322580u,
7321 2299983554u,
7322 74748560u,
7323 737514425u,
7324 3153050211u,
7325 652642663u,
7326 1270205115u,
7327 227197032u,
7328 2773091790u,
7329 325849216u,
7330 49998791u,
7331 4043203010u,
7332 3662748068u,
7333 1709364383u,
7334 1179105165u,
7335 1478504366u,
7336 2980456610u,
7337 1167476429u,
7338 1590390732u,
7339 1306256496u,
7340 292008135u,
7341 374690995u,
7342 1809200819u,
7343 1680595904u,
7344 646040226u,
7345 1742445560u,
7346 2435776844u,
7347 3703683804u,
7348 478742495u,
7349 814967947u,
7350 2698190177u,
7351 1003617993u,
7352 1436118705u,
7353 217056304u,
7354 1412287094u,
7355 2738417466u,
7356 2933279339u,
7357 3461877733u,
7358 1203141205u,
7359 2119492857u,
7360 1134895723u,
7361 1560001021u,
7362 3786320122u,
7363 3748116258u,
7364 3486219595u,
7365 702138030u,
7366 1062984182u,
7367 232789133u,
7368 1566523968u,
7369 3885443778u,
7370 1820171888u,
7371 3655858585u,
7372 2316903005u,
7373 2678779620u,
7374 395625433u,
7375 1609107564u,
7376 3108726411u,
7377 2937837224u,
7378 3911907151u,
7379 557272509u,
7380 3893435978u,
7381 1542613576u,
7382 1079886893u,
7383 2624566322u,
7384 1413700616u,
7385 2796974006u,
7386 1922556114u,
7387 562820464u,
7388 2845409784u,
7389 54180312u,
7390 1898782464u,
7391 3681814953u,
7392 2417064617u,
7393 1815464483u,
7394 911626132u,
7395 2964575550u,
7396 1852696128u,
7397 2319647785u,
7398 1998904590u,
7399 619992689u,
7400 3073207513u,
7401 1238163512u,
7402 3199435982u,
7403 828667254u,
7404 3561155502u,
7405 3943095163u,
7406 1045711849u,
7407 2238679131u,
7408 2114975398u,
7409 713808403u,
7410 3871787494u,
7411 2572031161u,
7412 2360934075u,
7413 2337781107u,
7414 262596504u,
7415 693836699u,
7416 2129369850u,
7417 3543189427u,
7418 962205222u,
7419 3685581020u,
7420 692974477u,
7421 725182211u,
7422 646123906u,
7423 2368836544u,
7424 2505872733u,
7425 1999977610u,
7426 1639885802u,
7427 1475058032u,
7428 207023609u,
7429 2773581234u,
7430 3524857793u,
7431 3433371102u,
7432 3243027613u,
7433 1787668353u,
7434 985757946u,
7435 3896012929u,
7436 702356957u,
7437 3559331129u,
7438 884084870u,
7439 4009998120u,
7440 648888720u,
7441 1403349048u,
7442 1624342778u,
7443 1766674171u,
7444 2518582204u,
7445 3251243146u,
7446 792751003u,
7447 1377201813u,
7448 3629686054u,
7449 1583734324u,
7450 3647107626u,
7451 4258564381u,
7452 1469878609u,
7453 1940598241u,
7454 2755003690u,
7455 1907120418u,
7456 109916701u,
7457 775347954u,
7458 2090960874u,
7459 611281803u,
7460 3470490146u,
7461 3301663253u,
7462 1835412158u,
7463 1803066146u,
7464 591872433u,
7465 550703713u,
7466 1495089683u,
7467 826492808u,
7468 817200035u,
7469 4177474571u,
7470 688070143u,
7471 971427632u,
7472 1442499481u,
7473 3568640348u,
7474 2789993738u,
7475 85808128u,
7476 2058346726u,
7477 394058570u,
7478 3466511434u,
7479 318905230u,
7480 4149248030u,
7481 415308316u,
7482 165997598u,
7483 1219639412u,
7484 1648022659u,
7485 2857432523u,
7486 1422508004u,
7487 468095522u,
7488 296968649u,
7489 430250611u,
7490 1775562314u,
7491 2976361671u,
7492 1040036362u,
7493 1372510167u,
7494 292746272u,
7495 3408238954u,
7496 626061886u,
7497 1317637569u,
7498 1237775792u,
7499 1218490455u,
7500 2224234499u,
7501 590942419u,
7502 713995643u,
7503 3541889330u,
7504 4140218960u,
7505 3529791107u,
7506 354462673u,
7507 842607274u,
7508 365048533u,
7509 2638303414u,
7510 3560458014u,
7511 31621379u,
7512 4210854794u,
7513 1273118792u,
7514 2572743762u,
7515 3513175801u,
7516 402066986u,
7517 602524471u,
7518 565029192u,
7519 180576438u,
7520 1288605959u,
7521 2896244423u,
7522 1420543484u,
7523 1329862227u,
7524 1791567324u,
7525 4248690247u,
7526 12917038u,
7527 3483481310u,
7528 2082050731u,
7529 1611921143u,
7530 2443766548u,
7531 2216338811u,
7532 2528006095u,
7533 2984009021u,
7534 674210884u,
7535 2857608106u,
7536 2155534809u,
7537 1023105067u,
7538 2968955846u,
7539 3303624302u,
7540 2502112850u,
7541 245749006u,
7542 3175229091u,
7543 3342796184u,
7544 3613785362u,
7545 1614168851u,
7546 2582149283u,
7547 895403488u,
7548 416205023u,
7549 3792242000u,
7550 529397534u,
7551 299415203u,
7552 4284673348u,
7553 2096851282u,
7554 1864524731u,
7555 2012577738u,
7556 3426363316u,
7557 1387308508u,
7558 1143610148u,
7559 2027467219u,
7560 3772856163u,
7561 3453862623u,
7562 2661437174u,
7563 2047145955u,
7564 2533381447u,
7565 2059534115u,
7566 439426587u,
7567 1537543414u,
7568 2384289877u,
7569 3174229055u,
7570 2658017753u,
7571 2293148474u,
7572 2359450158u,
7573 3930242475u,
7574 1510302397u,
7575 3354288821u,
7576 920095603u,
7577 2415746928u,
7578 2729472638u,
7579 2261143371u,
7580 848667611u,
7581 919157153u,
7582 3322393117u,
7583 4103299943u,
7584 413569608u,
7585 68911216u,
7586 3334990170u,
7587 1228068652u,
7588 1570056373u,
7589 1905477543u,
7590 2622302276u,
7591 2935063895u,
7592 3224810004u,
7593 4211768578u,
7594 828688131u,
7595 3556122839u,
7596 1930935348u,
7597 2605825202u,
7598 1540993970u,
7599 3209115883u,
7600 122847500u,
7601 665638794u,
7602 506571051u,
7603 2691795295u,
7604 3996966556u,
7605 714660621u,
7606 3662432239u,
7607 470651837u,
7608 1807432621u,
7609 3755290953u,
7610 359878860u,
7611 2793081615u,
7612 4065031431u,
7613 904653062u,
7614 2317800777u,
7615 568501094u,
7616 3492871707u,
7617 2738806116u,
7618 2883859610u,
7619 3242080257u,
7620 364246691u,
7621 3601786516u,
7622 3159362524u,
7623 1578272201u,
7624 1283574375u,
7625 2912186103u,
7626 2256279032u,
7627 1540671086u,
7628 2356088973u,
7629 2892277779u,
7630 3441449267u,
7631 2225005503u,
7632 3846428419u,
7633 2014549218u,
7634 2290734767u,
7635 2126684614u,
7636 4235463487u,
7637 3811556204u,
7638 174739661u,
7639 767525888u,
7640 47684458u,
7641 4211168099u,
7642 889063422u,
7643 469864411u,
7644 767407110u,
7645 413337343u,
7646 1618456644u,
7647 2814499820u,
7648 2401124192u,
7649 632089437u,
7650 1234980238u,
7651 1288585402u,
7652 3153169944u,
7653 2917822069u,
7654 1843320264u,
7655 3794359132u,
7656 3074573530u,
7657 258629454u,
7658 3813357060u,
7659 3806887248u,
7660 1665524736u,
7661 3324533324u,
7662 3005091922u,
7663 793108368u,
7664 1529669805u,
7665 2332660395u,
7666 2217730223u,
7667 2634687611u,
7668 442806463u,
7669 1968135266u,
7670 454523002u,
7671 3177866230u,
7672 2808960136u,
7673 4259114138u,
7674 4103264843u,
7675 3103714075u,
7676 2462967542u,
7677 1466891491u,
7678 477973764u,
7679 834565647u,
7680 741089037u,
7681 218837573u,
7682 1710536528u,
7683 2469088212u,
7684 1229072375u,
7685 2828341u,
7686 176923431u,
7687 985763350u,
7688 4095477420u,
7689 1984145538u,
7690 1870791084u,
7691 674956677u,
7692 1978138947u,
7693 1296493993u,
7694 1818183554u,
7695 3443333721u,
7696 2124949983u,
7697 2549590262u,
7698 2700850794u,
7699 2662736367u,
7700 739638109u,
7701 4061447096u,
7702 2960078422u,
7703 2453781158u,
7704 929570940u,
7705 3200328383u,
7706 2406328791u,
7707 1419180666u,
7708 2152455739u,
7709 2805741044u,
7710 3305999074u,
7711 3183816361u,
7712 2303165050u,
7713 4922104u,
7714 63096005u,
7715 936656347u,
7716 3104453886u,
7717 1088673880u,
7718 1113407526u,
7719 1457890086u,
7720 453478383u,
7721 1107686695u,
7722 3626027824u,
7723 1159687359u,
7724 2248467888u,
7725 2004578380u,
7726 3274954621u,
7727 1787958646u,
7728 2628726704u,
7729 1138419798u,
7730 3735442315u,
7731 692385301u,
7732 313807213u,
7733 2329068673u,
7734 59375364u,
7735 3261084359u,
7736 2088644507u,
7737 2471153194u,
7738 788336435u,
7739 4024527246u,
7740 141504460u,
7741 2307553888u,
7742 1930559950u,
7743 48975711u,
7744 2745693338u,
7745 230161982u,
7746 3429230862u,
7747 1335968626u,
7748 609591304u,
7749 57435073u,
7750 4279281136u,
7751 3152151665u,
7752 3984484924u,
7753 3459883943u,
7754 397478330u,
7755 1738762229u,
7756 3033590066u,
7757 3611539498u,
7758 1363463523u,
7759 3319364965u,
7760 2671169141u,
7761 3819548561u,
7762 1691193757u,
7763 2423834608u,
7764 2820147055u,
7765 1378120632u,
7766 1240565187u,
7767 3180720050u,
7768 680831086u,
7769 3309658414u,
7770 1986166490u,
7771 762099827u,
7772 510883662u,
7773 2047373648u,
7774 3606742294u,
7775 3894965352u,
7776 2342078853u,
7777 1091255717u,
7778 776594727u,
7779 3217317445u,
7780 1574468485u,
7781 3844504016u,
7782 2819598918u,
7783 1037401010u,
7784 2550943503u,
7785 3867184001u,
7786 1687911772u,
7787 165313836u,
7788 1679575281u,
7789 2418947263u,
7790 2038774952u,
7791 3913543652u,
7792 3209155736u,
7793 149905221u,
7794 3859604717u,
7795 713919631u,
7796 4069810796u,
7797 1882959164u,
7798 1019939034u,
7799 2379867302u,
7800 3666323035u,
7801 1157389013u,
7802 2422300650u,
7803 3366777340u,
7804 2526452062u,
7805 1313747885u,
7806 1039617868u,
7807 1620553692u,
7808 2032976978u,
7809 578789528u,
7810 1592846839u,
7811 2270630604u,
7812 897850577u,
7813 1603294178u,
7814 3105664807u,
7815 1442670138u,
7816 1728019360u,
7817 79313861u,
7818 1683031101u,
7819 1913067024u,
7820 4070719870u,
7821 708986470u,
7822 2586453359u,
7823 3993348863u,
7824 3358251279u,
7825 3003552537u,
7826 750174793u,
7827 836888956u,
7828 4190747426u,
7829 4251291318u,
7830 4145164938u,
7831 1366883260u,
7832 1912910955u,
7833 510192669u,
7834 1851315039u,
7835 3574241274u,
7836 3220062924u,
7837 2821142039u,
7838 1317082195u,
7839 2274293302u,
7840 1839219569u,
7841 126586168u,
7842 3989293643u,
7843 2680178207u,
7844 347056948u,
7845 799681430u,
7846 2864517481u,
7847 3180404853u,
7848 213140045u,
7849 1956305184u,
7850 1474675286u,
7851 3085723423u,
7852 2841859626u,
7853 308421914u,
7854 3670309263u,
7855 1765052231u,
7856 245459238u,
7857 113434331u,
7858 4079521092u,
7859 2115235526u,
7860 2943408816u,
7861 1055476938u,
7862 1506442339u,
7863 2291296392u,
7864 3267864332u,
7865 1282145528u,
7866 3700108015u,
7867 1932843667u,
7868 2677701670u,
7869 6041177u,
7870 3889648557u,
7871 1461025478u,
7872 };
7873
7874 // Return false only if offset is -1 and a spot check of 3 hashes all yield 0.
Test(int offset,int len=0)7875 bool Test(int offset, int len = 0) {
7876 #undef Check
7877 #undef IsAlive
7878
7879 #define Check(x) do { \
7880 bool ok = expected[index++] == (x); \
7881 assert(ok); \
7882 errors += !ok; \
7883 } while (0)
7884
7885 #define IsAlive(x) do { alive += IsNonZero(x); } while (0)
7886
7887 // After the following line is where the uses of "Check" and such will go.
7888 static int index = 0;
7889 if (offset == -1) { int alive = 0; IsAlive(farmhashsu::Hash32WithSeed(data, len++, SEED)); IsAlive(farmhashsu::Hash32(data, len++)); IsAlive(farmhashsu::Hash32(data, len++)); len -= 3; return alive > 0; }
7890 Check(farmhashsu::Hash32WithSeed(data + offset, len, SEED));
7891 Check(farmhashsu::Hash32(data + offset, len));
7892
7893 return true;
7894 #undef Check
7895 #undef IsAlive
7896 }
7897
RunTest()7898 int RunTest() {
7899 Setup();
7900 int i = 0;
7901 cout << "Running farmhashsuTest";
7902 if (!Test(-1)) {
7903 cout << "... Unavailable\n";
7904 return NoteErrors();
7905 }
7906 // Good. The function is attempting to hash, so run the full test.
7907 int errors_prior_to_test = errors;
7908 for ( ; i < kTestSize - 1; i++) {
7909 Test(i * i, i);
7910 }
7911 for ( ; i < kDataSize; i += i / 7) {
7912 Test(0, i);
7913 }
7914 Test(0, kDataSize);
7915 cout << (errors == errors_prior_to_test ? "... OK\n" : "... Failed\n");
7916 return NoteErrors();
7917 }
7918
7919 #else
7920
7921 // After the following line is where the code to print hash codes will go.
Dump(int offset,int len)7922 void Dump(int offset, int len) {
7923 cout << farmhashsu::Hash32WithSeed(data + offset, len, SEED) << "u," << endl;
7924 cout << farmhashsu::Hash32(data + offset, len) << "u," << endl;
7925 }
7926
7927 #endif
7928
7929 #undef SEED
7930 #undef SEED1
7931 #undef SEED0
7932
7933 } // namespace farmhashsuTest
7934
7935 #if TESTING
7936
7937 static int farmhashsuTestResult = farmhashsuTest::RunTest();
7938
7939 #else
main(int argc,char ** argv)7940 int main(int argc, char** argv) {
7941 Setup();
7942 cout << "uint32_t expected[] = {\n";
7943 int i = 0;
7944 for ( ; i < kTestSize - 1; i++) {
7945 farmhashsuTest::Dump(i * i, i);
7946 }
7947 for ( ; i < kDataSize; i += i / 7) {
7948 farmhashsuTest::Dump(0, i);
7949 }
7950 farmhashsuTest::Dump(0, kDataSize);
7951 cout << "};\n";
7952 }
7953 #endif
7954
7955 #endif // FARMHASHSELFTEST
7956