/** * Returns a hash function implementing * <a href="https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp">MurmurHash3 * algorithm</a> with the given seed value. This implementation produce equal results for equal * input on platforms with different {@link ByteOrder}, but is slower on big-endian platforms * than on little-endian. * * @see #murmur_3() */ public static LongHashFunction murmur_3(long seed) { return MurmurHash_3.asLongHashFunctionWithSeed(seed); }
/** * Returns a hash function implementing * <a href="https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp">MurmurHash3 * algorithm</a> without seed values. This implementation produce equal results for equal input * on platforms with different {@link ByteOrder}, but is slower on big-endian platforms than on * little-endian. * * @see #murmur_3(long) */ public static LongHashFunction murmur_3() { return MurmurHash_3.asLongHashFunctionWithoutSeed(); }
@Override <T> int fetch32(Access<T> access, T in, long off) { return Integer.reverseBytes(super.fetch32(access, in, off)); }
long remaining = length; while (remaining >= 16L) { long k1 = fetch64(access, input, offset); long k2 = fetch64(access, input, offset + 8L); offset += 16L; remaining -= 16L; h1 ^= mixK1(k1); h1 = h1 * 5L + 0x52dce729L; h2 ^= mixK2(k2); k2 ^= ((long) access.getUnsignedByte(input, offset + 8L)); // fall through case 8: k1 ^= fetch64(access, input, offset); break; case 7: k1 ^= ((long) access.getUnsignedByte(input, offset + 4L)) << 32; // fall through case 4: k1 ^= Primitives.unsignedInt(fetch32(access, input, offset)); break; case 3: h1 ^= mixK1(k1); h2 ^= mixK2(k2); return finalize(length, h1, h2);
@Override public long hashLong(long input) { return hashNativeLong(NATIVE_MURMUR.toLittleEndian(input), 8L); }
@Override <T> long fetch64(Access<T> access, T in, long off) { return reverseBytes(super.fetch64(access, in, off)); }
@Override public <T> long hash(T input, Access<T> access, long off, long len) { long seed = seed(); if (access.byteOrder(input) == LITTLE_ENDIAN) { return MurmurHash_3.INSTANCE.hash(seed, input, access, off, len); } else { return BigEndian.INSTANCE.hash(seed, input, access, off, len); } } }
@Override public long hashInt(int input) { return hashNativeLong(unsignedInt(NATIVE_MURMUR.toLittleEndian(input)), 4L); }