Like Java Collections.binarySearch(List, key, Comparator).

@return the index>=0 where the item was found,
or the index<0 for inserting the string at ~index in sorted order
(index into rootPrimaryIndexes)
970510
private static final int binarySearchForRootPrimaryNode(
            int[] rootPrimaryIndexes, int length, long[] nodes, long p) {
        if(length == 0) { return ~0; }
        int start = 0;
        int limit = length;
        for (;;) {
            int i = (int)(((long)start + (long)limit) / 2);
            long node = nodes[rootPrimaryIndexes[i]];
            long nodePrimary = node >>> 32;  // weight32FromNode(node)
            if (p == nodePrimary) {
                return i;
            } else if (p < nodePrimary) {
                if (i == start) {
                    return ~start;  // insert s before i
                }
                limit = i;
            } else {
                if (i == start) {
                    return ~(start + 1);  // insert s after i
                }
                start = i;
            }
        }
    }
783037
private static int unsignedBinarySearch(int[] a, int fromIndex, int toIndex, int key,
      Comparator<? super Integer> c) {
    int low = fromIndex;
    int high = toIndex - 1;

    while (low <= high) {
      int mid = (low + high) >>> 1;
      int midVal = a[mid];
      int cmp = c.compare(midVal, key);
      if (cmp < 0) {
        low = mid + 1;
      } else if (cmp > 0) {
        high = mid - 1;
      } else {
        return mid; // key found
      }
    }
    return -(low + 1); // key not found.
  }
715220
public int getIndex(Object item) {
	  if (!itemIndex.containsKey(item)) {
	    throw new NoSuchElementException("No such item: " + item);
	  }
		return itemIndex.get(item);
	}
648727
public int getIndexForPosition(int position) {
        int nSections = 0;

        Set<Entry<String, Integer>> entrySet = mSections.entrySet();
        for(Entry<String, Integer> entry : entrySet) {
            if(entry.getValue() < position) {
                nSections++;
            }
        }

        return position - nSections;
    }
1161095
private int findEqual(
    SearchComparator  comp,
    int               lower,
    int               upper,
    Object            searchKey)
  {
    int nkeys = numKeys(lower, upper);
    int idx = -1;
    if (nkeys < 4)
      idx = sequentialSearchEqual(comp, lower, upper, searchKey);
    else
      idx = binarySearchEqual(comp, lower, upper, searchKey);
    return idx;
  }
518379
public static <T> int binarySearch(final T[] a, final T key, final Comparator<? super T> cmp) {
        return Array.binarySearch(a, key, cmp);
    }
694172
private int binarySearch(T record) {
		int low = 0;
		int high = this.boundaries.length - 1;
		typeComparator.extractKeys(record, keys, 0);

		while (low <= high) {
			final int mid = (low + high) >>> 1;
			final int result = compareKeys(flatComparators, keys, this.boundaries[mid]);

			if (result > 0) {
				low = mid + 1;
			} else if (result < 0) {
				high = mid - 1;
			} else {
				return mid;
			}
		}
		// key not found, but the low index is the target
		// bucket, since the boundaries are the upper bound
		return low;
	}
917189
public int binarySearch(final int fromIndex, final int toIndex, final int key) {
        checkFromToIndex(fromIndex, toIndex);

        return N.binarySearch(elementData, fromIndex, toIndex, key);
    }
764700
public static <E, K extends Comparable> int binarySearch(
      List<E> list,
      Function<? super E, K> keyFunction,
      @Nullable K key,
      KeyPresentBehavior presentBehavior,
      KeyAbsentBehavior absentBehavior) {
    return binarySearch(
        list, keyFunction, key, Ordering.natural(), presentBehavior, absentBehavior);
  }
972648
function indexOf(element, fromIndex) {
    /* jshint validthis:true */
    var arr = toArray(this),
        index;

    if (fromIndex) {
        arr = arr.slice(fromIndex);
    }

    index = binarySearch(arr, element, this.comparator);

    if (index < 0) {
        return -1;
    } else {
        return index;
    }
}
780573
public static int binarySearch(final char[] a, final int fromIndex, final int toIndex, final char key) {
        return Array.binarySearch(a, fromIndex, toIndex, key);
    }
937481
public static int binarySearch(BaseNode[] branches, BaseNode node)
    {
        int high = branches.length - 1;
        if (branches.length < 1)
        {
            return high;
        }
        int low = 0;
        while (low <= high)
        {
            int mid = (low + high) >>> 1;
            int cmp = branches[mid].compareTo(node);

            if (cmp < 0)
                low = mid + 1;
            else if (cmp > 0)
                high = mid - 1;
            else
                return mid;
        }
        return -(low + 1);
    }
23056
private int binarySearch(SimpleMDAGNode[] mdagDataArray, char node)
    {
        if (transitionSetSize < 1)
        {
            return -1;
        }
        int high = transitionSetBeginIndex + transitionSetSize - 1;
        int low = transitionSetBeginIndex;
        while (low <= high)
        {
            int mid = ((low + high) >>> 1);
            int cmp = mdagDataArray[mid].getLetter() - node;

            if (cmp < 0)
                low = mid + 1;
            else if (cmp > 0)
                high = mid - 1;
            else
                return mid;
        }
        return -1;
    }
40673
private int binarySearchNonUnique(int fromIndex, int toIndex, long key1, long key2) {
		int low = fromIndex;
		int high = toIndex - 1;

		while (low <= high) {
			int mid = (low + high) >>> 1;
			long midVal1 = keys[mid];
			long midVal2 = values[mid];

        	if (midVal1 < key1) {
        		low = mid + 1;
        	} else if (midVal1 > key1) {
        		high = mid - 1;
        	} else {
            	if (midVal2 < key2) {
            		low = mid + 1;
            	} else if (midVal2 > key2) {
            		high = mid - 1;
            	} else {
            		return mid; // key found
            	}
        	}
		}
		return -(low + 1);  // key not found.
	}
709980
protected static int binarySearchGuess(@NotNull final BasePage page, @NotNull final ByteIterable key) {
        int index = binarySearchGuessUnsafe(page, key);
        if (index < 0) index = 0;
        return index;
    }
52669
public Integer getFirstPosition(String key) {
        int position = -1;
        String processedKey = processKey(key);

        if (this.values.containsKey(processedKey) == true) {
            position = this.order.indexOf(processedKey);
        }
        return position;
    }
1371022
int binarySearch(int fromIndex, int toIndex, long key, long value) {
		if (ind.isUnique()) {
			return binarySearchUnique(fromIndex, toIndex, key);
		}
		return binarySearchNonUnique(fromIndex, toIndex, key, value);
	}