public void testHashCodesM3_128_ints() { int seed = 123; Random rand = new Random(seed); HashFunction hf = Hashing.murmur3_128(seed); for (int i = 0; i < 1000; i++) { int val = rand.nextInt(); byte[] data = ByteBuffer.allocate(4).putInt(val).array(); // guava stores the hashcodes in little endian order ByteBuffer buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN); buf.put(hf.hashBytes(data).asBytes()); buf.flip(); long gl1 = buf.getLong(); long gl2 = buf.getLong(8); long[] hc = Murmur3.hash128(data, 0, data.length, seed); long m1 = hc[0]; long m2 = hc[1]; Assert.Equal(gl1, m1); Assert.Equal(gl2, m2); byte[] offsetData = new byte[data.length + 50]; Array.Copy(data, 0, offsetData, 50, data.length); hc = Murmur3.hash128(offsetData, 50, data.length, seed); Assert.Equal(gl1, hc[0]); Assert.Equal(gl2, hc[1]); } }
public void testHashCodesM3_128_string() { string key = "test"; int seed = 123; HashFunction hf = Hashing.murmur3_128(seed); // guava stores the hashcodes in little endian order ByteBuffer buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN); buf.put(hf.hashBytes(key.getBytes()).asBytes()); buf.flip(); long gl1 = buf.getLong(); long gl2 = buf.getLong(8); long[] hc = Murmur3.hash128(key.getBytes(), 0, key.getBytes().length, seed); long m1 = hc[0]; long m2 = hc[1]; Assert.Equal(gl1, m1); Assert.Equal(gl2, m2); key = "testkey128_testkey128"; buf = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN); buf.put(hf.hashBytes(key.getBytes()).asBytes()); buf.flip(); gl1 = buf.getLong(); gl2 = buf.getLong(8); byte[] keyBytes = key.getBytes(); hc = Murmur3.hash128(keyBytes, 0, keyBytes.length, seed); m1 = hc[0]; m2 = hc[1]; Assert.Equal(gl1, m1); Assert.Equal(gl2, m2); byte[] offsetKeyBytes = new byte[keyBytes.length + 35]; Arrays.fill(offsetKeyBytes, (byte)-1); Array.Copy(keyBytes, 0, offsetKeyBytes, 35, keyBytes.length); hc = Murmur3.hash128(offsetKeyBytes, 35, keyBytes.length, seed); Assert.Equal(gl1, hc[0]); Assert.Equal(gl2, hc[1]); }