// finds highest index where predicate is true. // returns from-1 when predicate is false on whole range. // Predicate operates on a range and returns true // iff any value in the range is contained in the set. static int lastIndexOfRangePredicate_IIntIntPred(int from default 0, int to, IIntIntPred pred) { // interval empty? if (from >= to) ret from-1; // predicate false on whole range? if (!pred.get(from, to)) ret from-1; while ping (to-from > 1) { // predicate is true somewhere in range. split in middle. int mid = (from + to) >>> 1; // check higher half if (pred.get(mid, to)) // predicate is true in higher half. move there. from = mid; else // higher half is clean, move to lower half to = mid; } // we've narrowed things down to one element, return index ret from; }