Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper handling of negative seeds #32

Open
GoogleCodeExporter opened this issue Jun 9, 2015 · 1 comment
Open

Improper handling of negative seeds #32

GoogleCodeExporter opened this issue Jun 9, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Supply a negative seed value when constructing an instance of MurmurHash3
2. Compute a hash
3. Get a different hash value than the reference implementation provides for 
the same input and seed



Please provide any additional information below.

Below is the current constructor for when a seed is supplied.

   public Murmur3F(int seed)
   {
      this.seed = seed & (0xffffffffL); // unsigned
      h1 = seed;
      h2 = seed;
   }

Here is the code from the reference implementation:

void MurmurHash3_x64_128 ( const void * key, const int len,
                           const uint32_t seed, void * out )
{
  const uint8_t * data = (const uint8_t*)key;
  const int nblocks = len / 16;

  uint64_t h1 = seed;
  uint64_t h2 = seed;


Note that h1 and h2 are unsigned 64-bit integers. Because they are unsigned, 
they will not inherit the sign of the supplied seed. However, in the 
corresponding java code, h1 and h2 will become negative if the seed is negative 
(e.g. a value greater than Integer.MAX_VALUE).

A minor modification to the constructor resolves the issue, and makes the 
output congrument with the reference implementation for negative seed values:

   public Murmur3F(int seed)
   {
      this.seed = seed & (0xffffffffL); // unsigned
      h1 = this.seed;
      h2 = this.seed;
   }

Original issue reported on code.google.com by jasonre...@gmail.com on 31 Dec 2014 at 3:39

@GoogleCodeExporter
Copy link
Author

Sorry, I meant to submit this issue to the GreenRobot Java implementation of 
MurmurHash3.

Original comment by jasonre...@gmail.com on 31 Dec 2014 at 3:41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant