binarySearchBy<K extends Comparable<K>> method Null safety

int binarySearchBy<K extends Comparable<K>>(
  1. E element,
  2. K keyOf(
    1. E element
  3. [int start = 0,
  4. int? end]

Returns the index of element in this sorted list.

Uses binary search to find the location of element. This takes on the order of log(n) comparisons. The list must be sorted according to the natural ordering of the keyOf of elements, otherwise the result is unspecified.

Returns -1 if element does not occur in this list.

If start and end are supplied, only the list range from start to end is searched, and only that range needs to be sorted.


int binarySearchBy<K extends Comparable<K>>(
        E element, K Function(E element) keyOf, [int start = 0, int? end]) =>
    algorithms.binarySearchBy<E, K>(
        this, keyOf, (a, b) => a.compareTo(b), element, start, end);