lowerBound<T> function

int lowerBound<T>(
  1. List<T> array,
  2. T value,
  3. Comparator comparator
)

Implementation

int lowerBound<T>( List<T> array, T value, Comparator comparator) {
  int first = 0;
  int count = array.length;
  while (count > 0) {
    int step = ((count / 2).truncate() | 0);
    int it = first + step;

    if ( comparator(array[it], value) <= 0) {
      first = ++it;
      count -= step + 1;
    } else {
      count = step;
    }
  }
  return first;
}