aappleby / smhasher

Automatically exported from code.google.com/p/smhasher
2.63k stars 467 forks source link

Weird finalization in MurmurHash3_x64_128 #65

Closed Novum closed 5 years ago

Novum commented 5 years ago

https://github.com/aappleby/smhasher/blob/61a0530f28277f2e850bfc39600ce61d02b518de/src/MurmurHash3.cpp#L321

After L321 and L322 aren't h1 and h2 exactly the same value? Which in turn also means the 64 bit halfs of the 128 bit output are identical?

If I'm not mistaken it's just 2 * fmix64( h1 + h2 ) for out[0] and out[1]?

sebres commented 5 years ago

After L321 and L322 aren't h1 and h2 exactly the same value?

No. Short explanation:

  h1 = 0x0123;
  h2 = 0x4567;
_
  h1 += h2;
  h2 += h1;
?
  h1 : 0x468A
  h2 : 0x8BF1

Operator += is a left modifier that increases left part with value of right part, considering type (thus can overflow ~ be smaller as the sum of both). Thus normally h1 != h2 after both operators used. Thus L321 and L322 is quasi linear "bit-mixer" of two 64-bit integers:

If I'm not mistaken it's just 2 * fmix64( h1 + h2 ) for out[0] and out[1]?

You are... so it is not the result you're assuming.

Novum commented 5 years ago

Nevermind, I'm an idiot 🤦‍♂️