static int generalizedBinarySearch(L l, B key, IF2 cmp) {
ret generalizedBinarySearch(l, 0, l(l), key, cmp);
}
static int generalizedBinarySearch(L l, int fromIndex, int toIndex, B key, IF2 cmp) {
int low = fromIndex;
int high = toIndex - 1;
while (low <= high) {
int mid = (low + high) >>> 1;
A midVal = l.get(mid);
int c = cmp.get(midVal, key);
if (c < 0)
low = mid + 1;
else if (c > 0)
high = mid - 1;
else
ret mid; // key found
}
ret -(low + 1); // key not found.
}