RollingHash { public long Hash(byte[] data, int offset, int length) { long h = RollingHashUtil.HashFirstTwoBytes(data, offset); for (int i = 2; i < window_size; ++i) { h = RollingHashUtil.HashStep(h, data[offset + i]); } return h; } RollingHash(int window_size); long Hash(byte[] data, int offset, int length); long Hash(ByteBuffer data); long UpdateHash(long old_hash, byte old_first_byte, byte new_last_byte);  }
@Test public void testAgainstCppResults() { Random random = new Random(1); byte[] buffer = new byte[4096]; random.nextBytes(buffer); CRC32 crc32 = new CRC32(); crc32.update(buffer); assertEquals(0x83402f90, (int) crc32.getValue()); int[] expectedHashes = new int[]{ 0xefa82, 0x546aae, 0x44eaf, 0x6b4d62, 0x5c9691, 0x546486, 0x3dc508, 0x45123c, }; for (int windowSize = 16, i = 0; i < expectedHashes.length; i++, windowSize <<= 1) { RollingHash hasher = new RollingHash(windowSize); assertEquals(expectedHashes[i], hasher.Hash(buffer, 0, buffer.length)); } }