class 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);
    }

    // Cut range in half and search again
    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);
  }

}