/** * Returns a hash function implementing the 64 bit version of * <a href = "https://github.com/jandrewrogers/MetroHash">metrohash algorithm</a> with a given seed value. * This implementation uses the initialization vector for metrohash64_2. * 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 #metro() */ public static LongHashFunction metro(long seed) { return MetroHash.asLongHashFunctionWithSeed(seed); }
/** * Returns a hash function implementing the 64 bit version of * <a href = "https://github.com/jandrewrogers/MetroHash">metrohash64 algorithm</a> without a seed value (0 is used * as default 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 #metro(long) */ public static LongHashFunction metro() { return MetroHash.asLongHashFunctionWithoutSeed(); }
@Override <T> long fetch64(Access<T> access, T in, long off) { return Long.reverseBytes(super.fetch64(access, in, off)); }
v0 += fetch64(access, input, off) * k0; v0 = Long.rotateRight(v0, 29) + v2; v1 += fetch64(access, input, off + 8) * k1; v1 = Long.rotateRight(v1, 29) + v3; v2 += fetch64(access, input, off + 16) * k2; v2 = Long.rotateRight(v2, 29) + v0; v3 += fetch64(access, input, off + 24) * k3; v3 = Long.rotateRight(v3, 29) + v1; long v0 = h + (fetch64(access, input, off) * k2); v0 = Long.rotateRight(v0, 29) * k3; long v1 = h + (fetch64(access, input, off + 8) * k2); v1 = Long.rotateRight(v1, 29) * k3; v0 ^= Long.rotateRight(v0 * k0, 21) + v1; h += fetch64(access, input, off) * k3; h ^= Long.rotateRight(h, 55) * k1; h += fetch32(access, input, off) * k3; h ^= Long.rotateRight(h, 26) * k1; h += fetch16(access, input, off) * k3; h ^= Long.rotateRight(h, 48) * k1; h += fetch8(access, input, off) * k3; h ^= Long.rotateRight(h, 37) * k1; return finalize(h);
@Override public long hashLong(long input) { input = NATIVE_METRO.toLittleEndian(input); long h = (seed() + k2) * k0; h += input * k3; h ^= Long.rotateRight(h, 55) * k1; return MetroHash.finalize(h); }
@Override <T> int fetch8(Access<T> access, T in, long off) { return super.fetch8(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 MetroHash.INSTANCE.metroHash64(seed, input, access, off, len); } else { return MetroHash.BigEndian.INSTANCE.metroHash64(seed, input, access, off, len); } } }
@Override public long hashInt(int input) { input = NATIVE_METRO.toLittleEndian(input); long h = (seed() + k2) * k0; h += Primitives.unsignedInt(input) * k3; h ^= Long.rotateRight(h, 26) * k1; return MetroHash.finalize(h); }
@Override public long hashShort(short input) { input = NATIVE_METRO.toLittleEndian(input); long h = (seed() + k2) * k0; h += Primitives.unsignedShort(input) * k3; h ^= Long.rotateRight(h, 48) * k1; return MetroHash.finalize(h); }