OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MurmurHash3Inl.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Shared/funcannotations.h"
4 
5 FORCE_INLINE DEVICE uint32_t rotl32(uint32_t x, int8_t r) {
6  return (x << r) | (x >> (32 - r));
7 }
8 
9 #define ROTL32(x, y) rotl32(x, y)
10 
11 FORCE_INLINE DEVICE uint32_t MurmurHash3Impl(const void* key, int len, uint32_t seed) {
12  const uint8_t* data = (const uint8_t*)key;
13  const int nblocks = len / 4;
14 
15  uint32_t h1 = seed;
16 
17  const uint32_t c1 = 0xcc9e2d51;
18  const uint32_t c2 = 0x1b873593;
19 
20  //----------
21  // body
22 
23  const uint32_t* blocks = (const uint32_t*)(data + nblocks * 4);
24 
25  for (int i = -nblocks; i; i++) {
26  uint32_t k1 = blocks[i];
27 
28  k1 *= c1;
29  k1 = ROTL32(k1, 15);
30  k1 *= c2;
31 
32  h1 ^= k1;
33  h1 = ROTL32(h1, 13);
34  h1 = h1 * 5 + 0xe6546b64;
35  }
36 
37  //----------
38  // tail
39 
40  const uint8_t* tail = (const uint8_t*)(data + nblocks * 4);
41 
42  uint32_t k1 = 0;
43 
44  switch (len & 3) {
45  case 3:
46  k1 ^= tail[2] << 16;
47  case 2:
48  k1 ^= tail[1] << 8;
49  case 1:
50  k1 ^= tail[0];
51  k1 *= c1;
52  k1 = ROTL32(k1, 15);
53  k1 *= c2;
54  h1 ^= k1;
55  };
56 
57  //----------
58  // finalization
59 
60  h1 ^= len;
61 
62  //-----------------------------------------------------------------------------
63  // Finalization mix - force all bits of a hash block to avalanche
64 
65  h1 ^= h1 >> 16;
66  h1 *= 0x85ebca6b;
67  h1 ^= h1 >> 13;
68  h1 *= 0xc2b2ae35;
69  h1 ^= h1 >> 16;
70 
71  return h1;
72 }
FORCE_INLINE DEVICE uint32_t MurmurHash3Impl(const void *key, int len, uint32_t seed)
#define DEVICE
FORCE_INLINE DEVICE uint32_t rotl32(uint32_t x, int8_t r)
Definition: MurmurHash3Inl.h:5
#define FORCE_INLINE
#define ROTL32(x, y)
Definition: MurmurHash3Inl.h:9