int find(K needle) {
      int begin = startIndex;
      int end = endIndex - 1;

      while (begin <= end) {
        int mid = begin + ((end - begin) / 2);
        K midKey = entries[mid].key;
        int compareRes = keyComparator.compare(midKey, needle);

        // 0 means equals
        // We found the key.
        if (compareRes == 0) {
          return mid;
        } else if (compareRes < 0) {
          // midKey is less than needle so we need
          // to look at farther up
          begin = mid + 1;
        } else {
          // midKey is greater than needle so we
          // need to look down.
          end = mid - 1;
        }
      }

      return (-1 * begin) - 1;
    }
Binary search for a given key
@param needle The key to look for in all of the entries
@return Same return value as Arrays.binarySearch. Positive numbers mean the index. Otherwise
        (-1 * insertion point) - 1
hbase-common/src/main/java/org/apache/hadoop/hbase/types/CopyOnWriteArrayMap.java