public static int binarySearch(byte[][] arr, byte[] key, int offset, int length) {
    int low = 0;
    int high = arr.length - 1;

    while (low <= high) {
      int mid = low + ((high - low) >> 1);
      // we have to compare in this order, because the comparator order
      // has special logic when the 'left side' is a special key.
      int cmp =
        Bytes.BYTES_RAWCOMPARATOR.compare(key, offset, length, arr[mid], 0, arr[mid].length);
      // key lives above the midpoint
      if (cmp > 0) low = mid + 1;
      // key lives below the midpoint
      else if (cmp < 0) high = mid - 1;
      // BAM. how often does this really happen?
      else return mid;
    }
    return -(low + 1);
  }
Binary search for keys in indexes using Bytes.BYTES_RAWCOMPARATOR.
@param arr    array of byte arrays to search for
@param key    the key you want to find
@param offset the offset in the key you want to find
@param length the length of the key
@return zero-based index of the key, if the key is present in the array. Otherwise, a value -(i
        + 1) such that the key is between arr[i - 1] and arr[i] non-inclusively, where i is in
        [0, i], if we define arr[-1] = -Inf and arr[N] = Inf for an N-element array. The above
        means that this function can return 2N + 1 different values ranging from -(N + 1) to N
        - 1.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java