Michaelangel007 / smhasher

Automatically exported from code.google.com/p/smhasher
0 stars 0 forks source link

murmurhash3 128bit gives wrong result on big-endian platform #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
string "str_hash_mmh"

should give mmh3_128 value

EBC36FB5EAEF57B81E12217B6E10C8B1 (x64 Linux/Solaris/Windows/etc)

while for big-endian machines it gives

B857EFEAB56FC3EBB1C8106E7B21121E (SPARC Solaris)

Original issue reported on code.google.com by alexandr.ustinov on 5 Dec 2014 at 4:35

GoogleCodeExporter commented 8 years ago
The fix is very simple, as reference we could start from this code

https://github.com/hideo55/node-murmurhash3/blob/master/src/MurmurHash3.cpp

see function getblock(), for BIG_ENDIAN it should return swapped bytes, and 
final rows, 

   ((uint64_t*) out)[0] = h1;
    ((uint64_t*) out)[1] = h2;

for BIG_ENDIAN platform also should be swapped:

   ((uint64_t*) out)[0] =  BYTESWAP64(h1);
    ((uint64_t*) out)[1] =  BYTESWAP64(h2);

as result I've got the same values for both platforms.

Original comment by alexandr.ustinov on 8 Dec 2014 at 5:28