public static int hash(Slice data) { return hash(data, 0, data.length()); }
@Test(invocationCount = 100) public void testSingleInt() throws Exception { int value = ThreadLocalRandom.current().nextInt(); Slice slice = Slices.allocate(4); slice.setInt(0, value); int expected = Murmur3Hash32.hash(slice); int actual = Murmur3Hash32.hash(value); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testSingleLong() throws Exception { long value = ThreadLocalRandom.current().nextLong(); Slice slice = Slices.allocate(8); slice.setLong(0, value); int expected = Murmur3Hash32.hash(slice); int actual = Murmur3Hash32.hash(value); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testLessThan4Bytes() throws Exception { byte[] data = randomBytes(ThreadLocalRandom.current().nextInt(4)); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testMoreThan4Bytes() throws Exception { byte[] data = randomBytes(131); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testMoreThan4Bytes() throws Exception { byte[] data = randomBytes(131); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testNonDefaultSeed() throws Exception { byte[] data = randomBytes(131); int seed = 123456789; int expected = Hashing.murmur3_32(seed).hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(seed, Slices.wrappedBuffer(data), 0, data.length); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testOffsetAndLength() throws Exception { byte[] data = randomBytes(131); int offset = 13; int length = 55; int expected = Hashing.murmur3_32().hashBytes(data, offset, length).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data), offset, length); assertEquals(actual, expected); }
@Test public void testTail() throws Exception { for (int i = 0; i < 4; i++) { byte[] data = randomBytes(50 + i); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); } }
@Test(invocationCount = 100) public void testNonDefaultSeed() throws Exception { byte[] data = randomBytes(131); int seed = 123456789; int expected = Hashing.murmur3_32(seed).hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(seed, Slices.wrappedBuffer(data), 0, data.length); assertEquals(actual, expected); }
@Test(invocationCount = 100) public void testOffsetAndLength() throws Exception { byte[] data = randomBytes(131); int offset = 13; int length = 55; int expected = Hashing.murmur3_32().hashBytes(data, offset, length).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data), offset, length); assertEquals(actual, expected); }
@Test public void testTail() throws Exception { for (int i = 0; i < 4; i++) { byte[] data = randomBytes(50 + i); int expected = Hashing.murmur3_32().hashBytes(data).asInt(); int actual = Murmur3Hash32.hash(Slices.wrappedBuffer(data)); assertEquals(actual, expected); } }
@Benchmark public int hashInt(BenchmarkData data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_INT); return Murmur3Hash32.hash(data.getSlice(), 0, 4); }
@Benchmark public int specializedHashLong(SingleLong data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash32.hash(data.getValue()); }
@Benchmark public int specializedHashLong(SingleLong data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash32.hash(data.getValue()); }
@Benchmark public int specializedHashInt(SingleLong data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_INT); return Murmur3Hash32.hash((int) data.getValue()); }
@Benchmark public int hashLong(BenchmarkData data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash32.hash(data.getSlice(), 0, 8); }
@Benchmark public int hashLong(BenchmarkData data, ByteCounter counter) { counter.add(SizeOf.SIZE_OF_LONG); return Murmur3Hash32.hash(data.getSlice(), 0, 8); }
@Benchmark public int hash(BenchmarkData data, ByteCounter counter) { counter.add(data.getSlice().length()); return Murmur3Hash32.hash(data.getSlice()); }
@Benchmark public int hash(BenchmarkData data, ByteCounter counter) { counter.add(data.getSlice().length()); return Murmur3Hash32.hash(data.getSlice()); }