private int getRegionIndex(List<Pair<byte[], byte[]>> startEndKeys, byte[] key) {
    int idx = Collections.binarySearch(startEndKeys, Pair.newPair(key, HConstants.EMPTY_END_ROW),
      (p1, p2) -> Bytes.compareTo(p1.getFirst(), p2.getFirst()));
    if (idx < 0) {
      // not on boundary, returns -(insertion index). Calculate region it
      // would be in.
      idx = -(idx + 1) - 1;
    }
    return idx;
  }
@param startEndKeys the start/end keys of regions belong to this table, the list in ascending
                    order by start key
@param key          the key need to find which region belong to
@return region index
hbase-server/src/main/java/org/apache/hadoop/hbase/tool/BulkLoadHFilesTool.java