HeapPriorityQueue<E> class Null safety

Heap based priority queue.

The elements are kept in a heap structure, where the element with the highest priority is immediately accessible, and modifying a single element takes logarithmic time in the number of elements on average.

  • The add and removeFirst operations take amortized logarithmic time, O(log(n)), but may occasionally take linear time when growing the capacity of the heap.
  • The addAll operation works as doing repeated add operations.
  • The first getter takes constant time, O(1).
  • The clear and removeAll methods also take constant time, O(1).
  • The contains and remove operations may need to search the entire queue for the elements, taking O(n) time.
  • The toList operation effectively sorts the elements, taking O(n*log(n)) time.
  • The toUnorderedList operation copies, but does not sort, the elements, and is linear, O(n).
  • The toSet operation effectively adds each element to the new set, taking an expected O(n*log(n)) time.
Implemented types


HeapPriorityQueue([int comparison(E, E)?])
Create a new priority queue.


comparison Comparator<E>
The comparison being used to compare the priority of elements.
first → E
Returns the next element that will be returned by removeFirst.
read-only, override
hashCode int
The hash code for this object.
read-only, inherited
isEmpty bool
Whether the queue is empty.
read-only, override
isNotEmpty bool
Whether the queue has any elements.
read-only, override
length int
Number of elements in the queue.
read-only, override
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
unorderedElements Iterable<E>
Provides efficient access to all the elements currently in the queue.
read-only, override


add(E element) → void
Adds element to the queue.
addAll(Iterable<E> elements) → void
Adds all elements to the queue.
clear() → void
Removes all the elements from this queue.
contains(E object) bool
Checks if object is in the queue.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
remove(E element) bool
Removes an element of the queue that compares equal to element.
removeAll() Iterable<E>
Removes all the elements from this queue and returns them.
removeFirst() → E
Removes and returns the element with the highest priority.
toList() List<E>
Returns a list of the elements of this queue in priority order.
toSet() Set<E>
Return a comparator based set using the comparator of this queue.
toString() String
Returns some representation of the queue.
toUnorderedList() List<E>
Returns a list of the elements of this queue in no specific order.


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