partitionPoint method

int partitionPoint(
  1. bool predicate(
    1. T
    )
)

Returns the index of the partition point according to the given predicate (the index of the first element of the second partition). The slice is assumed to be partitioned according to the given predicate. This means that all elements for which the predicate returns true are at the start of the slice and all elements for which the predicate returns false are at the end. For example, 7, 15, 3, 5, 4, 12, 6 is partitioned under the predicate x % 2 != 0 (all odd numbers are at the start, all even at the end). If this slice is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.

Implementation

int partitionPoint(bool Function(T) predicate) {
  int low = 0;
  int high = length;

  while (low < high) {
    int mid = (low + high) >> 1;
    if (predicate(getUnchecked(mid))) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }

  return low;
}