proxygen
folly::hash::SpookyHashV1 Class Reference

#include <SpookyHashV1.h>

Public Member Functions

void Init (uint64_t seed1, uint64_t seed2)
 
void Update (const void *message, size_t length)
 
void Final (uint64_t *hash1, uint64_t *hash2)
 

Static Public Member Functions

static void Hash128 (const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
 
static uint64_t Hash64 (const void *message, size_t length, uint64_t seed)
 
static uint32_t Hash32 (const void *message, size_t length, uint32_t seed)
 
static uint64_t Rot64 (uint64_t x, int k)
 
static void Mix (const uint64_t *data, uint64_t &s0, uint64_t &s1, uint64_t &s2, uint64_t &s3, uint64_t &s4, uint64_t &s5, uint64_t &s6, uint64_t &s7, uint64_t &s8, uint64_t &s9, uint64_t &s10, uint64_t &s11)
 
static void EndPartial (uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3, uint64_t &h4, uint64_t &h5, uint64_t &h6, uint64_t &h7, uint64_t &h8, uint64_t &h9, uint64_t &h10, uint64_t &h11)
 
static void End (uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3, uint64_t &h4, uint64_t &h5, uint64_t &h6, uint64_t &h7, uint64_t &h8, uint64_t &h9, uint64_t &h10, uint64_t &h11)
 
static void ShortMix (uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3)
 
static void ShortEnd (uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3)
 

Static Private Member Functions

static void Short (const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
 

Private Attributes

uint64_t m_data [2 *sc_numVars]
 
uint64_t m_state [sc_numVars]
 
size_t m_length
 
uint8_t m_remainder
 

Static Private Attributes

static const size_t sc_numVars = 12
 
static const size_t sc_blockSize = sc_numVars*8
 
static const size_t sc_bufSize = 2*sc_blockSize
 
static const uint64_t sc_const = 0xdeadbeefdeadbeefULL
 

Detailed Description

Definition at line 55 of file SpookyHashV1.h.

Member Function Documentation

static void folly::hash::SpookyHashV1::End ( uint64_t h0,
uint64_t h1,
uint64_t h2,
uint64_t h3,
uint64_t h4,
uint64_t h5,
uint64_t h6,
uint64_t h7,
uint64_t h8,
uint64_t h9,
uint64_t h10,
uint64_t h11 
)
inlinestatic

Definition at line 196 of file SpookyHashV1.h.

References EndPartial().

Referenced by Final(), and Hash128().

200  {
201  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
202  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
203  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
204  }
static void EndPartial(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3, uint64_t &h4, uint64_t &h5, uint64_t &h6, uint64_t &h7, uint64_t &h8, uint64_t &h9, uint64_t &h10, uint64_t &h11)
Definition: SpookyHashV1.h:177
static void folly::hash::SpookyHashV1::EndPartial ( uint64_t h0,
uint64_t h1,
uint64_t h2,
uint64_t h3,
uint64_t h4,
uint64_t h5,
uint64_t h6,
uint64_t h7,
uint64_t h8,
uint64_t h9,
uint64_t h10,
uint64_t h11 
)
inlinestatic

Definition at line 177 of file SpookyHashV1.h.

References Rot64().

Referenced by End().

181  {
182  h11+= h1; h2 ^= h11; h1 = Rot64(h1,44);
183  h0 += h2; h3 ^= h0; h2 = Rot64(h2,15);
184  h1 += h3; h4 ^= h1; h3 = Rot64(h3,34);
185  h2 += h4; h5 ^= h2; h4 = Rot64(h4,21);
186  h3 += h5; h6 ^= h3; h5 = Rot64(h5,38);
187  h4 += h6; h7 ^= h4; h6 = Rot64(h6,33);
188  h5 += h7; h8 ^= h5; h7 = Rot64(h7,10);
189  h6 += h8; h9 ^= h6; h8 = Rot64(h8,13);
190  h7 += h9; h10^= h7; h9 = Rot64(h9,38);
191  h8 += h10; h11^= h8; h10= Rot64(h10,53);
192  h9 += h11; h0 ^= h9; h11= Rot64(h11,42);
193  h10+= h0; h1 ^= h10; h0 = Rot64(h0,54);
194  }
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV1.h:123
void folly::hash::SpookyHashV1::Final ( uint64_t hash1,
uint64_t hash2 
)

Definition at line 340 of file SpookyHashV1.cpp.

References folly::data(), End(), m_data, m_length, m_remainder, m_state, Mix(), sc_blockSize, sc_bufSize, sc_numVars, Short(), uint64_t, and uint8_t.

Referenced by Hash32().

341 {
342  // init the variables
343  if (m_length < sc_bufSize)
344  {
345  *hash1 = m_state[0];
346  *hash2 = m_state[1];
347  Short( m_data, m_length, hash1, hash2);
348  return;
349  }
350 
351  const uint64_t *data = (const uint64_t *)m_data;
352  uint8_t remainder = m_remainder;
353 
354  uint64_t h0 = m_state[0];
355  uint64_t h1 = m_state[1];
356  uint64_t h2 = m_state[2];
357  uint64_t h3 = m_state[3];
358  uint64_t h4 = m_state[4];
359  uint64_t h5 = m_state[5];
360  uint64_t h6 = m_state[6];
361  uint64_t h7 = m_state[7];
362  uint64_t h8 = m_state[8];
363  uint64_t h9 = m_state[9];
364  uint64_t h10 = m_state[10];
365  uint64_t h11 = m_state[11];
366 
367  if (remainder >= sc_blockSize)
368  {
369  // m_data can contain two blocks; handle any whole first block
370  Mix(data, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
371  data += sc_numVars;
372  remainder -= sc_blockSize;
373  }
374 
375  // mix in the last partial block, and the length mod sc_blockSize
376  memset(&((uint8_t *)data)[remainder], 0, (sc_blockSize-remainder));
377 
378  ((uint8_t *)data)[sc_blockSize-1] = remainder;
379  Mix(data, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
380 
381  // do some final mixing
382  End(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
383 
384  *hash1 = h0;
385  *hash2 = h1;
386 }
static const size_t sc_numVars
Definition: SpookyHashV1.h:281
static void Mix(const uint64_t *data, uint64_t &s0, uint64_t &s1, uint64_t &s2, uint64_t &s3, uint64_t &s4, uint64_t &s5, uint64_t &s6, uint64_t &s7, uint64_t &s8, uint64_t &s9, uint64_t &s10, uint64_t &s11)
Definition: SpookyHashV1.h:141
uint64_t m_state[sc_numVars]
Definition: SpookyHashV1.h:299
uint64_t m_data[2 *sc_numVars]
Definition: SpookyHashV1.h:298
static const size_t sc_bufSize
Definition: SpookyHashV1.h:287
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static const size_t sc_blockSize
Definition: SpookyHashV1.h:284
static void Short(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
static void End(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3, uint64_t &h4, uint64_t &h5, uint64_t &h6, uint64_t &h7, uint64_t &h8, uint64_t &h9, uint64_t &h10, uint64_t &h11)
Definition: SpookyHashV1.h:196
void folly::hash::SpookyHashV1::Hash128 ( const void *  message,
size_t  length,
uint64_t hash1,
uint64_t hash2 
)
static

Definition at line 161 of file SpookyHashV1.cpp.

References ALLOW_UNALIGNED_READS, folly::test::end(), End(), i, message, Mix(), sc_blockSize, sc_bufSize, sc_const, sc_numVars, Short(), uint64_t, and uint8_t.

Referenced by Hash32(), and Hash64().

166 {
167  if (length < sc_bufSize)
168  {
169  Short(message, length, hash1, hash2);
170  return;
171  }
172 
173  uint64_t h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11;
174  uint64_t buf[sc_numVars];
175  uint64_t *end;
176  union
177  {
178  const uint8_t *p8;
179  uint64_t *p64;
180  size_t i;
181  } u;
182  size_t remainder;
183 
184  h0=h3=h6=h9 = *hash1;
185  h1=h4=h7=h10 = *hash2;
186  h2=h5=h8=h11 = sc_const;
187 
188  u.p8 = (const uint8_t *)message;
189  end = u.p64 + (length/sc_blockSize)*sc_numVars;
190 
191  // handle all whole sc_blockSize blocks of bytes
192  if (ALLOW_UNALIGNED_READS || ((u.i & 0x7) == 0))
193  {
194  while (u.p64 < end)
195  {
196  Mix(u.p64, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
197  u.p64 += sc_numVars;
198  }
199  }
200  else
201  {
202  while (u.p64 < end)
203  {
204  memcpy(buf, u.p64, sc_blockSize);
205  Mix(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
206  u.p64 += sc_numVars;
207  }
208  }
209 
210  // handle the last partial block of sc_blockSize bytes
211  remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
212  memcpy(buf, end, remainder);
213  memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
214  ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
215  Mix(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
216 
217  // do some final mixing
218  End(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
219  *hash1 = h0;
220  *hash2 = h1;
221 }
Definition: test.c:42
static const size_t sc_numVars
Definition: SpookyHashV1.h:281
static void Mix(const uint64_t *data, uint64_t &s0, uint64_t &s1, uint64_t &s2, uint64_t &s3, uint64_t &s4, uint64_t &s5, uint64_t &s6, uint64_t &s7, uint64_t &s8, uint64_t &s9, uint64_t &s10, uint64_t &s11)
Definition: SpookyHashV1.h:141
static const uint64_t sc_const
Definition: SpookyHashV1.h:296
#define ALLOW_UNALIGNED_READS
static const size_t sc_bufSize
Definition: SpookyHashV1.h:287
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
static const size_t sc_blockSize
Definition: SpookyHashV1.h:284
static void Short(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
static void End(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3, uint64_t &h4, uint64_t &h5, uint64_t &h6, uint64_t &h7, uint64_t &h8, uint64_t &h9, uint64_t &h10, uint64_t &h11)
Definition: SpookyHashV1.h:196
static uint32_t folly::hash::SpookyHashV1::Hash32 ( const void *  message,
size_t  length,
uint32_t  seed 
)
inlinestatic

Definition at line 83 of file SpookyHashV1.h.

References Final(), Hash128(), Init(), seed, uint32_t, uint64_t, and Update().

87  {
88  uint64_t hash1 = seed, hash2 = seed;
89  Hash128(message, length, &hash1, &hash2);
90  return (uint32_t)hash1;
91  }
Definition: test.c:42
static const int seed
static void Hash128(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
static uint64_t folly::hash::SpookyHashV1::Hash64 ( const void *  message,
size_t  length,
uint64_t  seed 
)
inlinestatic

Definition at line 70 of file SpookyHashV1.h.

References Hash128(), seed, and uint64_t.

74  {
75  uint64_t hash1 = seed;
76  Hash128(message, length, &hash1, &seed);
77  return hash1;
78  }
Definition: test.c:42
static const int seed
static void Hash128(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
void folly::hash::SpookyHashV1::Init ( uint64_t  seed1,
uint64_t  seed2 
)

Definition at line 226 of file SpookyHashV1.cpp.

References m_length, m_remainder, and m_state.

Referenced by Hash32().

227 {
228  m_length = 0;
229  m_remainder = 0;
230  m_state[0] = seed1;
231  m_state[1] = seed2;
232 }
uint64_t m_state[sc_numVars]
Definition: SpookyHashV1.h:299
static void folly::hash::SpookyHashV1::Mix ( const uint64_t data,
uint64_t s0,
uint64_t s1,
uint64_t s2,
uint64_t s3,
uint64_t s4,
uint64_t s5,
uint64_t s6,
uint64_t s7,
uint64_t s8,
uint64_t s9,
uint64_t s10,
uint64_t s11 
)
inlinestatic

Definition at line 141 of file SpookyHashV1.h.

References Rot64().

Referenced by Final(), Hash128(), and Update().

146  {
147  s0 += data[0]; s2 ^= s10; s11 ^= s0; s0 = Rot64(s0,11); s11 += s1;
148  s1 += data[1]; s3 ^= s11; s0 ^= s1; s1 = Rot64(s1,32); s0 += s2;
149  s2 += data[2]; s4 ^= s0; s1 ^= s2; s2 = Rot64(s2,43); s1 += s3;
150  s3 += data[3]; s5 ^= s1; s2 ^= s3; s3 = Rot64(s3,31); s2 += s4;
151  s4 += data[4]; s6 ^= s2; s3 ^= s4; s4 = Rot64(s4,17); s3 += s5;
152  s5 += data[5]; s7 ^= s3; s4 ^= s5; s5 = Rot64(s5,28); s4 += s6;
153  s6 += data[6]; s8 ^= s4; s5 ^= s6; s6 = Rot64(s6,39); s5 += s7;
154  s7 += data[7]; s9 ^= s5; s6 ^= s7; s7 = Rot64(s7,57); s6 += s8;
155  s8 += data[8]; s10 ^= s6; s7 ^= s8; s8 = Rot64(s8,55); s7 += s9;
156  s9 += data[9]; s11 ^= s7; s8 ^= s9; s9 = Rot64(s9,54); s8 += s10;
157  s10 += data[10]; s0 ^= s8; s9 ^= s10; s10 = Rot64(s10,22); s9 += s11;
158  s11 += data[11]; s1 ^= s9; s10 ^= s11; s11 = Rot64(s11,46); s10 += s0;
159  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV1.h:123
static uint64_t folly::hash::SpookyHashV1::Rot64 ( uint64_t  x,
int  k 
)
inlinestatic

Definition at line 123 of file SpookyHashV1.h.

References k.

Referenced by EndPartial(), Mix(), ShortEnd(), and ShortMix().

124  {
125  return (x << k) | (x >> (64 - k));
126  }
Definition: InvokeTest.cpp:58
KeyT k
void folly::hash::SpookyHashV1::Short ( const void *  message,
size_t  length,
uint64_t hash1,
uint64_t hash2 
)
staticprivate

Definition at line 44 of file SpookyHashV1.cpp.

References a, ALLOW_UNALIGNED_READS, b, c, folly::test::end(), FOLLY_FALLTHROUGH, i, sc_const, sc_numVars, ShortEnd(), ShortMix(), uint32_t, uint64_t, and uint8_t.

Referenced by Final(), Hash128(), and ShortEnd().

49 {
50  uint64_t buf[2*sc_numVars];
51  union
52  {
53  const uint8_t *p8;
54  uint32_t *p32;
55  uint64_t *p64;
56  size_t i;
57  } u;
58 
59  u.p8 = (const uint8_t *)message;
60 
61  if (!ALLOW_UNALIGNED_READS && (u.i & 0x7))
62  {
63  memcpy(buf, message, length);
64  u.p64 = buf;
65  }
66 
67  size_t remainder = length%32;
68  uint64_t a=*hash1;
69  uint64_t b=*hash2;
72 
73  if (length > 15)
74  {
75  const uint64_t *end = u.p64 + (length/32)*4;
76 
77  // handle all complete sets of 32 bytes
78  for (; u.p64 < end; u.p64 += 4)
79  {
80  c += u.p64[0];
81  d += u.p64[1];
82  ShortMix(a,b,c,d);
83  a += u.p64[2];
84  b += u.p64[3];
85  }
86 
87  //Handle the case of 16+ remaining bytes.
88  if (remainder >= 16)
89  {
90  c += u.p64[0];
91  d += u.p64[1];
92  ShortMix(a,b,c,d);
93  u.p64 += 2;
94  remainder -= 16;
95  }
96  }
97 
98  // Handle the last 0..15 bytes, and its length
99  d = ((uint64_t)length) << 56;
100  switch (remainder)
101  {
102  case 15:
103  d += ((uint64_t)u.p8[14]) << 48;
105  case 14:
106  d += ((uint64_t)u.p8[13]) << 40;
108  case 13:
109  d += ((uint64_t)u.p8[12]) << 32;
111  case 12:
112  d += u.p32[2];
113  c += u.p64[0];
114  break;
115  case 11:
116  d += ((uint64_t)u.p8[10]) << 16;
118  case 10:
119  d += ((uint64_t)u.p8[9]) << 8;
121  case 9:
122  d += (uint64_t)u.p8[8];
124  case 8:
125  c += u.p64[0];
126  break;
127  case 7:
128  c += ((uint64_t)u.p8[6]) << 48;
130  case 6:
131  c += ((uint64_t)u.p8[5]) << 40;
133  case 5:
134  c += ((uint64_t)u.p8[4]) << 32;
136  case 4:
137  c += u.p32[0];
138  break;
139  case 3:
140  c += ((uint64_t)u.p8[2]) << 16;
142  case 2:
143  c += ((uint64_t)u.p8[1]) << 8;
145  case 1:
146  c += (uint64_t)u.p8[0];
147  break;
148  case 0:
149  c += sc_const;
150  d += sc_const;
151  }
152  ShortEnd(a,b,c,d);
153  *hash1 = a;
154  *hash2 = b;
155 }
Definition: test.c:42
static const size_t sc_numVars
Definition: SpookyHashV1.h:281
char b
static const uint64_t sc_const
Definition: SpookyHashV1.h:296
#define ALLOW_UNALIGNED_READS
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
char a
static void ShortEnd(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3)
Definition: SpookyHashV1.h:250
char c
static void ShortMix(uint64_t &h0, uint64_t &h1, uint64_t &h2, uint64_t &h3)
Definition: SpookyHashV1.h:221
#define FOLLY_FALLTHROUGH
Definition: CppAttributes.h:63
static void folly::hash::SpookyHashV1::ShortEnd ( uint64_t h0,
uint64_t h1,
uint64_t h2,
uint64_t h3 
)
inlinestatic

Definition at line 250 of file SpookyHashV1.h.

References Rot64(), Short(), and uint64_t.

Referenced by Short().

252  {
253  h3 ^= h2; h2 = Rot64(h2,15); h3 += h2;
254  h0 ^= h3; h3 = Rot64(h3,52); h0 += h3;
255  h1 ^= h0; h0 = Rot64(h0,26); h1 += h0;
256  h2 ^= h1; h1 = Rot64(h1,51); h2 += h1;
257  h3 ^= h2; h2 = Rot64(h2,28); h3 += h2;
258  h0 ^= h3; h3 = Rot64(h3,9); h0 += h3;
259  h1 ^= h0; h0 = Rot64(h0,47); h1 += h0;
260  h2 ^= h1; h1 = Rot64(h1,54); h2 += h1;
261  h3 ^= h2; h2 = Rot64(h2,32); h3 += h2;
262  h0 ^= h3; h3 = Rot64(h3,25); h0 += h3;
263  h1 ^= h0; h0 = Rot64(h0,63); h1 += h0;
264  }
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV1.h:123
static void folly::hash::SpookyHashV1::ShortMix ( uint64_t h0,
uint64_t h1,
uint64_t h2,
uint64_t h3 
)
inlinestatic

Definition at line 221 of file SpookyHashV1.h.

References Rot64().

Referenced by Short().

223  {
224  h2 = Rot64(h2,50); h2 += h3; h0 ^= h2;
225  h3 = Rot64(h3,52); h3 += h0; h1 ^= h3;
226  h0 = Rot64(h0,30); h0 += h1; h2 ^= h0;
227  h1 = Rot64(h1,41); h1 += h2; h3 ^= h1;
228  h2 = Rot64(h2,54); h2 += h3; h0 ^= h2;
229  h3 = Rot64(h3,48); h3 += h0; h1 ^= h3;
230  h0 = Rot64(h0,38); h0 += h1; h2 ^= h0;
231  h1 = Rot64(h1,37); h1 += h2; h3 ^= h1;
232  h2 = Rot64(h2,62); h2 += h3; h0 ^= h2;
233  h3 = Rot64(h3,34); h3 += h0; h1 ^= h3;
234  h0 = Rot64(h0,5); h0 += h1; h2 ^= h0;
235  h1 = Rot64(h1,36); h1 += h2; h3 ^= h1;
236  }
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV1.h:123
void folly::hash::SpookyHashV1::Update ( const void *  message,
size_t  length 
)

Definition at line 236 of file SpookyHashV1.cpp.

References ALLOW_UNALIGNED_READS, folly::test::end(), i, m_data, m_length, m_remainder, m_state, Mix(), prefix(), sc_blockSize, sc_bufSize, sc_const, sc_numVars, uint64_t, and uint8_t.

Referenced by Hash32().

237 {
238  uint64_t h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11;
239  size_t newLength = length + m_remainder;
240  uint8_t remainder;
241  union
242  {
243  const uint8_t *p8;
244  uint64_t *p64;
245  size_t i;
246  } u;
247  const uint64_t *end;
248 
249  // Is this message fragment too short? If it is, stuff it away.
250  if (newLength < sc_bufSize)
251  {
252  memcpy(&((uint8_t *)m_data)[m_remainder], message, length);
253  m_length = length + m_length;
254  m_remainder = (uint8_t)newLength;
255  return;
256  }
257 
258  // init the variables
259  if (m_length < sc_bufSize)
260  {
261  h0=h3=h6=h9 = m_state[0];
262  h1=h4=h7=h10 = m_state[1];
263  h2=h5=h8=h11 = sc_const;
264  }
265  else
266  {
267  h0 = m_state[0];
268  h1 = m_state[1];
269  h2 = m_state[2];
270  h3 = m_state[3];
271  h4 = m_state[4];
272  h5 = m_state[5];
273  h6 = m_state[6];
274  h7 = m_state[7];
275  h8 = m_state[8];
276  h9 = m_state[9];
277  h10 = m_state[10];
278  h11 = m_state[11];
279  }
280  m_length = length + m_length;
281 
282  // if we've got anything stuffed away, use it now
283  if (m_remainder)
284  {
286  memcpy(&(((uint8_t *)m_data)[m_remainder]), message, prefix);
287  u.p64 = m_data;
288  Mix(u.p64, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
289  Mix(&u.p64[sc_numVars], h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
290  u.p8 = ((const uint8_t *)message) + prefix;
291  length -= prefix;
292  }
293  else
294  {
295  u.p8 = (const uint8_t *)message;
296  }
297 
298  // handle all whole blocks of sc_blockSize bytes
299  end = u.p64 + (length/sc_blockSize)*sc_numVars;
300  remainder = (uint8_t)(length-((const uint8_t *)end-u.p8));
301  if (ALLOW_UNALIGNED_READS || (u.i & 0x7) == 0)
302  {
303  while (u.p64 < end)
304  {
305  Mix(u.p64, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
306  u.p64 += sc_numVars;
307  }
308  }
309  else
310  {
311  while (u.p64 < end)
312  {
313  memcpy(m_data, u.p8, sc_blockSize);
314  Mix(m_data, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
315  u.p64 += sc_numVars;
316  }
317  }
318 
319  // stuff away the last few bytes
320  m_remainder = remainder;
321  memcpy(m_data, end, remainder);
322 
323  // stuff away the variables
324  m_state[0] = h0;
325  m_state[1] = h1;
326  m_state[2] = h2;
327  m_state[3] = h3;
328  m_state[4] = h4;
329  m_state[5] = h5;
330  m_state[6] = h6;
331  m_state[7] = h7;
332  m_state[8] = h8;
333  m_state[9] = h9;
334  m_state[10] = h10;
335  m_state[11] = h11;
336 }
Definition: test.c:42
static const size_t sc_numVars
Definition: SpookyHashV1.h:281
static void Mix(const uint64_t *data, uint64_t &s0, uint64_t &s1, uint64_t &s2, uint64_t &s3, uint64_t &s4, uint64_t &s5, uint64_t &s6, uint64_t &s7, uint64_t &s8, uint64_t &s9, uint64_t &s10, uint64_t &s11)
Definition: SpookyHashV1.h:141
static const uint64_t sc_const
Definition: SpookyHashV1.h:296
uint64_t m_state[sc_numVars]
Definition: SpookyHashV1.h:299
bool prefix(Cursor &c, uint32_t expected)
uint64_t m_data[2 *sc_numVars]
Definition: SpookyHashV1.h:298
#define ALLOW_UNALIGNED_READS
static const size_t sc_bufSize
Definition: SpookyHashV1.h:287
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
static const size_t sc_blockSize
Definition: SpookyHashV1.h:284

Member Data Documentation

uint64_t folly::hash::SpookyHashV1::m_data[2 *sc_numVars]
private

Definition at line 298 of file SpookyHashV1.h.

Referenced by Final(), and Update().

size_t folly::hash::SpookyHashV1::m_length
private

Definition at line 300 of file SpookyHashV1.h.

Referenced by Final(), Init(), and Update().

uint8_t folly::hash::SpookyHashV1::m_remainder
private

Definition at line 301 of file SpookyHashV1.h.

Referenced by Final(), Init(), and Update().

uint64_t folly::hash::SpookyHashV1::m_state[sc_numVars]
private

Definition at line 299 of file SpookyHashV1.h.

Referenced by Final(), Init(), and Update().

const size_t folly::hash::SpookyHashV1::sc_blockSize = sc_numVars*8
staticprivate

Definition at line 284 of file SpookyHashV1.h.

Referenced by Final(), Hash128(), and Update().

const size_t folly::hash::SpookyHashV1::sc_bufSize = 2*sc_blockSize
staticprivate

Definition at line 287 of file SpookyHashV1.h.

Referenced by Final(), Hash128(), and Update().

const uint64_t folly::hash::SpookyHashV1::sc_const = 0xdeadbeefdeadbeefULL
staticprivate

Definition at line 296 of file SpookyHashV1.h.

Referenced by Hash128(), Short(), and Update().

const size_t folly::hash::SpookyHashV1::sc_numVars = 12
staticprivate

Definition at line 281 of file SpookyHashV1.h.

Referenced by Final(), Hash128(), Short(), and Update().


The documentation for this class was generated from the following files: