TinyQueue<T> constructor

TinyQueue<T>([
  1. Iterable<T>? data,
  2. Comparator<T>? compare
])

Constructs a new queue.

Adding all elements at once would be faster than using push for each one. If elements are not Comparable, specify the compare function.

Implementation

TinyQueue([Iterable<T>? data, Comparator<T>? compare])
    : data = data?.toList() ?? [],
      length = data?.length ?? 0,
      compare = compare ?? ((a, b) => (a as Comparable).compareTo(b)) {
  if (length > 0) {
    for (var i = (length >> 1) - 1; i >= 0; i--) {
      _down(i);
    }
  }
}