private int find(T needle) {
    int begin = minCellIdx;
    int end = maxCellIdx - 1;

    while (begin <= end) {
      int mid = begin + ((end - begin) >> 1);
      T midCell = getCell(mid);
      int compareRes = comparator.compare(midCell, needle);

      if (compareRes == 0) {
        return mid; // 0 means equals. We found the key
      }
      // Key not found. Check the comparison results; reverse the meaning of
      // the comparison in case the order is descending (using XOR)
      if ((compareRes < 0) ^ descending) {
        // midCell is less than needle so we need to look at farther up
        begin = mid + 1;
      } else {
        // midCell is greater than needle so we need to look down
        end = mid - 1;
      }
    }

    return (-1 * begin) - 1;
  }
Binary search for a given key in between given boundaries of the array. Positive returned
numbers mean the index. Negative returned numbers means the key not found. The absolute value
of the output is the possible insert index for the searched key In twos-complement, (-1 *
insertion point)-1 is the bitwise not of the insert point.
@param needle The key to look for in all of the entries
@return Same return value as Arrays.binarySearch.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CellFlatMap.java