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: &PriorityQueue<T>) -> uint

How many elements it holds.

Returns: the count

Source

IsEmpty

pub func IsEmpty(self: &PriorityQueue<T>) -> bool

Whether it holds nothing.

Returns: whether it is empty

Source

Push

pub func Push(
    self: &var PriorityQueue<T>,
    value: T
) -> ! CollectionError

Adds value, moving it in. Logarithmic time, amortized over the vector's growth.

NameTypeDescription
valueTthe element

Returns: nothing, or why there was no room; the queue is unchanged on failure

Source

Peek

pub func Peek(self: &PriorityQueue<T>) -> (*T)?

The largest element, without taking it out.

Returns: a pointer to it, valid until the queue next changes, or none when the queue is empty

Source

Pop

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

Takes the largest element out. Logarithmic time.

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

Source

Clear

pub func Clear(self: &var PriorityQueue<T>)

Destroys every element, keeping the storage.

Source

AsSlice

pub func AsSlice(self: &PriorityQueue<T>) -> 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