bisectRight<T> function Bisecting data

int bisectRight<T>(
  1. List<T> list,
  2. T x, {
  3. int lo = 0,
  4. int? hi,
  5. num comparator(
    1. T,
    2. T
    ) = ascending,
})

Similar to bisectLeft, but returns an insertion point which comes after (to the right of) any existing entries of x in list.

The returned insertion point i partitions the list into two halves so that all v <= x for v in list.sublist(lo, i) for the left side and all v > x for v in list.sublist(i, hi) for the right side.

Implementation

int bisectRight<T>(List<T> list, T x,
    {int lo = 0, int? hi, num Function(T, T) comparator = ascending}) {
  hi ??= list.length;
  if (lo < hi) {
    if (comparator(x, x) != 0) return hi;
    do {
      var mid = (lo + hi!) >>> 1;
      if (comparator(list[mid], x) <= 0) {
        lo = mid + 1;
      } else {
        hi = mid;
      }
    } while (lo < hi);
  }
  return lo;
}