@Test public void searchForMatchShortGroupArrayTest() throws IOException { final String s1 = "asdf;1234;this should match;5678"; final String s2 = "hkjl.9999.00vbn,``'=-this should match.9900-mmmnmn,,,.x??'"; final byte[] s1b = s1.getBytes(Charset.forName("US-ASCII")); final byte[] s2b = s2.getBytes(Charset.forName("US-ASCII")); final RandomAccessObject s1ro = new RandomAccessObject.RandomAccessByteArrayObject(s1b); final RandomAccessObject s2ro = new RandomAccessObject.RandomAccessByteArrayObject(s2b); final RandomAccessObject groupArrayRO = intArrayToRandomAccessObject(BsDiffTestData.SHORT_GROUP_ARRAY); BsDiff.Match ret = BsDiff.searchForMatch(groupArrayRO, s1ro, s2ro, 0, 0, 12); Assert.assertEquals(0, ret.length); Assert.assertEquals(10, ret.start); }
static Match searchForMatch( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { if (oldDataRangeStartB - oldDataRangeStartA < 2) { return searchForMatchBaseCase( groupArray, oldData, newData, newStart, oldDataRangeStartA, oldDataRangeStartB); } final int rangeLength = oldDataRangeStartB - oldDataRangeStartA; final int pivot = oldDataRangeStartA + (rangeLength / 2); groupArray.seekToIntAligned(pivot); final int groupArrayPivot = groupArray.readInt(); if (BsUtil.lexicographicalCompare( oldData, groupArrayPivot, (int) oldData.length() - groupArrayPivot, newData, newStart, (int) newData.length() - newStart) < 0) { return searchForMatch(groupArray, oldData, newData, newStart, pivot, oldDataRangeStartB); } return searchForMatch(groupArray, oldData, newData, newStart, oldDataRangeStartA, pivot); }
BsDiff { static Match searchForMatch( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { if (oldDataRangeStartB - oldDataRangeStartA < 2) { return searchForMatchBaseCase( groupArray, oldData, newData, newStart, oldDataRangeStartA, oldDataRangeStartB); } final int rangeLength = oldDataRangeStartB - oldDataRangeStartA; final int pivot = oldDataRangeStartA + (rangeLength / 2); groupArray.seekToIntAligned(pivot); final int groupArrayPivot = groupArray.readInt(); if (BsUtil.lexicographicalCompare( oldData, groupArrayPivot, (int) oldData.length() - groupArrayPivot, newData, newStart, (int) newData.length() - newStart) < 0) { return searchForMatch(groupArray, oldData, newData, newStart, pivot, oldDataRangeStartB); } return searchForMatch(groupArray, oldData, newData, newStart, oldDataRangeStartA, pivot); } }
BsDiff { static Match searchForMatch( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { if (oldDataRangeStartB - oldDataRangeStartA < 2) { return searchForMatchBaseCase( groupArray, oldData, newData, newStart, oldDataRangeStartA, oldDataRangeStartB); } final int rangeLength = oldDataRangeStartB - oldDataRangeStartA; final int pivot = oldDataRangeStartA + (rangeLength / 2); groupArray.seekToIntAligned(pivot); final int groupArrayPivot = groupArray.readInt(); if (BsUtil.lexicographicalCompare( oldData, groupArrayPivot, (int) oldData.length() - groupArrayPivot, newData, newStart, (int) newData.length() - newStart) < 0) { return searchForMatch(groupArray, oldData, newData, newStart, pivot, oldDataRangeStartB); } return searchForMatch(groupArray, oldData, newData, newStart, oldDataRangeStartA, pivot); }  }
BsDiff { static Match searchForMatch( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { if (oldDataRangeStartB - oldDataRangeStartA < 2) { return searchForMatchBaseCase( groupArray, oldData, newData, newStart, oldDataRangeStartA, oldDataRangeStartB); } final int rangeLength = oldDataRangeStartB - oldDataRangeStartA; final int pivot = oldDataRangeStartA + (rangeLength / 2); groupArray.seekToIntAligned(pivot); final int groupArrayPivot = groupArray.readInt(); if (BsUtil.lexicographicalCompare( oldData, groupArrayPivot, (int) oldData.length() - groupArrayPivot, newData, newStart, (int) newData.length() - newStart) < 0) { return searchForMatch(groupArray, oldData, newData, newStart, pivot, oldDataRangeStartB); } return searchForMatch(groupArray, oldData, newData, newStart, oldDataRangeStartA, pivot); }   }
BsDiff { static Match searchForMatch( final RandomAccessObject groupArray, final RandomAccessObject oldData, final RandomAccessObject newData, final int newStart, final int oldDataRangeStartA, final int oldDataRangeStartB) throws IOException { if (oldDataRangeStartB - oldDataRangeStartA < 2) { return searchForMatchBaseCase( groupArray, oldData, newData, newStart, oldDataRangeStartA, oldDataRangeStartB); } final int rangeLength = oldDataRangeStartB - oldDataRangeStartA; final int pivot = oldDataRangeStartA + (rangeLength / 2); groupArray.seekToIntAligned(pivot); final int groupArrayPivot = groupArray.readInt(); if (BsUtil.lexicographicalCompare( oldData, groupArrayPivot, (int) oldData.length() - groupArrayPivot, newData, newStart, (int) newData.length() - newStart) < 0) { return searchForMatch(groupArray, oldData, newData, newStart, pivot, oldDataRangeStartB); } return searchForMatch(groupArray, oldData, newData, newStart, oldDataRangeStartA, pivot); }    }