BlockHash { protected static int MatchingBytesToRight(ByteBuffer source_match_end, int source_match_end_offset, byte[] target_match_end, int target_match_end_offset, int max_bytes) { int bytes_found = 0; while ((bytes_found < max_bytes) && (source_match_end.get(source_match_end_offset) == target_match_end[target_match_end_offset])) { ++bytes_found; ++source_match_end_offset; ++target_match_end_offset; } return bytes_found; } BlockHash(byte[] source_data, int starting_offset, boolean populate_hash_table);  BlockHash(ByteBuffer source_data, int starting_offset, boolean populate_hash_table); static BlockHash CreateDictionaryHash(byte[] dictionary_data); static BlockHash CreateTargetHash(byte[] target_data, int dictionary_size); static BlockHash CreateTargetHash(ByteBuffer target_data, int dictionary_size); void AddOneIndexHash(int index, int hash_value); void AddAllBlocksThroughIndex(int end_index); void FindBestMatch(int hash_value, ByteBuffer target, Match best_match); void FindBestMatch(int hash_value, byte[] target_candidate, int target_candidate_start, byte[] target, int target_start, Match best_match); static final int kBlockSize; }
@Test public void RightLimitedByMaxBytes() throws UnsupportedEncodingException { final int expected_length = (kBlockSize * "fearsom".getBytes(StandardCharsets.US_ASCII).length) + (kBlockSize - 1); final int max_bytes = expected_length - 1; Assert.assertEquals(max_bytes, BlockHash.MatchingBytesToRight( search_string, index_of_f_in_fearsome, search_string_altered, index_of_f_in_fearsome, max_bytes)); }
@Test public void RightNotLimited() throws UnsupportedEncodingException { final int expected_length = (kBlockSize * "fearsom".getBytes(StandardCharsets.US_ASCII).length) + (kBlockSize - 1); final int max_bytes = expected_length + 1; Assert.assertEquals(expected_length, BlockHash.MatchingBytesToRight( search_string, index_of_f_in_fearsome, search_string_altered, index_of_f_in_fearsome, max_bytes)); Assert.assertEquals(expected_length, BlockHash.MatchingBytesToRight( search_string, index_of_f_in_fearsome, search_string_altered, index_of_f_in_fearsome, Integer.MAX_VALUE)); }