proxygen
folly::hash::SpookyHashV2 Class Reference

#include <SpookyHashV2.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) const
 

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 (const uint64_t *data, 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 constexpr size_t sc_numVars = 12
 
static constexpr size_t sc_blockSize = sc_numVars*8
 
static constexpr size_t sc_bufSize = 2*sc_blockSize
 
static constexpr uint64_t sc_const = 0xdeadbeefdeadbeefULL
 

Detailed Description

Definition at line 56 of file SpookyHashV2.h.

Member Function Documentation

static void folly::hash::SpookyHashV2::End ( const uint64_t data,
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 197 of file SpookyHashV2.h.

References EndPartial().

Referenced by Final(), and Hash128().

202  {
203  h0 += data[0]; h1 += data[1]; h2 += data[2]; h3 += data[3];
204  h4 += data[4]; h5 += data[5]; h6 += data[6]; h7 += data[7];
205  h8 += data[8]; h9 += data[9]; h10 += data[10]; h11 += data[11];
206  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
207  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
208  EndPartial(h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
209  }
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
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: SpookyHashV2.h:178
static void folly::hash::SpookyHashV2::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 178 of file SpookyHashV2.h.

References Rot64().

Referenced by End().

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

Definition at line 340 of file SpookyHashV2.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 folly::RecordIOReader::Iterator::advanceToValid(), Hash32(), and folly::IOBufHash::operator()().

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  uint64_t buf[2*sc_numVars];
352  memcpy(buf, m_data, sizeof(buf));
353  uint64_t *data = buf;
354  uint8_t remainder = m_remainder;
355 
356  uint64_t h0 = m_state[0];
357  uint64_t h1 = m_state[1];
358  uint64_t h2 = m_state[2];
359  uint64_t h3 = m_state[3];
360  uint64_t h4 = m_state[4];
361  uint64_t h5 = m_state[5];
362  uint64_t h6 = m_state[6];
363  uint64_t h7 = m_state[7];
364  uint64_t h8 = m_state[8];
365  uint64_t h9 = m_state[9];
366  uint64_t h10 = m_state[10];
367  uint64_t h11 = m_state[11];
368 
369  if (remainder >= sc_blockSize)
370  {
371  // m_data can contain two blocks; handle any whole first block
372  Mix(data, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
373  data += sc_numVars;
374  remainder -= sc_blockSize;
375  }
376 
377  // mix in the last partial block, and the length mod sc_blockSize
378  memset(&((uint8_t *)data)[remainder], 0, (sc_blockSize-remainder));
379 
380  ((uint8_t *)data)[sc_blockSize-1] = remainder;
381 
382  // do some final mixing
383  End(data, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
384 
385  *hash1 = h0;
386  *hash2 = h1;
387 }
static void Short(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
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: SpookyHashV2.h:142
uint64_t m_state[sc_numVars]
Definition: SpookyHashV2.h:304
static constexpr size_t sc_blockSize
Definition: SpookyHashV2.h:289
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
static constexpr size_t sc_bufSize
Definition: SpookyHashV2.h:292
static constexpr size_t sc_numVars
Definition: SpookyHashV2.h:286
static void End(const uint64_t *data, 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: SpookyHashV2.h:197
uint64_t m_data[2 *sc_numVars]
Definition: SpookyHashV2.h:303
void folly::hash::SpookyHashV2::Hash128 ( const void *  message,
size_t  length,
uint64_t hash1,
uint64_t hash2 
)
static

Definition at line 162 of file SpookyHashV2.cpp.

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

Referenced by folly::IPAddressV6::hash(), Hash32(), and Hash64().

167 {
168  if (length < sc_bufSize)
169  {
170  Short(message, length, hash1, hash2);
171  return;
172  }
173 
174  uint64_t h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11;
175  uint64_t buf[sc_numVars];
176  uint64_t *end;
177  union
178  {
179  const uint8_t *p8;
180  uint64_t *p64;
181  size_t i;
182  } u;
183  size_t remainder;
184 
185  h0=h3=h6=h9 = *hash1;
186  h1=h4=h7=h10 = *hash2;
187  h2=h5=h8=h11 = sc_const;
188 
189  u.p8 = (const uint8_t *)message;
190  end = u.p64 + (length/sc_blockSize)*sc_numVars;
191 
192  // handle all whole sc_blockSize blocks of bytes
193  if (kHasUnalignedAccess || ((u.i & 0x7) == 0))
194  {
195  while (u.p64 < end)
196  {
197  Mix(u.p64, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
198  u.p64 += sc_numVars;
199  }
200  }
201  else
202  {
203  while (u.p64 < end)
204  {
205  memcpy(buf, u.p64, sc_blockSize);
206  Mix(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
207  u.p64 += sc_numVars;
208  }
209  }
210 
211  // handle the last partial block of sc_blockSize bytes
212  remainder = (length - ((const uint8_t *)end-(const uint8_t *)message));
213  memcpy(buf, end, remainder);
214  memset(((uint8_t *)buf)+remainder, 0, sc_blockSize-remainder);
215  ((uint8_t*)buf)[sc_blockSize - 1] = uint8_t(remainder);
216 
217  // do some final mixing
218  End(buf, h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11);
219  *hash1 = h0;
220  *hash2 = h1;
221 }
constexpr bool kHasUnalignedAccess
Definition: Portability.h:29
static void Short(const void *message, size_t length, uint64_t *hash1, uint64_t *hash2)
Definition: test.c:42
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: SpookyHashV2.h:142
static constexpr size_t sc_blockSize
Definition: SpookyHashV2.h:289
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
static constexpr size_t sc_bufSize
Definition: SpookyHashV2.h:292
static constexpr size_t sc_numVars
Definition: SpookyHashV2.h:286
static void End(const uint64_t *data, 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: SpookyHashV2.h:197
static constexpr uint64_t sc_const
Definition: SpookyHashV2.h:301
static uint32_t folly::hash::SpookyHashV2::Hash32 ( const void *  message,
size_t  length,
uint32_t  seed 
)
inlinestatic

Definition at line 84 of file SpookyHashV2.h.

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

Referenced by folly::RecordIOReader::Iterator::advanceToValid().

88  {
89  uint64_t hash1 = seed, hash2 = seed;
90  Hash128(message, length, &hash1, &hash2);
91  return (uint32_t)hash1;
92  }
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::SpookyHashV2::Hash64 ( const void *  message,
size_t  length,
uint64_t  seed 
)
inlinestatic

Definition at line 71 of file SpookyHashV2.h.

References Hash128(), seed, and uint64_t.

Referenced by folly::RecordIOReader::Iterator::advanceToValid(), detail::SpookyHashV2::operator()(), folly::hasher< std::string >::operator()(), and folly::exception_tracer::operator<<().

75  {
76  uint64_t hash1 = seed;
77  Hash128(message, length, &hash1, &seed);
78  return hash1;
79  }
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::SpookyHashV2::Init ( uint64_t  seed1,
uint64_t  seed2 
)

Definition at line 226 of file SpookyHashV2.cpp.

References m_length, m_remainder, and m_state.

Referenced by folly::RecordIOReader::Iterator::advanceToValid(), Hash32(), and folly::IOBufHash::operator()().

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: SpookyHashV2.h:304
static void folly::hash::SpookyHashV2::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 142 of file SpookyHashV2.h.

References Rot64().

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

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

Definition at line 124 of file SpookyHashV2.h.

References k.

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

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

Definition at line 45 of file SpookyHashV2.cpp.

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

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

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

Definition at line 255 of file SpookyHashV2.h.

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

Referenced by Short().

257  {
258  h3 ^= h2; h2 = Rot64(h2,15); h3 += h2;
259  h0 ^= h3; h3 = Rot64(h3,52); h0 += h3;
260  h1 ^= h0; h0 = Rot64(h0,26); h1 += h0;
261  h2 ^= h1; h1 = Rot64(h1,51); h2 += h1;
262  h3 ^= h2; h2 = Rot64(h2,28); h3 += h2;
263  h0 ^= h3; h3 = Rot64(h3,9); h0 += h3;
264  h1 ^= h0; h0 = Rot64(h0,47); h1 += h0;
265  h2 ^= h1; h1 = Rot64(h1,54); h2 += h1;
266  h3 ^= h2; h2 = Rot64(h2,32); h3 += h2;
267  h0 ^= h3; h3 = Rot64(h3,25); h0 += h3;
268  h1 ^= h0; h0 = Rot64(h0,63); h1 += h0;
269  }
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV2.h:124
static void folly::hash::SpookyHashV2::ShortMix ( uint64_t h0,
uint64_t h1,
uint64_t h2,
uint64_t h3 
)
inlinestatic

Definition at line 226 of file SpookyHashV2.h.

References Rot64().

Referenced by Short().

228  {
229  h2 = Rot64(h2,50); h2 += h3; h0 ^= h2;
230  h3 = Rot64(h3,52); h3 += h0; h1 ^= h3;
231  h0 = Rot64(h0,30); h0 += h1; h2 ^= h0;
232  h1 = Rot64(h1,41); h1 += h2; h3 ^= h1;
233  h2 = Rot64(h2,54); h2 += h3; h0 ^= h2;
234  h3 = Rot64(h3,48); h3 += h0; h1 ^= h3;
235  h0 = Rot64(h0,38); h0 += h1; h2 ^= h0;
236  h1 = Rot64(h1,37); h1 += h2; h3 ^= h1;
237  h2 = Rot64(h2,62); h2 += h3; h0 ^= h2;
238  h3 = Rot64(h3,34); h3 += h0; h1 ^= h3;
239  h0 = Rot64(h0,5); h0 += h1; h2 ^= h0;
240  h1 = Rot64(h1,36); h1 += h2; h3 ^= h1;
241  }
static uint64_t Rot64(uint64_t x, int k)
Definition: SpookyHashV2.h:124
void folly::hash::SpookyHashV2::Update ( const void *  message,
size_t  length 
)

Definition at line 236 of file SpookyHashV2.cpp.

References folly::test::end(), i, folly::kHasUnalignedAccess, 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 folly::RecordIOReader::Iterator::advanceToValid(), Hash32(), and folly::IOBufHash::operator()().

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 (kHasUnalignedAccess || (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 }
constexpr bool kHasUnalignedAccess
Definition: Portability.h:29
Definition: test.c:42
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: SpookyHashV2.h:142
bool prefix(Cursor &c, uint32_t expected)
uint64_t m_state[sc_numVars]
Definition: SpookyHashV2.h:304
static constexpr size_t sc_blockSize
Definition: SpookyHashV2.h:289
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
static constexpr size_t sc_bufSize
Definition: SpookyHashV2.h:292
static constexpr size_t sc_numVars
Definition: SpookyHashV2.h:286
uint64_t m_data[2 *sc_numVars]
Definition: SpookyHashV2.h:303
static constexpr uint64_t sc_const
Definition: SpookyHashV2.h:301

Member Data Documentation

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

Definition at line 303 of file SpookyHashV2.h.

Referenced by Final(), and Update().

size_t folly::hash::SpookyHashV2::m_length
private

Definition at line 305 of file SpookyHashV2.h.

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

uint8_t folly::hash::SpookyHashV2::m_remainder
private

Definition at line 306 of file SpookyHashV2.h.

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

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

Definition at line 304 of file SpookyHashV2.h.

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

constexpr size_t folly::hash::SpookyHashV2::sc_blockSize = sc_numVars*8
staticprivate

Definition at line 289 of file SpookyHashV2.h.

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

constexpr size_t folly::hash::SpookyHashV2::sc_bufSize = 2*sc_blockSize
staticprivate

Definition at line 292 of file SpookyHashV2.h.

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

constexpr uint64_t folly::hash::SpookyHashV2::sc_const = 0xdeadbeefdeadbeefULL
staticprivate

Definition at line 301 of file SpookyHashV2.h.

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

constexpr size_t folly::hash::SpookyHashV2::sc_numVars = 12
staticprivate

Definition at line 286 of file SpookyHashV2.h.

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


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