c++ - is it possible for MurmurHash3 to produce a 64 bit hash where the upper 32 bits are all 0? -


looking @ https://github.com/aappleby/smhasher/blob/master/src/murmurhash3.cpp don't think wanted check.

the situation this, if have key of 1,2,3 or 4 bytes, reliable take numeric value of bytes instead of hashing 8 bytes, or cause collision keys greater 4 bytes hashed murmur3?

such property bad property hash function. shrinks function co-domain, increasing collision chance, seems unlikely.

moreover, this blog post provides inversion function murmurhash:

uint64 murmur_hash_64(const void * key, int len, uint64 seed) {     const uint64 m = 0xc6a4a7935bd1e995ull;     const int r = 47;      uint64 h = seed ^ (len * m);      const uint64 * data = (const uint64 *)key;     const uint64 * end = data + (len / 8);      while (data != end)     { #ifdef platform_big_endian         uint64 k = *data++;         char *p = (char *)&k;         char c;         c = p[0]; p[0] = p[7]; p[7] = c;         c = p[1]; p[1] = p[6]; p[6] = c;         c = p[2]; p[2] = p[5]; p[5] = c;         c = p[3]; p[3] = p[4]; p[4] = c; #else         uint64 k = *data++; #endif          k *= m;         k ^= k >> r;         k *= m;          h ^= k;         h *= m;     }      const unsigned char * data2 = (const unsigned char*)data;      switch (len & 7)     {     case 7: h ^= uint64(data2[6]) << 48;     case 6: h ^= uint64(data2[5]) << 40;     case 5: h ^= uint64(data2[4]) << 32;     case 4: h ^= uint64(data2[3]) << 24;     case 3: h ^= uint64(data2[2]) << 16;     case 2: h ^= uint64(data2[1]) << 8;     case 1: h ^= uint64(data2[0]);         h *= m;     };      h ^= h >> r;     h *= m;     h ^= h >> r;      return h; }  uint64 murmur_hash_64_inverse(uint64 h, uint64 seed) {     const uint64 m = 0xc6a4a7935bd1e995ull;     const uint64 minv = 0x5f7a0ea7e59b19bdull; // multiplicative inverse of m under % 2^64     const int r = 47;      h ^= h >> r;     h *= minv;     h ^= h >> r;     h *= minv;      uint64 hforward = seed ^ (((uint64)8) * m);     uint64 k = h ^ hforward;      k *= minv;     k ^= k >> r;     k *= minv;  #ifdef platform_big_endian     char *p = (char *)&k;     char c;     c = p[0]; p[0] = p[7]; p[7] = c;     c = p[1]; p[1] = p[6]; p[6] = c;     c = p[2]; p[2] = p[5]; p[5] = c;     c = p[3]; p[3] = p[4]; p[4] = c; #endif      return k; } 

you can find many inputs hash values <2^32 want.

your question reliability doesn't make sense: must ready handle collisions properly. practice, not recommend use plain integers or pointer values hash, can produce undesired patterns.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -