static int intArrayBinarySearchWithGeneralizedComparator(int[] a, IF1_IntToInt comparator) { ret intArrayBinarySearchWithGeneralizedComparator(a, 0, a.length, comparator); } static int intArrayBinarySearchWithGeneralizedComparator(int[] a, int fromIndex, int toIndex, IF1_IntToInt comparator) { int low = fromIndex; int high = toIndex - 1; while (low <= high) { int mid = (low + high) >>> 1; int midVal = a[mid]; int cmp = comparator.get(midVal); ifdef intArrayBinarySearchWithGeneralizedComparator_debug printVars_str(+low, +high, +mid, +midVal, +cmp); endifdef if (cmp < 0) low = mid + 1; else if (cmp > 0) high = mid - 1; else ret mid; // key found } ret -(low + 1); // key not found. }