Module collections/priority_queue
collections/priority_queue
Binary min-heap priority queue.
Example
{ PriorityQueue } :: import "std/collections/priority_queue";
pq := PriorityQueue(i32).new();
pq.push(5);
pq.push(1);
pq.push(3);
x := pq.pop().unwrap(); // 1
Types
PriorityQueue
type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo5d2e5ef9_id_17) : Type)
Min-heap backed by an ArrayList. Elements are ordered ascending (smallest first). Negate keys for max-heap behavior.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
impl(forall(T : Type), PriorityQueue(T), ...)
new : (fn() -> Self)Returns: Self
len : (fn(self: Self) -> usize)Returns: usize
is_empty : (fn(self: Self) -> bool)Returns: bool
peek : (fn(self: Self) -> Option(T))Returns: Option(T)
push : (fn(self: Self, val: T, where(T <: Ord(T))) -> unit)Returns: unit
pop : (fn(self: Self, where(T <: Ord(T))) -> Option(T))Returns: Option(T)
impl(forall(T : Type), PriorityQueue(T), ...)
into_iter : (fn(self : Self) -> PriorityQueueIter(T))Returns: PriorityQueueIter(T)
impl(forall(T : Type), PriorityQueue(T), ...)
iter : (fn(self : *(Self)) -> PriorityQueueIterPtr(T))Returns: PriorityQueueIterPtr(T)
PriorityQueueIter
type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo5d2e5ef9_id_99) : Type)
Value iterator for PriorityQueue - yields elements in heap (arbitrary) order Note: This iterates in internal storage order, NOT sorted order.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), PriorityQueueIter(T), Iterator(...))
Item : Tnext : (fn(self : *(Self)) -> Option(T))Returns: Option(T)
PriorityQueueIterPtr
type-function
fn(comptime(T) : Type) -> (comptime(fn_return_yo5d2e5ef9_id_222) : Type)
Pointer iterator for PriorityQueue - yields pointers to elements in heap order
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), PriorityQueueIterPtr(T), Iterator(...))
Item : *(T)next : (fn(self : *(Self)) -> Option(*(T)))Returns: Option(*(T))