MCPcopy Create free account
hub / github.com/F-Stack/f-stack / MurmurHash64A

Function MurmurHash64A

app/redis-6.2.6/src/hyperloglog.c:396–446  ·  view source on GitHub ↗

Our hash function is MurmurHash2, 64 bit version. * It was modified for Redis in order to provide the same result in * big and little endian archs (endian neutral). */

Source from the content-addressed store, hash-verified

394 * It was modified for Redis in order to provide the same result in
395 * big and little endian archs (endian neutral). */
396uint64_t MurmurHash64A (const void * key, int len, unsigned int seed) {
397 const uint64_t m = 0xc6a4a7935bd1e995;
398 const int r = 47;
399 uint64_t h = seed ^ (len * m);
400 const uint8_t *data = (const uint8_t *)key;
401 const uint8_t *end = data + (len-(len&7));
402
403 while(data != end) {
404 uint64_t k;
405
406#if (BYTE_ORDER == LITTLE_ENDIAN)
407 #ifdef USE_ALIGNED_ACCESS
408 memcpy(&k,data,sizeof(uint64_t));
409 #else
410 k = *((uint64_t*)data);
411 #endif
412#else
413 k = (uint64_t) data[0];
414 k |= (uint64_t) data[1] << 8;
415 k |= (uint64_t) data[2] << 16;
416 k |= (uint64_t) data[3] << 24;
417 k |= (uint64_t) data[4] << 32;
418 k |= (uint64_t) data[5] << 40;
419 k |= (uint64_t) data[6] << 48;
420 k |= (uint64_t) data[7] << 56;
421#endif
422
423 k *= m;
424 k ^= k >> r;
425 k *= m;
426 h ^= k;
427 h *= m;
428 data += 8;
429 }
430
431 switch(len & 7) {
432 case 7: h ^= (uint64_t)data[6] << 48; /* fall-thru */
433 case 6: h ^= (uint64_t)data[5] << 40; /* fall-thru */
434 case 5: h ^= (uint64_t)data[4] << 32; /* fall-thru */
435 case 4: h ^= (uint64_t)data[3] << 24; /* fall-thru */
436 case 3: h ^= (uint64_t)data[2] << 16; /* fall-thru */
437 case 2: h ^= (uint64_t)data[1] << 8; /* fall-thru */
438 case 1: h ^= (uint64_t)data[0];
439 h *= m; /* fall-thru */
440 };
441
442 h ^= h >> r;
443 h *= m;
444 h ^= h >> r;
445 return h;
446}
447
448/* Given a string element to add to the HyperLogLog, returns the length
449 * of the pattern 000..1 of the element hash. As a side effect 'regp' is

Callers 1

hllPatLenFunction · 0.70

Calls 1

memcpyFunction · 0.50

Tested by

no test coverage detected