bsearch method

int bsearch(
  1. E x, {
  2. Comparator<E>? compare,
  3. int low = 0,
  4. int? high,
})

Assuming the list is sorted, locate the leftmost element exactly equal to x.

If the element is found, the index of element is returned. If not found, -1 is returned.

Implementation

int bsearch(E x, {Comparator<E>? compare, int low = 0, int? high}) {
  compare = argToComparator<E>(compare, null);
  final i = this.bisectLeft(x, compare: compare, low: low, high: high);
  if (i != this.length && compare(this[i], x) == 0) {
    return i;
  }
  return -1;
}