PriorityQueue<T> structv0.1.0
pub struct PriorityQueue<T> {
// private fields
}
Move-only: it owns its elements.
Type parameters
| Name | Description |
|---|---|
T | the element type, which needs < |
Constructors
PriorityQueue
pub func PriorityQueue(allocator: Allocator) -> PriorityQueue<T>
An empty queue that has not allocated anything.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
Returns: the queue
Methods
Length
pub func Length(self: &PriorityQueue<T>) -> uint
How many elements it holds.
Returns: the count
IsEmpty
pub func IsEmpty(self: &PriorityQueue<T>) -> bool
Whether it holds nothing.
Returns: whether it is empty
Push
pub func Push(
self: &var PriorityQueue<T>,
value: T
) -> ! CollectionError
Adds value, moving it in. Logarithmic time, amortized over the vector's growth.
| Name | Type | Description |
|---|---|---|
value | T | the element |
Returns: nothing, or why there was no room; the queue is unchanged on failure
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
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
Clear
pub func Clear(self: &var PriorityQueue<T>)
Destroys every element, keeping the storage.
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