TinyQueue<T> class

Port of https://github.com/mourner/tinyqueue. The smallest and simplest binary heap priority queue.

// create an empty priority queue
var queue = new TinyQueue();

// add some items
queue.push(7);
queue.push(5);
queue.push(10);

// remove the top item
var top = queue.pop(); // returns 5

// return the top item (without removal)
top = queue.peek(); // returns 7

// get queue length
queue.length; // returns 2

// create a priority queue from an existing array (modifies the array)
queue = new TinyQueue([7, 5, 10]);

// pass a custom item comparator as a second argument
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
	return a.value - b.value;
});

// turn a queue into a sorted array
var array = [];
while (queue.length) array.push(queue.pop());

Constructors

TinyQueue([Iterable<T>? data, Comparator<T>? compare])
Constructs a new queue.

Properties

compare Comparator<T>
final
data List<T>
final
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
no setter
isNotEmpty bool
no setter
length int
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
peek() → T
Returns the smallest queue element without removing it.
pop() → T
Removes the smallest element from the queue and returns it.
push(T item) → dynamic
Adds an element to this queue.
toString() String
A string representation of this object.
inherited

Operators

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