murmur icon indicating copy to clipboard operation
murmur copied to clipboard

Murmur3 gives out different hash values for the same input

Open KingBoomie opened this issue 6 years ago • 1 comments

Running in jshell

import com.sangupta.murmur.Murmur3;

byte[] data2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1};
Murmur3.hash_x64_128(data2, data2.length, 0);
Murmur3.hash_x64_128(data2, data2.length, 0);
Murmur3.hash_x64_128(data2, data2.length, 0);

Murmur3.hash_x64_128(data2, data2.length, 0);

returns

import com.sangupta.murmur.Murmur3
field byte[] data2 = byte[17] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1 }
Murmur3.hash_x64_128(data2, data2.length, 0); = long[2] { 2108477303888159446, 3080087960434196035 }
Murmur3.hash_x64_128(data2, data2.length, 0); = long[2] { -5533461732917773897, -8684579065263202028 }
Murmur3.hash_x64_128(data2, data2.length, 0); = long[2] { -5533461732917773897, -8684579065263202028 }
Murmur3.hash_x64_128(data2, data2.length, 0); = long[2] { -5533461732917773897, -8684579065263202028 }

Expected all return values to be equal. running OracleJDK 12.0.2.

KingBoomie avatar Sep 01 '19 11:09 KingBoomie

@KingBoomie The byte-array is modified after the first run of the hash pass:

@Test
public void test() {
	byte[] data2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1};
	byte[] data3 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1};

	final long seed = new Random().nextLong();		
	long[] initial = Murmur3.hash_x64_128(data2, data2.length, seed);
	
	System.out.println(Arrays.toString(data2));
	Assert.assertArrayEquals(data2, data3); // this fails
}

The data2 is modified to:

[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1]

I will debug further to see why this happens.

sangupta avatar Sep 15 '19 06:09 sangupta