20 #define FORCE_INLINE __forceinline
22 #define ROTL32(x,y) _rotl(x,y)
23 #define ROTL64(x,y) _rotl64(x,y)
24 #define BIG_CONSTANT(x) (x)
27 #define FORCE_INLINE inline __attribute__((always_inline))
29 inline uint32_t rotl32(uint32_t x, int8_t r)
31 return (x << r) | (x >> (32 - r));
34 inline uint64_t rotl64(uint64_t x, int8_t r)
36 return (x << r) | (x >> (64 - r));
39 #define ROTL32(x,y) rotl32(x,y)
40 #define ROTL64(x,y) rotl64(x,y)
42 #define BIG_CONSTANT(x) (x##LLU)
50 FORCE_INLINE uint32_t getblock32(
const uint32_t * p,
size_t i)
55 FORCE_INLINE uint64_t getblock64(
const uint64_t * p,
size_t i)
63 FORCE_INLINE uint32_t fmix32(uint32_t h)
74 FORCE_INLINE uint64_t fmix64(uint64_t k)
77 k *= BIG_CONSTANT(0xff51afd7ed558ccd);
79 k *= BIG_CONSTANT(0xc4ceb9fe1a85ec53);
85 const MurmurHash3 &MurmurHash3::operator = (
const MurmurHash3 &other)
87 seed[0] = other.seed[0];
88 seed[1] = other.seed[1];
92 bool MurmurHash3::operator==(
const MurmurHash3 &rh)
const
94 return seed[0] == rh.seed[0] && seed[1] == rh.seed[1];
97 bool MurmurHash3::operator!=(
const MurmurHash3 &rh)
const
99 return seed[0] != rh.seed[0] || seed[1] != rh.seed[1];
102 bool MurmurHash3::operator<(
const MurmurHash3 &rh)
const
104 return seed[0] < rh.seed[0] || (seed[0] == rh.seed[0] && seed[1] < rh.seed[1]);
107 void MurmurHash3::hash(
const void *key,
size_t len)
109 const uint8_t * data = (
const uint8_t*)key;
110 const size_t nblocks = len / 16;
112 uint64_t h1 = seed[0];
113 uint64_t h2 = seed[1];
115 const uint64_t c1 = BIG_CONSTANT(0x87c37b91114253d5);
116 const uint64_t c2 = BIG_CONSTANT(0x4cf5ad432745937f);
120 const uint64_t * blocks = (
const uint64_t *)(data);
122 for (
size_t i = 0; i < nblocks; i++)
124 uint64_t k1 = getblock64(blocks, i * 2 + 0);
125 uint64_t k2 = getblock64(blocks, i * 2 + 1);
126 k1 *= c1; k1 = ROTL64(k1, 31); k1 *= c2; h1 ^= k1;
127 h1 = ROTL64(h1, 27); h1 += h2; h1 = h1 * 5 + 0x52dce729;
128 k2 *= c2; k2 = ROTL64(k2, 33); k2 *= c1; h2 ^= k2;
129 h2 = ROTL64(h2, 31); h2 += h1; h2 = h2 * 5 + 0x38495ab5;
135 const uint8_t * tail = (
const uint8_t*)(data + nblocks * 16);
142 case 15: k2 ^= ((uint64_t)tail[14]) << 48;
143 case 14: k2 ^= ((uint64_t)tail[13]) << 40;
144 case 13: k2 ^= ((uint64_t)tail[12]) << 32;
145 case 12: k2 ^= ((uint64_t)tail[11]) << 24;
146 case 11: k2 ^= ((uint64_t)tail[10]) << 16;
147 case 10: k2 ^= ((uint64_t)tail[9]) << 8;
148 case 9: k2 ^= ((uint64_t)tail[8]) << 0;
149 k2 *= c2; k2 = ROTL64(k2, 33); k2 *= c1; h2 ^= k2;
150 case 8: k1 ^= ((uint64_t)tail[7]) << 56;
151 case 7: k1 ^= ((uint64_t)tail[6]) << 48;
152 case 6: k1 ^= ((uint64_t)tail[5]) << 40;
153 case 5: k1 ^= ((uint64_t)tail[4]) << 32;
154 case 4: k1 ^= ((uint64_t)tail[3]) << 24;
155 case 3: k1 ^= ((uint64_t)tail[2]) << 16;
156 case 2: k1 ^= ((uint64_t)tail[1]) << 8;
157 case 1: k1 ^= ((uint64_t)tail[0]) << 0;
158 k1 *= c1; k1 = ROTL64(k1, 31); k1 *= c2; h1 ^= k1;
164 h1 ^= len; h2 ^= len;
174 ((uint64_t*)seed)[0] = h1;
175 ((uint64_t*)seed)[1] = h2;
178 void MurmurHash3::append(
bool data)
181 hash(&value,
sizeof(
char));
184 void MurmurHash3::append(
char data)
186 hash(&data,
sizeof(
char));
189 void MurmurHash3::append(
unsigned char data)
191 hash(&data,
sizeof(
unsigned char));
194 void MurmurHash3::append(
short data)
196 hash(&data,
sizeof(
short));
199 void MurmurHash3::append(
unsigned short data)
201 hash(&data,
sizeof(
unsigned short));
204 void MurmurHash3::append(
int data)
206 hash(&data,
sizeof(
int));
209 void MurmurHash3::append(
unsigned int data)
211 hash(&data,
sizeof(
unsigned int));
214 void MurmurHash3::append(int64_t data)
216 hash(&data,
sizeof(int64_t));
219 void MurmurHash3::append(uint64_t data)
221 hash(&data,
sizeof(uint64_t));
224 void MurmurHash3::append(
size_t data)
226 hash(&data,
sizeof(uint64_t));
229 void MurmurHash3::append(
float data)
231 hash(&data,
sizeof(
float));
234 void MurmurHash3::append(
double data)
236 hash(&data,
sizeof(
double));
239 void MurmurHash3::append(
const char *data)
241 hash(&data,
sizeof(
char) * strlen(data));
244 void MurmurHash3::append(
const std::string &data)
246 hash(&data[0],
sizeof(
char) * data.size());
249 void MurmurHash3::append(
const Vector2 &data)
251 hash(&data.getValue()[0],
sizeof(
double) * 2);
254 void MurmurHash3::append(
const Vector2f &data)
256 hash(&data.getValue()[0],
sizeof(
float) * 2);
259 void MurmurHash3::append(
const Vector2i &data)
261 hash(&data.getValue()[0],
sizeof(
int) * 2);
264 void MurmurHash3::append(
const Vector3 &data)
266 hash(&data.getValue()[0],
sizeof(
double) * 2);
269 void MurmurHash3::append(
const Vector3f &data)
271 hash(&data.getValue()[0],
sizeof(
float) * 3);
274 void MurmurHash3::append(
const Vector3i &data)
276 hash(&data.getValue()[0],
sizeof(
int) * 3);
279 void MurmurHash3::append(
const Vector4 &data)
281 append(data.x); append(data.y); append(data.z); append(data.w);
284 void MurmurHash3::append(
const Vector4f &data)
286 append(data.x); append(data.y); append(data.z); append(data.w);
289 void MurmurHash3::append(
const Vector4i &data)
291 append(data.x); append(data.y); append(data.z); append(data.w);
294 void MurmurHash3::append(
const Euler &data)
296 hash(&data.
getValue()[0],
sizeof(
double));
299 void MurmurHash3::append(
const Eulerf &data)
301 hash(&data.
getValue()[0],
sizeof(
float));
304 void MurmurHash3::append(
const Quaternion &data)
306 append(data.r); append(data.v);
311 append(data.r); append(data.v);
314 void MurmurHash3::append(
const Box2 &data)
316 append(data.min); append(data.max);
319 void MurmurHash3::append(
const Box2i &data)
321 append(data.
min); append(data.
max);
324 void MurmurHash3::append(
const Box2f &data)
326 append(data.
min); append(data.
max);
329 void MurmurHash3::append(
const Box3 &data)
331 append(data.min); append(data.max);
334 void MurmurHash3::append(
const Box3i &data)
336 append(data.
min); append(data.
max);
339 void MurmurHash3::append(
const Box3f &data)
341 append(data.
min); append(data.
max);
344 void MurmurHash3::append(
const Matrix &data)
346 hash(&data.getValue()[0],
sizeof(
double) * 16);
349 void MurmurHash3::append(
const Matrixf &data)
351 hash(&data.getValue()[0],
sizeof(
float) * 16);
358 void MurmurHash3::append(
const std::vector<bool>& data)
360 for (
size_t i = 0; i < data.size(); ++i)
366 void MurmurHash3::append(
const std::vector<char>& data)
368 hash(&data[0],
sizeof(
char) * data.size());
371 void MurmurHash3::append(
const std::vector<unsigned char>& data)
373 hash(&data[0],
sizeof(
unsigned char) * data.size());
376 void MurmurHash3::append(
const std::vector<short>& data)
378 hash(&data[0],
sizeof(
short) * data.size());
381 void MurmurHash3::append(
const std::vector<unsigned short>& data)
383 hash(&data[0],
sizeof(
unsigned short) * data.size());
386 void MurmurHash3::append(
const std::vector<int>& data)
388 hash(&data[0],
sizeof(
int) * data.size());
391 void MurmurHash3::append(
const std::vector<unsigned int>& data)
393 hash(&data[0],
sizeof(
unsigned int) * data.size());
396 void MurmurHash3::append(
const std::vector<int64_t>& data)
398 hash(&data[0],
sizeof(int64_t) * data.size());
401 void MurmurHash3::append(
const std::vector<uint64_t>& data)
403 hash(&data[0],
sizeof(uint64_t) * data.size());
406 void MurmurHash3::append(
const std::vector<float>& data)
408 hash(&data[0],
sizeof(
float) * data.size());
411 void MurmurHash3::append(
const std::vector<double>& data)
413 hash(&data[0],
sizeof(
double) * data.size());
416 void MurmurHash3::append(
const std::vector<std::string> &data)
418 for (
size_t i = 0; i < data.size(); ++i)
424 void MurmurHash3::append(
const std::vector<Vector2> &data)
426 hash(&data[0],
sizeof(
Vector2) * data.size());
429 void MurmurHash3::append(
const std::vector<Vector2f> &data)
431 hash(&data[0],
sizeof(
Vector2f) * data.size());
434 void MurmurHash3::append(
const std::vector<Vector2i> &data)
436 hash(&data[0],
sizeof(
Vector2i) * data.size());
439 void MurmurHash3::append(
const std::vector<Vector3> &data)
441 hash(&data[0],
sizeof(
Vector3) * data.size());
444 void MurmurHash3::append(
const std::vector<Vector3f> &data)
446 hash(&data[0],
sizeof(
Vector3f) * data.size());
449 void MurmurHash3::append(
const std::vector<Vector3i> &data)
451 hash(&data[0],
sizeof(
Vector3i) * data.size());
454 void MurmurHash3::append(
const std::vector<Vector4> &data)
456 hash(&data[0],
sizeof(
Vector4) * data.size());
459 void MurmurHash3::append(
const std::vector<Vector4f> &data)
461 hash(&data[0],
sizeof(
Vector4f) * data.size());
464 void MurmurHash3::append(
const std::vector<Vector4i> &data)
466 hash(&data[0],
sizeof(
Vector4i) * data.size());
469 void MurmurHash3::append(
const std::vector<Euler> &data)
471 hash(&data[0],
sizeof(
Euler) * data.size());
474 void MurmurHash3::append(
const std::vector<Eulerf> &data)
476 hash(&data[0],
sizeof(
Eulerf) * data.size());
479 void MurmurHash3::append(
const std::vector<Quaternion> &data)
481 hash(&data[0],
sizeof(
Quaternion) * data.size());
484 void MurmurHash3::append(
const std::vector<Quaternionf> &data)
489 void MurmurHash3::append(
const std::vector<Box2> &data)
491 hash(&data[0],
sizeof(
Box2) * data.size());
494 void MurmurHash3::append(
const std::vector<Box2i> &data)
496 hash(&data[0],
sizeof(
Box2i) * data.size());
499 void MurmurHash3::append(
const std::vector<Box2f> &data)
501 hash(&data[0],
sizeof(
Box2f) * data.size());
504 void MurmurHash3::append(
const std::vector<Box3> &data)
506 hash(&data[0],
sizeof(
Box3) * data.size());
509 void MurmurHash3::append(
const std::vector<Box3i> &data)
511 hash(&data[0],
sizeof(
Box3i) * data.size());
514 void MurmurHash3::append(
const std::vector<Box3f> &data)
516 hash(&data[0],
sizeof(
Box3f) * data.size());
519 void MurmurHash3::append(
const std::vector<Matrix> &data)
521 hash(&data[0],
sizeof(
Matrix) * data.size());
524 void MurmurHash3::append(
const std::vector<Matrixf> &data)
526 hash(&data[0],
sizeof(
Matrixf) * data.size());
529 void MurmurHash3::append(
const MurmurHash3& data)
531 hash(&data.seed[0],
sizeof(
size_t) * 2);
Definition: ImathBox.h:36
V min
The minimum value of the box.
Definition: ImathBox.h:43
V max
The maximum value of the box.
Definition: ImathBox.h:46
Definition: ImathEuler.h:118
ATOMSMATH_HOSTDEVICE void getValue(S &a, S &b, S &c) const noexcept
Return the value in a, b, and c
AtomsCore namespace.
Definition: Agent.h:344
AtomsMath::Vector4f Vector4f
Vector4 class.
Definition: AtomsMath.h:61
AtomsMath::Vector3i Vector3i
Vector3i class.
Definition: AtomsMath.h:59
AtomsMath::Vector2 Vector2
Vector2 class.
Definition: AtomsMath.h:54
AtomsMath::Vector4i Vector4i
Vector4 class.
Definition: AtomsMath.h:62
AtomsMath::Quaternion Quaternion
Quaternion class.
Definition: AtomsMath.h:67
AtomsMath::Vector2i Vector2i
Vector2 class.
Definition: AtomsMath.h:56
AtomsMath::Vector4 Vector4
Vector4 class.
Definition: AtomsMath.h:60
AtomsMath::Box3 Box3
Bounding box class.
Definition: AtomsMath.h:74
AtomsMath::Box2 Box2
Bounding box class.
Definition: AtomsMath.h:71
AtomsMath::Matrixf Matrixf
Matrix class.
Definition: AtomsMath.h:64
AtomsMath::Vector2f Vector2f
Vector2 class.
Definition: AtomsMath.h:55
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
AtomsMath::Vector3f Vector3f
Vector3 class.
Definition: AtomsMath.h:58
AtomsMath::Quaternionf Quaternionf
Quaternion class.
Definition: AtomsMath.h:68