public int hashUnsafeWords(Object base, long offset, int lengthInBytes) { return hashUnsafeWords(base, offset, lengthInBytes, seed); }
@Test public void randomizedStressTestBytes() { final Murmur3_x86_32 hasher = new Murmur3_x86_32(0); final int size = 65536; final Random random = new Random(); // A set used to track collision rate. final Set<Integer> hashcodes = new HashSet<>(); for (int i = 0; i < size; i++) { final int byteArrSize = random.nextInt(100) * 8; final byte[] bytes = new byte[byteArrSize]; random.nextBytes(bytes); assertEquals( hasher.hashUnsafeWords(bytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize), hasher.hashUnsafeWords(bytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize)); hashcodes.add(hasher.hashUnsafeWords(bytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize)); } // A very loose bound. assertTrue(hashcodes.size() > size * 0.95); }
@Test public void randomizedStressTestPaddedStrings() { final Murmur3_x86_32 hasher = new Murmur3_x86_32(0); final int size = 64000; // A set used to track collision rate. final Set<Integer> hashcodes = new HashSet<>(); for (int i = 0; i < size; i++) { final int byteArrSize = 8; final byte[] strBytes = String.valueOf(i).getBytes(StandardCharsets.UTF_8); final byte[] paddedBytes = new byte[byteArrSize]; System.arraycopy(strBytes, 0, paddedBytes, 0, strBytes.length); assertEquals( hasher.hashUnsafeWords(paddedBytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize), hasher.hashUnsafeWords(paddedBytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize)); hashcodes.add(hasher.hashUnsafeWords(paddedBytes, Platform.BYTE_ARRAY_OFFSET, byteArrSize)); } // A very loose bound. assertTrue(hashcodes.size() > size * 0.95); } }