Heap<E> class

A priority queue implemented using a binary heap.

Inheritance
Available extensions

Constructors

Heap({Comparator<E>? comparator})
Constructs an empty max-heap with an optional comparator. To create a min-heap invert the comparator.
Heap.of(Iterable<E> iterable, {Comparator<E>? comparator})
Constructs a max-heap with an iterable of elements and an optional comparator. To create a min-heap invert the comparator.

Properties

first → E
The first element.
no setterinherited
firstOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The first element of this iterator, or null if the iterable is empty.
no setter
hashCode → int
The hash code for this object.
no setterinherited
indexed → Iterable<(int, T)>

Available on Iterable<T>, provided by the IterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmpty → bool
Whether this heap has no elements.
no setteroverride
isNotEmpty → bool
Whether this heap has at least one element.
no setteroverride
iterator → Iterator<E>
Returns an Iterator over the underlying values.
no setteroverride
last → E
The last element.
no setterinherited
lastOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The last element of this iterable, or null if the iterable is empty.
no setter
length → int
Returns the number of elements in this heap.
no setteroverride
nonNulls → Iterable<T>

Available on Iterable<T?>, provided by the NullableIterableExtensions extension

The non-null elements of this iterable.
no setter
peek → E
Returns the last/largest value from this heap.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
single → E
Checks that this iterable has only one element, and returns that element.
no setterinherited
singleOrNull → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The single element of this iterator, or null.
no setter
toJSIterable → JSIterable<T>

Available on Iterable<T>, provided by the IterableToJSIterable extension

A JSIterable wrapper that proxies to the Dart iterable API.
no setter
wait → Future<List<T>>

Available on Iterable<Future<T>>, provided by the FutureIterable extension

Waits for futures in parallel.
no setter

Methods

any(bool test(E element)) → bool
Checks whether any element of this iterable satisfies test.
inherited
asNameMap() → Map<String, T>

Available on Iterable<T>, provided by the EnumByName extension

Creates a map from the names of enum values to the values.
atRandom({Random? random, E orElse()?}) → E

Available on Iterable<E>, provided by the RandomExtension extension

Returns a random element from this Iterable.
byName(String name) → T

Available on Iterable<T>, provided by the EnumByName extension

Finds the enum value in this list with name name.
cast<R>() → Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
chunked(int size) → Iterable<List<E>>

Available on Iterable<E>, provided by the ChunkedExtension extension

Divides this Iterable into sub-lists of a given size. The final list might be smaller or equal to the desired size.
chunkedWithPadding(int size, E padding) → Iterable<Iterable<E>>

Available on Iterable<E>, provided by the ChunkedExtension extension

Divides this Iterable into sub-lists of a given size. The final list is expanded with the provided padding, or null.
clear() → void
Removes all objects from this heap.
combinations(int count, {bool repetitions = false}) → Iterable<List<E>>

Available on Iterable<E>, provided by the CombinationsExtension extension

Returns an iterable over the combinations of this Iterable of length count. The combinations are emitted in lexicographical order based on the input.
contains(Object? element) → bool
Whether the collection contains an element equal to element.
inherited
count(bool predicate(E element)) → int

Available on Iterable<E>, provided by the CountIterableExtension extension

Returns the number of time predicate evaluates to true.
cycle([int? count]) → Iterable<E>

Available on Iterable<E>, provided by the RepeatIterableExtension extension

Deprecated alias for repeat.
elementAt(int index) → E
Returns the indexth element.
inherited
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableExtensions extension

The element at position index of this iterable, or null.
every(bool test(E element)) → bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(E element)) → Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(E element), {E orElse()?}) → E
The first element that satisfies the given predicate test.
inherited
flatMap<T>(Iterable<T> callback(E element)) → Iterable<T>

Available on Iterable<E>, provided by the FlatMapExtension extension

Maps each element of this Iterable using a mapping function to zero or more elements, then flattens the result into a continuous iterable.
flatten() → Iterable<E>

Available on Iterable<Iterable<E>>, provided by the FlattenExtension extension

Flattens an Iterable of Iterables to a flattened Iterable.
fold<T>(T initialValue, T combine(T previousValue, E element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<E> other) → Iterable<E>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(E element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
groupBy<K>([K key(V element)?]) → Iterable<Group<K, V>>

Available on Iterable<V>, provided by the GroupExtension extension

Groups consecutive keys of this Iterable.
indexed({int offset = 0}) → Iterable<Indexed<E>>

Available on Iterable<E>, provided by the IndexedExtension extension

Returns a iterable that combines the index and value of this Iterable.
indices({int step = 1}) → Range<int>

Available on Iterable<Object?>, provided by the IndicesIterableExtension extension

Returns a Range of the indices of this iterable that can be accessed with the [] operator.
join([String separator = ""]) → String
Converts each element to a String and concatenates the strings.
inherited
largest(int count, {Comparator<E>? comparator}) → List<E>

Available on Iterable<E>, provided by the OperatorsExtension extension

Returns a list of the count largest elements of this Iterable. The elements need to be Comparable, unless a custom comparator is provided.
lastWhere(bool test(E element), {E orElse()?}) → E
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(E e)) → Iterable<T>
The current elements of this iterable modified by toElement.
inherited
max({Comparator<E>? comparator, E orElse()?}) → E

Available on Iterable<E>, provided by the OperatorsExtension extension

Returns the maximum of this Iterable. The elements need to be Comparable, unless a custom comparator is provided.
min({Comparator<E>? comparator, E orElse()?}) → E

Available on Iterable<E>, provided by the OperatorsExtension extension

Returns the minimum of this Iterable. The elements need to be Comparable, unless a custom comparator is provided.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
permutations([int? count]) → Iterable<List<E>>

Available on Iterable<E>, provided by the PermutationIterableExtension extension

Returns an iterable over the permutations of this Iterable of length count. If no count is specified all full-length permutations are generated. The permutations are emitted in lexicographical order based on the input.
polynomial([num x = 10]) → num

Available on Iterable<num>, provided by the PolynomialIterableExtension extension

Evaluates the polynomial described by this Iterables coefficients and the value x.
pop() → E
Removes and returns the last/largest value from this heap.
popAndPush(E value) → E
A pop immediately followed by a push. Contrary to pushAndPop this requires a non-empty heap and never returns value.
powerSet() → Iterable<List<E>>

Available on Iterable<E>, provided by the PowerSetExtension extension

Returns all subsets of this iterable including the empty set and the complete set itself. The power-set has 2^n elements, if the iterable has length n.
product({int repeat = 1}) → Iterable<List<E>>

Available on Iterable<Iterable<E>>, provided by the ProductExtension extension

Returns an iterable over the cross product of this Iterable.
push(E value) → void
Adds a new value onto this heap.
pushAll(Iterable<E> values) → void
Adds multiple new values onto this heap.
pushAndPop(E value) → E
A push immediately followed by a pop. Contrary to popAndPush this works on an empty heap and might directly return value.
reduce(E combine(E value, E element)) → E
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
repeat({int? count}) → Iterable<E>

Available on Iterable<E>, provided by the RepeatIterableExtension extension

Returns an infinite iterable with the elements of this iterable. If count is provided the resulting iterator is limited to count repetitions.
separatedBy(Builder<E> separator, {Builder<E>? before, Builder<E>? after}) → Iterable<E>

Available on Iterable<E>, provided by the SeparatedExtension extension

Returns an Iterable where every element is separated by an element built by a separator builder. Optionally specified before and after builders can provide an element at the beginning or the end of the non-empty iterable.
singleWhere(bool test(E element), {E orElse()?}) → E
The single element that satisfies test.
inherited
skip(int count) → Iterable<E>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(E element)) → Iterable<E>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
smallest(int count, {Comparator<E>? comparator}) → List<E>

Available on Iterable<E>, provided by the OperatorsExtension extension

Returns a list of the count smallest elements of this Iterable. The elements need to be Comparable, unless a custom comparator is provided.
take(int count) → Iterable<E>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(E element)) → Iterable<E>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toBiMap<K, V>({K key(E element)?, V value(E element)?}) → BiMap<K, V>

Available on Iterable<E>, provided by the BiMapOnIterableExtension extension

Converts this Iterable to a BiMap.
toBitList({bool growable = false}) → BitList

Available on Iterable<bool>, provided by the BitListExtension extension

Converts this Iterable to a space-efficient BitList.
toComparator() → Comparator<T>

Available on Iterable<Comparator<T>>, provided by the CompoundIterableComparator extension

Returns a Comparator that tries each of the comparators in this iterable in order and returns the first result that doesn't end up in a tie.
toList({bool growable = true}) → List<E>
Creates a List containing the elements of this Iterable.
inherited
toListMultimap<K, V>({K key(E element)?, V value(E element)?, Map<K, List<V>>? map, Factory<List<V>>? factory}) → ListMultimap<K, V>

Available on Iterable<E>, provided by the ListMultimapOnIterableExtension extension

Converts this Iterable to a ListMultimap.
toMap<K, V>({K key(E element)?, V value(E element)?}) → Map<K, V>

Available on Iterable<E>, provided by the ToMapExtension extension

Returns an Map from an Iterable.
toMultiset() → Multiset<T>

Available on Iterable<T>, provided by the MultisetExtension extension

toPrinter() → Printer<T>

Available on Iterable<Printer<T>>, provided by the SequencePrinterIterableExtension extension

Constructs a sequence of printers.
toSet() → Set<E>
Creates a Set containing the same elements as this iterable.
inherited
toSetMultimap<K, V>({K key(E element)?, V value(E element)?, Map<K, Set<V>>? map, Factory<Set<V>>? factory}) → SetMultimap<K, V>

Available on Iterable<E>, provided by the SetMultimapOnIterableExtension extension

Converts this Iterable to a SetMultimap.
toSortedList({Comparator<E>? comparator}) → SortedList<E>

Available on Iterable<E>, provided by the SortedListIterableExtension extension

Converts this Iterable to a SortedList.
toString() → String
Returns a string representation of (some of) the elements of this.
inherited
unique({bool equals(E e1, E e2)?, int hashCode(E e)?}) → Iterable<E>

Available on Iterable<E>, provided by the UniqueExtension extension

Returns a lazy iterable that filters out duplicates from this Iterator. If equals and hashCode are omitted, the iterator uses the objects' intrinsic Object.operator== and Object.hashCode for comparison.
where(bool test(E element)) → Iterable<E>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() → Iterable<R>
Creates a new lazy Iterable with all elements that have type T.
inherited
window(int size, {int step = 1, bool includePartial = false}) → Iterable<List<E>>

Available on Iterable<E>, provided by the WindowExtension extension

Sliding window of given size over this Iterable.
zip() → Iterable<List<E>>

Available on Iterable<Iterable<E>>, provided by the ZipExtension extension

Combines the first, second, third, ... elements of each Iterable into a new list. The resulting iterable has the length of the shortest input iterable.
zipPartial() → Iterable<List<E?>>

Available on Iterable<Iterable<E>>, provided by the ZipExtension extension

Combines the first, second, third, ... elements of each Iterable into a new list. The resulting iterable has the length of the longest input iterable, missing values are padded with null.
zipPartialWith(E padding) → Iterable<List<E>>

Available on Iterable<Iterable<E>>, provided by the ZipExtension extension

Combines the first, second, third, ... elements of each Iterable into a new list. The resulting iterable has the length of the longest input iterable, missing values are padded with padding.

Operators

operator ==(Object other) → bool
The equality operator.
inherited