binarySearch static method

int binarySearch(
  1. List<double> values,
  2. double target, [
  3. int step = 1
])

Implementation

static int binarySearch(List<double> values, double target, [int step = 1]) {
  int low = 0;
  int high = values.length ~/ step - 2;
  if (high == 0) return step;
  int current = high >> 1;
  for (;;) {
    if (values[(current + 1) * step] <= target) {
      low = current + 1;
    } else {
      high = current;
    }
    if (low == high) return (low + 1) * step;
    current = (low + high) >> 1;
  }
}