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) -> uint
How many elements it holds.
Returns: the count
IsEmpty
pub func IsEmpty(&self) -> bool
Whether it holds nothing.
Returns: whether it is empty
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.
| Name | Type | Description |
|---|---|---|
value | T | the element |
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
Pop
pub func Pop(&var self) -> T?
Takes the largest element out. Logarithmic time.
Returns: the element, or none when the queue is empty
Clear
pub func Clear(&var self)
Destroys every element, keeping the storage.
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