private static <L, R> int compareRows(L left, int loffset, int llength, R right, int roffset,
    int rlength, SearchDelimiter<L> searchLeft, SearchDelimiter<R> searchRight,
    SearchDelimiterInReverse<L> searchInReverseLeft,
    SearchDelimiterInReverse<R> searchInReverseRight, Compare<L, R> comparator) {
    int leftDelimiter = searchLeft.search(left, loffset, llength, HConstants.DELIMITER);
    int rightDelimiter = searchRight.search(right, roffset, rlength, HConstants.DELIMITER);
    // Compare up to the delimiter
    int lpart = (leftDelimiter < 0 ? llength : leftDelimiter - loffset);
    int rpart = (rightDelimiter < 0 ? rlength : rightDelimiter - roffset);
    int result = comparator.compareTo(left, loffset, lpart, right, roffset, rpart);
    if (result != 0) {
      return result;
    } else {
      if (leftDelimiter < 0 && rightDelimiter >= 0) {
        return -1;
      } else if (rightDelimiter < 0 && leftDelimiter >= 0) {
        return 1;
      } else if (leftDelimiter < 0) {
        return 0;
      }
    }
    // Compare middle bit of the row.
    // Move past delimiter
    leftDelimiter++;
    rightDelimiter++;
    int leftFarDelimiter = searchInReverseLeft.search(left, leftDelimiter,
      llength - (leftDelimiter - loffset), HConstants.DELIMITER);
    int rightFarDelimiter = searchInReverseRight.search(right, rightDelimiter,
      rlength - (rightDelimiter - roffset), HConstants.DELIMITER);
    // Now compare middlesection of row.
    lpart = (leftFarDelimiter < 0 ? llength + loffset : leftFarDelimiter) - leftDelimiter;
    rpart = (rightFarDelimiter < 0 ? rlength + roffset : rightFarDelimiter) - rightDelimiter;
    result = comparator.compareTo(left, leftDelimiter, lpart, right, rightDelimiter, rpart);
    if (result != 0) {
      return result;
    } else {
      if (leftDelimiter < 0 && rightDelimiter >= 0) {
        return -1;
      } else if (rightDelimiter < 0 && leftDelimiter >= 0) {
        return 1;
      } else if (leftDelimiter < 0) {
        return 0;
      }
    }
    // Compare last part of row, the rowid.
    leftFarDelimiter++;
    rightFarDelimiter++;
    result = comparator.compareTo(left, leftFarDelimiter, llength - (leftFarDelimiter - loffset),
      right, rightFarDelimiter, rlength - (rightFarDelimiter - roffset));
    return result;
  }
A {@link MetaCellComparator} for <code>hbase:meta</code> catalog table {@link KeyValue}s.
hbase-common/src/main/java/org/apache/hadoop/hbase/MetaCellComparator.java