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];
331 static void end(
const Uint64 *data,
359 static void mix(
const Uint64 *data,
376 static void shortHash(
const void *message,
400 SpookyHashAlgorithmImp(
const SpookyHashAlgorithmImp& original);
402 SpookyHashAlgorithmImp& operator=(
const SpookyHashAlgorithmImp& rhs);
459 void update(
const void *message,
size_t length);
488 Uint64 hash1 = seed, hash2 = seed;
489 hash128(message, length, &hash1, &hash2);
490 return static_cast<Uint32>(hash1);
501 hash128(message, length, &hash1, &seed);
507SpookyHashAlgorithmImp::SpookyHashAlgorithmImp(
Uint64 seed1,
Uint64 seed2)
517void SpookyHashAlgorithmImp::end(
519 Uint64 &h0, Uint64 &h1, Uint64 &h2, Uint64 &h3,
520 Uint64 &h4, Uint64 &h5, Uint64 &h6, Uint64 &h7,
521 Uint64 &h8, Uint64 &h9, Uint64 &h10,Uint64 &h11)
524 h0 += data[0]; h1 += data[1]; h2 += data[2]; h3 += data[3];
525 h4 += data[4]; h5 += data[5]; h6 += data[6]; h7 += data[7];
526 h8 += data[8]; h9 += data[9]; h10 += data[10]; h11 += data[11];
527 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
528 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
529 endPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
533void SpookyHashAlgorithmImp::endPartial(
534 Uint64 &h0, Uint64 &h1, Uint64 &h2, Uint64 &h3,
535 Uint64 &h4, Uint64 &h5, Uint64 &h6, Uint64 &h7,
536 Uint64 &h8, Uint64 &h9, Uint64 &h10,Uint64 &h11)
538 h11+= h1; h2 ^= h11; h1 = rot64(h1,44);
539 h0 += h2; h3 ^= h0; h2 = rot64(h2,15);
540 h1 += h3; h4 ^= h1; h3 = rot64(h3,34);
541 h2 += h4; h5 ^= h2; h4 = rot64(h4,21);
542 h3 += h5; h6 ^= h3; h5 = rot64(h5,38);
543 h4 += h6; h7 ^= h4; h6 = rot64(h6,33);
544 h5 += h7; h8 ^= h5; h7 = rot64(h7,10);
545 h6 += h8; h9 ^= h6; h8 = rot64(h8,13);
546 h7 += h9; h10^= h7; h9 = rot64(h9,38);
547 h8 += h10; h11^= h8; h10= rot64(h10,53);
548 h9 += h11; h0 ^= h9; h11= rot64(h11,42);
549 h10+= h0; h1 ^= h10; h0 = rot64(h0,54);
553void SpookyHashAlgorithmImp::mix(
555 Uint64 &s0, Uint64 &s1, Uint64 &s2, Uint64 &s3,
556 Uint64 &s4, Uint64 &s5, Uint64 &s6, Uint64 &s7,
557 Uint64 &s8, Uint64 &s9, Uint64 &s10,Uint64 &s11)
560 s0 +=
data[0]; s2 ^= s10; s11 ^= s0; s0 = rot64(s0,11); s11 += s1;
561 s1 +=
data[1]; s3 ^= s11; s0 ^= s1; s1 = rot64(s1,32); s0 += s2;
562 s2 +=
data[2]; s4 ^= s0; s1 ^= s2; s2 = rot64(s2,43); s1 += s3;
563 s3 +=
data[3]; s5 ^= s1; s2 ^= s3; s3 = rot64(s3,31); s2 += s4;
564 s4 +=
data[4]; s6 ^= s2; s3 ^= s4; s4 = rot64(s4,17); s3 += s5;
565 s5 +=
data[5]; s7 ^= s3; s4 ^= s5; s5 = rot64(s5,28); s4 += s6;
566 s6 +=
data[6]; s8 ^= s4; s5 ^= s6; s6 = rot64(s6,39); s5 += s7;
567 s7 +=
data[7]; s9 ^= s5; s6 ^= s7; s7 = rot64(s7,57); s6 += s8;
568 s8 +=
data[8]; s10 ^= s6; s7 ^= s8; s8 = rot64(s8,55); s7 += s9;
569 s9 +=
data[9]; s11 ^= s7; s8 ^= s9; s9 = rot64(s9,54); s8 += s10;
570 s10 +=
data[10]; s0 ^= s8; s9 ^= s10; s10 = rot64(s10,22); s9 += s11;
571 s11 +=
data[11]; s1 ^= s9; s10 ^= s11; s11 = rot64(s11,46); s10 += s0;
577 return (x << k) | (x >> (64 - k));
581void SpookyHashAlgorithmImp::shortEnd(Uint64 &h0,
586 h3 ^= h2; h2 = rot64(h2,15); h3 += h2;
587 h0 ^= h3; h3 = rot64(h3,52); h0 += h3;
588 h1 ^= h0; h0 = rot64(h0,26); h1 += h0;
589 h2 ^= h1; h1 = rot64(h1,51); h2 += h1;
590 h3 ^= h2; h2 = rot64(h2,28); h3 += h2;
591 h0 ^= h3; h3 = rot64(h3,9); h0 += h3;
592 h1 ^= h0; h0 = rot64(h0,47); h1 += h0;
593 h2 ^= h1; h1 = rot64(h1,54); h2 += h1;
594 h3 ^= h2; h2 = rot64(h2,32); h3 += h2;
595 h0 ^= h3; h3 = rot64(h3,25); h0 += h3;
596 h1 ^= h0; h0 = rot64(h0,63); h1 += h0;
600void SpookyHashAlgorithmImp::shortMix(Uint64 &h0,
605 h2 = rot64(h2,50); h2 += h3; h0 ^= h2;
606 h3 = rot64(h3,52); h3 += h0; h1 ^= h3;
607 h0 = rot64(h0,30); h0 += h1; h2 ^= h0;
608 h1 = rot64(h1,41); h1 += h2; h3 ^= h1;
609 h2 = rot64(h2,54); h2 += h3; h0 ^= h2;
610 h3 = rot64(h3,48); h3 += h0; h1 ^= h3;
611 h0 = rot64(h0,38); h0 += h1; h2 ^= h0;
612 h1 = rot64(h1,37); h1 += h2; h3 ^= h1;
613 h2 = rot64(h2,62); h2 += h3; h0 ^= h2;
614 h3 = rot64(h3,34); h3 += h0; h1 ^= h3;
615 h0 = rot64(h0,5); h0 += h1; h2 ^= h0;
616 h1 = rot64(h1,36); h1 += h2; h3 ^= h1;
623#undef BSLH_SPOOKYHASHALGORITHMIMP_INLINE
Definition bslh_spookyhashalgorithmimp.h:291
static Uint64 hash64(const void *message, size_t length, Uint64 seed)
Definition bslh_spookyhashalgorithmimp.h:494
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:482
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:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1325
Definition bslh_defaulthashalgorithm.h:339
unsigned long long Uint64
Definition bsls_types.h:139