huangya90 / smhasher

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

Probably bug in KeysetTest.cpp #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Trying to port C++ implementation to C# I found a funny bug that confused me 
when I compared the hashes between both implementations.

The hard coded value for the MurMurHash3_x86_32 (end probably for the rest of 
methods) is not correct because of the bug in KeysetTest.cpp.

The problem is in the following piece of code (lines 28-33):

 for(int i = 0; i < 256; i++)
  {
    key[i] = (uint8_t)i;

    hash(key,i,256-i,&hashes[i*hashbytes]);
  }

At first iteration the first element of key array is set to "0" and the length 
of the key array is 1, but as far as i is sent to hash function as len 
parameter, it is set to 0.

The correct code should look like:

    hash(key,i+1,256-i,&hashes[i*hashbytes]);

and the resulting hash is 0xDBFB92BE.

Original issue reported on code.google.com by geopap...@gmail.com on 28 Feb 2013 at 4:09