8#ifndef INCLUDED_BSLH_SPOOKYHASHALGORITHMIMP
9#define INCLUDED_BSLH_SPOOKYHASHALGORITHMIMP
265#include <bslscm_version.h>
274#if defined(BSLS_PLATFORM_CMP_GNU)
275#define BSLH_SPOOKYHASHALGORITHMIMP_INLINE \
276 inline __attribute__((always_inline))
278#define BSLH_SPOOKYHASHALGORITHMIMP_INLINE inline
303 enum { k_NUM_VARS = 12 };
306 enum { k_BLOCK_SIZE = k_NUM_VARS * 8 };
309 enum { k_BUFFER_SIZE = k_BLOCK_SIZE * 2 };
313 static const Uint64 sc_const = 0xdeadbeefdeadbeefULL;
315 Uint64 m_data[2 * k_NUM_VARS];
316 Uint64 m_state[k_NUM_VARS];
329 static void end(
const Uint64 *data,
353 static void mix(
const Uint64 *data,
369 static void shortHash(
const void *message,
390 SpookyHashAlgorithmImp(
const SpookyHashAlgorithmImp& original);
392 SpookyHashAlgorithmImp& operator=(
const SpookyHashAlgorithmImp& rhs);
445 void update(
const void *message,
size_t length);
472 Uint64 hash1 = seed, hash2 = seed;
473 hash128(message, length, &hash1, &hash2);
474 return static_cast<Uint32>(hash1);
485 hash128(message, length, &hash1, &seed);
491SpookyHashAlgorithmImp::SpookyHashAlgorithmImp(
Uint64 seed1,
Uint64 seed2)
501void SpookyHashAlgorithmImp::end(
503 Uint64 &h0, Uint64 &h1, Uint64 &h2, Uint64 &h3,
504 Uint64 &h4, Uint64 &h5, Uint64 &h6, Uint64 &h7,
505 Uint64 &h8, Uint64 &h9, Uint64 &h10,Uint64 &h11)
508 h0 += data[0]; h1 += data[1]; h2 += data[2]; h3 += data[3];
509 h4 += data[4]; h5 += data[5]; h6 += data[6]; h7 += data[7];
510 h8 += data[8]; h9 += data[9]; h10 += data[10]; h11 += data[11];
511 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
512 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
513 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
517void SpookyHashAlgorithmImp::endPartial(
518 Uint64 &h0, Uint64 &h1, Uint64 &h2, Uint64 &h3,
519 Uint64 &h4, Uint64 &h5, Uint64 &h6, Uint64 &h7,
520 Uint64 &h8, Uint64 &h9, Uint64 &h10,Uint64 &h11)
522 h11+= h1; h2 ^= h11; h1 = rot64(h1,44);
523 h0 += h2; h3 ^= h0; h2 = rot64(h2,15);
524 h1 += h3; h4 ^= h1; h3 = rot64(h3,34);
525 h2 += h4; h5 ^= h2; h4 = rot64(h4,21);
526 h3 += h5; h6 ^= h3; h5 = rot64(h5,38);
527 h4 += h6; h7 ^= h4; h6 = rot64(h6,33);
528 h5 += h7; h8 ^= h5; h7 = rot64(h7,10);
529 h6 += h8; h9 ^= h6; h8 = rot64(h8,13);
530 h7 += h9; h10^= h7; h9 = rot64(h9,38);
531 h8 += h10; h11^= h8; h10= rot64(h10,53);
532 h9 += h11; h0 ^= h9; h11= rot64(h11,42);
533 h10+= h0; h1 ^= h10; h0 = rot64(h0,54);
537void SpookyHashAlgorithmImp::mix(
539 Uint64 &s0, Uint64 &s1, Uint64 &s2, Uint64 &s3,
540 Uint64 &s4, Uint64 &s5, Uint64 &s6, Uint64 &s7,
541 Uint64 &s8, Uint64 &s9, Uint64 &s10,Uint64 &s11)
544 s0 +=
data[0]; s2 ^= s10; s11 ^= s0; s0 = rot64(s0,11); s11 += s1;
545 s1 +=
data[1]; s3 ^= s11; s0 ^= s1; s1 = rot64(s1,32); s0 += s2;
546 s2 +=
data[2]; s4 ^= s0; s1 ^= s2; s2 = rot64(s2,43); s1 += s3;
547 s3 +=
data[3]; s5 ^= s1; s2 ^= s3; s3 = rot64(s3,31); s2 += s4;
548 s4 +=
data[4]; s6 ^= s2; s3 ^= s4; s4 = rot64(s4,17); s3 += s5;
549 s5 +=
data[5]; s7 ^= s3; s4 ^= s5; s5 = rot64(s5,28); s4 += s6;
550 s6 +=
data[6]; s8 ^= s4; s5 ^= s6; s6 = rot64(s6,39); s5 += s7;
551 s7 +=
data[7]; s9 ^= s5; s6 ^= s7; s7 = rot64(s7,57); s6 += s8;
552 s8 +=
data[8]; s10 ^= s6; s7 ^= s8; s8 = rot64(s8,55); s7 += s9;
553 s9 +=
data[9]; s11 ^= s7; s8 ^= s9; s9 = rot64(s9,54); s8 += s10;
554 s10 +=
data[10]; s0 ^= s8; s9 ^= s10; s10 = rot64(s10,22); s9 += s11;
555 s11 +=
data[11]; s1 ^= s9; s10 ^= s11; s11 = rot64(s11,46); s10 += s0;
561 return (x << k) | (x >> (64 - k));
565void SpookyHashAlgorithmImp::shortEnd(Uint64 &h0,
570 h3 ^= h2; h2 = rot64(h2,15); h3 += h2;
571 h0 ^= h3; h3 = rot64(h3,52); h0 += h3;
572 h1 ^= h0; h0 = rot64(h0,26); h1 += h0;
573 h2 ^= h1; h1 = rot64(h1,51); h2 += h1;
574 h3 ^= h2; h2 = rot64(h2,28); h3 += h2;
575 h0 ^= h3; h3 = rot64(h3,9); h0 += h3;
576 h1 ^= h0; h0 = rot64(h0,47); h1 += h0;
577 h2 ^= h1; h1 = rot64(h1,54); h2 += h1;
578 h3 ^= h2; h2 = rot64(h2,32); h3 += h2;
579 h0 ^= h3; h3 = rot64(h3,25); h0 += h3;
580 h1 ^= h0; h0 = rot64(h0,63); h1 += h0;
584void SpookyHashAlgorithmImp::shortMix(Uint64 &h0,
589 h2 = rot64(h2,50); h2 += h3; h0 ^= h2;
590 h3 = rot64(h3,52); h3 += h0; h1 ^= h3;
591 h0 = rot64(h0,30); h0 += h1; h2 ^= h0;
592 h1 = rot64(h1,41); h1 += h2; h3 ^= h1;
593 h2 = rot64(h2,54); h2 += h3; h0 ^= h2;
594 h3 = rot64(h3,48); h3 += h0; h1 ^= h3;
595 h0 = rot64(h0,38); h0 += h1; h2 ^= h0;
596 h1 = rot64(h1,37); h1 += h2; h3 ^= h1;
597 h2 = rot64(h2,62); h2 += h3; h0 ^= h2;
598 h3 = rot64(h3,34); h3 += h0; h1 ^= h3;
599 h0 = rot64(h0,5); h0 += h1; h2 ^= h0;
600 h1 = rot64(h1,36); h1 += h2; h3 ^= h1;
607#undef BSLH_SPOOKYHASHALGORITHMIMP_INLINE
Definition bslh_spookyhashalgorithmimp.h:291
static Uint64 hash64(const void *message, size_t length, Uint64 seed)
Definition bslh_spookyhashalgorithmimp.h:478
unsigned int Uint32
Definition bslh_spookyhashalgorithmimp.h:295
void update(const void *message, size_t length)
bsls::Types::Uint64 Uint64
Definition bslh_spookyhashalgorithmimp.h:294
unsigned char Uint8
Definition bslh_spookyhashalgorithmimp.h:297
~SpookyHashAlgorithmImp()=default
static Uint32 hash32(const void *message, size_t length, Uint32 seed)
Definition bslh_spookyhashalgorithmimp.h:466
static void hash128(const void *message, size_t length, Uint64 *hash1, Uint64 *hash2)
unsigned short Uint16
Definition bslh_spookyhashalgorithmimp.h:296
void finalize(Uint64 *hash1, Uint64 *hash2)
#define BSLH_SPOOKYHASHALGORITHMIMP_INLINE
See implementation notes for the explanation of this macro.
Definition bslh_spookyhashalgorithmimp.h:278
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1231
Definition bslh_defaulthashalgorithm.h:339
unsigned long long Uint64
Definition bsls_types.h:137