v0.4.0

PriorityQueue<T> structv0.1.0

Source
A max-priority queue over a binary heap.
pub struct PriorityQueue<T> {
    // private fields
}

Move-only: it owns its elements.

Type parameters

NameDescription
Tthe element type, which needs <

Constructors

PriorityQueue

pub func PriorityQueue(allocator: Allocator) -> PriorityQueue<T>

An empty queue that has not allocated anything.

NameTypeDescription
allocatorAllocatorwhere the storage comes from

Returns: the queue

Source

Methods

Length

pub func Length(&self) -> uint

How many elements it holds.

Returns: the count

Source

IsEmpty

pub func IsEmpty(&self) -> bool

Whether it holds nothing.

Returns: whether it is empty

Source

Push

pub func Push(&var self, value: T)

Adds value, moving it in. Logarithmic time, amortized over the vector's growth. Terminates the program when the storage cannot grow.

NameTypeDescription
valueTthe element

Source

Peek

pub func Peek(&self) -> &T?

The largest element, borrowed where it sits, without taking it out. self stays borrowed while the reference is in use, so the queue cannot change under it.

Returns: a reference to it, or none when the queue is empty

Source

Pop

pub func Pop(&var self) -> T?

Takes the largest element out. Logarithmic time.

Returns: the element, or none when the queue is empty

Source

Clear

pub func Clear(&var self)

Destroys every element, keeping the storage.

Source

AsSlice

pub func AsSlice(&self) -> T[..]

The elements in heap order: the largest first, the rest in no useful order.

Returns: a view of them, valid until the queue next changes

Source