public static HashValue murmurhash3_x64_128(final String str, final int seed) { byte[] bytes = StringUtil.getBytes(str); return murmurhash3_x64_128(bytes, 0, bytes.length, seed); }
long k1 = getLongLittleEndian(key, i); long k2 = getLongLittleEndian(key, i + 8); k1 *= c1; k1 = Long.rotateLeft(k1, 31); h2 += h1; h1 = fmix64(h1); h2 = fmix64(h2);
long k1 = getLongLittleEndian(key, i); long k2 = getLongLittleEndian(key, i + 8); k1 *= c1; k1 = Long.rotateLeft(k1, 31); h2 += h1; h1 = fmix64(h1); h2 = fmix64(h2);
@Test void testCorrectValues() throws Exception { byte[] bytes = "Now is the time for all good men to come to the aid of their country".getBytes("UTF-8"); int hash = 0; for (int i = 0; i < bytes.length; i++) { hash = hash * 31 + (bytes[i] & 0xff); bytes[i] = (byte) hash; } // test different offsets. for (int offset = 0; offset < 20; offset++) { // put the original bytes at the offset so the same hash will be generated byte[] arr = new byte[bytes.length + offset]; System.arraycopy(bytes, 0, arr, offset, bytes.length); int seed = 1; for (int len = 0; len < bytes.length; len++) { seed *= 0x9e3779b1; MurmurHash3.HashValue result = MurmurHash3.murmurhash3_x64_128(arr, offset, len, seed); assertEquals(answers128[len * 2], result.val1); assertEquals(answers128[len * 2 + 1], result.val2); } } }
public static HashValue murmurhash3_x64_128(final String str, final int seed) { byte[] bytes = StringUtil.getBytes(str); return murmurhash3_x64_128(bytes, 0, bytes.length, seed); }