private static int binarySearch( StructuredArray<Entry> entries, int fromIndex, int toIndex, Object key, Comparator c) { int low = fromIndex; int high = toIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; Object midVal = entries.get(mid).getKey(); int cmp = compare(c, 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. }