35 #define bitRotateLeft(x, nBits) (((x) << (nBits)) | ((x) >> (32 - (nBits)))) 115 #define bitMixer(a, b, c) \ 117 a -= c; a ^= bitRotateLeft(c, 4); c += b; \ 118 b -= a; b ^= bitRotateLeft(a, 6); a += c; \ 119 c -= b; c ^= bitRotateLeft(b, 8); b += a; \ 120 a -= c; a ^= bitRotateLeft(c,16); c += b; \ 121 b -= a; b ^= bitRotateLeft(a,19); a += c; \ 122 c -= b; c ^= bitRotateLeft(b, 4); b += a; \ 150 #define bitMixerFinal(a, b, c) \ 152 c ^= b; c -= bitRotateLeft(b, 14); \ 153 a ^= c; a -= bitRotateLeft(c, 11); \ 154 b ^= a; b -= bitRotateLeft(a, 25); \ 155 c ^= b; c -= bitRotateLeft(b, 16); \ 156 a ^= c; a -= bitRotateLeft(c, 4); \ 157 b ^= a; b -= bitRotateLeft(a, 14); \ 158 c ^= b; c -= bitRotateLeft(b, 24); \ 185 a =
b =
c = 0xdeadbeef + (
static_cast<uint32_t
>(length) << 2) + seed;
201 case 3 :
c +=
k[2]; [[fallthrough]];
202 case 2 :
b +=
k[1]; [[fallthrough]];
234 a =
b =
c = 0xdeadbeef + (
static_cast<uint32_t
>(length) << 2) + hash1;
251 case 3 :
c +=
k[2]; [[fallthrough]];
252 case 2 :
b +=
k[1]; [[fallthrough]];
298 #ifdef WM_LITTLE_ENDIAN 299 static unsigned jenkins_hashlittle
307 union {
const void *ptr;
size_t i; } u;
310 a =
b =
c = 0xdeadbeef +
static_cast<uint32_t
>(length) + initval;
313 if ((u.i & 0x3) == 0)
316 const uint32_t *
k =
reinterpret_cast<const uint32_t*
>(
key);
330 const uint8_t *k8 =
reinterpret_cast<const uint8_t*
>(
k);
333 case 12:
c +=
k[2];
b +=
k[1]; a +=
k[0];
break;
334 case 11:
c +=
static_cast<uint32_t
>(k8[10]) << 16; [[fallthrough]];
335 case 10:
c +=
static_cast<uint32_t
>(k8[9]) << 8; [[fallthrough]];
336 case 9 :
c += k8[8]; [[fallthrough]];
337 case 8 :
b +=
k[1]; a +=
k[0];
break;
338 case 7 :
b +=
static_cast<uint32_t
>(k8[6]) << 16; [[fallthrough]];
339 case 6 :
b +=
static_cast<uint32_t
>(k8[5]) << 8; [[fallthrough]];
340 case 5 :
b += k8[4]; [[fallthrough]];
341 case 4 : a +=
k[0];
break;
342 case 3 : a +=
static_cast<uint32_t
>(k8[2]) << 16; [[fallthrough]];
343 case 2 : a +=
static_cast<uint32_t
>(k8[1]) << 8; [[fallthrough]];
344 case 1 : a += k8[0];
break;
348 else if ((u.i & 0x1) == 0)
351 const uint16_t *
k =
reinterpret_cast<const uint16_t*
>(
key);
356 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
357 b +=
k[2] + (
static_cast<uint32_t
>(
k[3]) << 16);
358 c +=
k[4] + (
static_cast<uint32_t
>(
k[5]) << 16);
365 const uint8_t *k8 =
reinterpret_cast<const uint8_t*
>(
k);
369 c +=
k[4] + (
static_cast<uint32_t
>(
k[5]) << 16);
370 b +=
k[2] + (
static_cast<uint32_t
>(
k[3]) << 16);
371 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
374 c +=
static_cast<uint32_t
>(k8[10]) << 16;
378 b +=
k[2] + (
static_cast<uint32_t
>(
k[3]) << 16);
379 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
385 b +=
k[2] + (
static_cast<uint32_t
>(
k[3]) << 16);
386 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
389 b +=
static_cast<uint32_t
>(k8[6]) << 16;
393 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
399 a +=
k[0] + (
static_cast<uint32_t
>(
k[1]) << 16);
402 a +=
static_cast<uint32_t
>(k8[2]) << 16;
416 const uint8_t *
k =
reinterpret_cast<const uint8_t*
>(
key);
422 a +=
static_cast<uint32_t
>(
k[1]) << 8;
423 a +=
static_cast<uint32_t
>(
k[2]) << 16;
424 a +=
static_cast<uint32_t
>(
k[3]) << 24;
426 b +=
static_cast<uint32_t
>(
k[5]) << 8;
427 b +=
static_cast<uint32_t
>(
k[6]) << 16;
428 b +=
static_cast<uint32_t
>(
k[7]) << 24;
430 c +=
static_cast<uint32_t
>(
k[9]) << 8;
431 c +=
static_cast<uint32_t
>(
k[10]) << 16;
432 c +=
static_cast<uint32_t
>(
k[11]) << 24;
442 case 12:
c +=
static_cast<uint32_t
>(
k[11]) << 24; [[fallthrough]];
443 case 11:
c +=
static_cast<uint32_t
>(
k[10]) << 16; [[fallthrough]];
444 case 10:
c +=
static_cast<uint32_t
>(
k[9]) << 8; [[fallthrough]];
445 case 9 :
c +=
k[8]; [[fallthrough]];
447 case 8 :
b +=
static_cast<uint32_t
>(
k[7]) << 24; [[fallthrough]];
448 case 7 :
b +=
static_cast<uint32_t
>(
k[6]) << 16; [[fallthrough]];
449 case 6 :
b +=
static_cast<uint32_t
>(
k[5]) << 8; [[fallthrough]];
450 case 5 :
b +=
k[4]; [[fallthrough]];
452 case 4 : a +=
static_cast<uint32_t
>(
k[3]) << 24; [[fallthrough]];
453 case 3 : a +=
static_cast<uint32_t
>(
k[2]) << 16; [[fallthrough]];
454 case 2 : a +=
static_cast<uint32_t
>(
k[1]) << 8; [[fallthrough]];
476 static unsigned jenkins_hashbig
484 union {
const void *ptr;
size_t i; } u;
487 a =
b =
c = 0xdeadbeef +
static_cast<uint32_t
>(length) + initval;
490 if ((u.i & 0x3) == 0)
493 const uint32_t *
k =
reinterpret_cast<const uint32_t*
>(
key);
507 const uint8_t *k8 =
reinterpret_cast<const uint8_t*
>(
k);
511 case 12:
c +=
k[2];
b +=
k[1]; a +=
k[0];
break;
512 case 11:
c +=
static_cast<uint32_t
>(k8[10]) << 8; [[fallthrough]];
513 case 10:
c +=
static_cast<uint32_t
>(k8[9]) << 16; [[fallthrough]];
514 case 9 :
c +=
static_cast<uint32_t
>(k8[8]) << 24; [[fallthrough]];
515 case 8 :
b +=
k[1]; a +=
k[0];
break;
516 case 7 :
b +=
static_cast<uint32_t
>(k8[6]) << 8; [[fallthrough]];
517 case 6 :
b +=
static_cast<uint32_t
>(k8[5]) << 16; [[fallthrough]];
518 case 5 :
b +=
static_cast<uint32_t
>(k8[4]) << 24; [[fallthrough]];
519 case 4 : a +=
k[0];
break;
520 case 3 : a +=
static_cast<uint32_t
>(k8[2]) << 8; [[fallthrough]];
521 case 2 : a +=
static_cast<uint32_t
>(k8[1]) << 16; [[fallthrough]];
522 case 1 : a +=
static_cast<uint32_t
>(k8[0]) << 24;
break;
529 const uint8_t *
k =
reinterpret_cast<const uint8_t*
>(
key);
534 a +=
static_cast<uint32_t
>(
k[0]) << 24;
535 a +=
static_cast<uint32_t
>(
k[1]) << 16;
536 a +=
static_cast<uint32_t
>(
k[2]) << 8;
537 a +=
static_cast<uint32_t
>(
k[3]);
538 b +=
static_cast<uint32_t
>(
k[4]) << 24;
539 b +=
static_cast<uint32_t
>(
k[5]) << 16;
540 b +=
static_cast<uint32_t
>(
k[6]) << 8;
541 b +=
static_cast<uint32_t
>(
k[7]);
542 c +=
static_cast<uint32_t
>(
k[8]) << 24;
543 c +=
static_cast<uint32_t
>(
k[9]) << 16;
544 c +=
static_cast<uint32_t
>(
k[10]) << 8;
545 c +=
static_cast<uint32_t
>(
k[11]);
555 case 12:
c +=
k[11]; [[fallthrough]];
556 case 11:
c +=
static_cast<uint32_t
>(
k[10]) << 8; [[fallthrough]];
557 case 10:
c +=
static_cast<uint32_t
>(
k[9]) << 16; [[fallthrough]];
558 case 9 :
c +=
static_cast<uint32_t
>(
k[8]) << 24; [[fallthrough]];
559 case 8 :
b +=
k[7]; [[fallthrough]];
560 case 7 :
b +=
static_cast<uint32_t
>(
k[6]) << 8; [[fallthrough]];
561 case 6 :
b +=
static_cast<uint32_t
>(
k[5]) << 16; [[fallthrough]];
562 case 5 :
b +=
static_cast<uint32_t
>(
k[4]) << 24; [[fallthrough]];
563 case 4 : a +=
k[3]; [[fallthrough]];
564 case 3 : a +=
static_cast<uint32_t
>(
k[2]) << 8; [[fallthrough]];
565 case 2 : a +=
static_cast<uint32_t
>(
k[1]) << 16; [[fallthrough]];
566 case 1 : a +=
static_cast<uint32_t
>(
k[0]) << 24; [[fallthrough]];
587 #if defined (WM_BIG_ENDIAN) 588 return jenkins_hashbig(
key, length, initval);
589 #elif defined (WM_LITTLE_ENDIAN) 590 return jenkins_hashlittle(
key, length, initval);
592 #error "Cannot determine WM_BIG_ENDIAN or WM_LITTLE_ENDIAN." unsigned HasherInt(const uint32_t *data, size_t length, unsigned seed=0)
An optimized version of Hasher.
#define bitMixer(a, b, c)
label k
Boltzmann constant.
Help with architecture-specific aspects.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
#define bitMixerFinal(a, b, c)
Optimized hashing functions.
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins's 96-bit mixer hashing function (lookup3)
unsigned HasherDual(const uint32_t *data, size_t length, unsigned &hash1, unsigned &hash2)
An optimized version of Hasher, returning dual hash values.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Miscellaneous hashing functions, mostly from Bob Jenkins.
const dimensionedScalar c
Speed of light in a vacuum.