/** * Returns the 64 most significant bits of the Murmur128 hash of the provided value */ public static long hash64(Slice data) { return Murmur3Hash128.hash64(data); }
/** * Returns the 64 most significant bits of the Murmur128 hash of the provided value */ public static long hash64(Slice data) { return Murmur3Hash128.hash64(data); }
/** * Special-purpose version for hashing a single long value. Value is treated as little-endian */ public static long hash64(long value) { return Murmur3Hash128.hash64(value); } }
public static long hash64(Slice data, int offset, int length) { return hash64(DEFAULT_SEED, data, offset, length); }
/** * Returns the 64 most significant bits of the Murmur128 hash of the provided value */ public static long hash64(Slice data) { return hash64(data, 0, data.length()); }
@Test(invocationCount = 100) public void testSingleLong() throws Exception { long value = ThreadLocalRandom.current().nextLong(); Slice slice = Slices.allocate(8); slice.setLong(0, value); long expected = Murmur3Hash128.hash64(slice); long actual = Murmur3Hash128.hash64(value); assertEquals(actual, expected); }
private static DenseHll makeHll(int indexBits, long... values) { DenseHll result = new DenseHll(indexBits); for (long value : values) { result.insertHash(Murmur3Hash128.hash64(value)); } return result; } }
@Test(invocationCount = 100) public void test64ReturnsMsb() throws Exception { byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(200)); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testLessThan16Bytes64() throws Exception { byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(16)); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testMoreThan16Bytes64() throws Exception { byte[] data = randomBytes(131); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Benchmark public long specializedHashLong(SingleLong data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash128.hash64(data.getValue()); }
@Benchmark public long hashLong(BenchmarkData data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash128.hash64(data.getSlice(), 0, 8); }
@Test(invocationCount = 100) public void testMoreThan16Bytes64() throws Exception { byte[] data = randomBytes(131); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test public void testTail64() throws Exception { for (int i = 0; i < 16; i++) { byte[] data = randomBytes(50 + i); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); } }
@Test public void testTail64() throws Exception { for (int i = 0; i < 16; i++) { byte[] data = randomBytes(50 + i); long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data)).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data)); assertEquals(actual, expected); } }
@Test(invocationCount = 100) public void testNonDefaultSeed64() throws Exception { byte[] data = randomBytes(131); int seed = 123456789; long expected = Murmur3Hash128.hash(seed, Slices.wrappedBuffer(data), 0, data.length).getLong(0); long actual = Murmur3Hash128.hash64(seed, Slices.wrappedBuffer(data), 0, data.length); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testOffsetAndLength64() throws Exception { byte[] data = randomBytes(131); int offset = 13; int length = 55; long expected = Murmur3Hash128.hash(Slices.wrappedBuffer(data), offset, length).getLong(0); long actual = Murmur3Hash128.hash64(Slices.wrappedBuffer(data), offset, length); assertEquals(actual, expected); }
@Benchmark public long hashLong(BenchmarkData data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash128.hash64(data.getSlice(), 0, 8); }
@Test public void testRoundtrip() throws Exception { DenseHll hll = new DenseHll(4); for (int i = 0; i < 1000; i++) { hll.insertHash(Murmur3Hash128.hash64(i)); Slice serialized = hll.serialize(); Slice reserialized = new DenseHll(serialized).serialize(); assertSlicesEqual(serialized, reserialized); } }
@Benchmark public long hash64(BenchmarkData data, ByteCounter counter) { counter.add(data.getSlice().length()); return Murmur3Hash128.hash64(data.getSlice()); }