PriorityQueue API Reference

Min-heap priority queue (smaller values have higher priority)

Import

U std/priority_queue

Struct

S PriorityQueue { data: i64, size: i64, capacity: i64 }

Methods

MethodSignatureDescription
with_capacityF with_capacity(capacity: i64) -> PriorityQueueCreate with capacity
lenF len(&self) -> i64Number of elements
capacityF capacity(&self) -> i64Allocated capacity
is_emptyF is_empty(&self) -> i64Check if empty
pushF push(&self, value: i64) -> i64Insert element
popF pop(&self) -> i64Remove and return minimum (returns 0 if empty)
pop_optF pop_opt(&self) -> OptionRemove and return minimum using Option
peekF peek(&self) -> i64View minimum without removing (returns 0 if empty)
peek_optF peek_opt(&self) -> OptionView minimum using Option
clearF clear(&self) -> i64Remove all elements
dropF drop(&self) -> i64Free memory

Free Functions

FunctionSignatureDescription
pq_newF pq_new() -> PriorityQueueCreate new PriorityQueue with default capacity (8)
pq_pushF pq_push(pq: PriorityQueue, value: i64) -> i64Push element into priority queue
pq_popF pq_pop(pq: PriorityQueue) -> i64Pop minimum element
pq_peekF pq_peek(pq: PriorityQueue) -> i64Peek at minimum element
pq_sizeF pq_size(pq: PriorityQueue) -> i64Get size
pq_is_emptyF pq_is_empty(pq: PriorityQueue) -> i64Check if empty
pq_clearF pq_clear(pq: PriorityQueue) -> i64Clear all elements
pq_freeF pq_free(pq: PriorityQueue) -> i64Free memory

Usage

U std/priority_queue

F main() -> i64 {
    # Using methods
    pq := PriorityQueue.with_capacity(16)
    pq.push(30)
    pq.push(10)
    pq.push(20)
    min := pq.pop()  # 10

    # Using Option methods
    opt_min := pq.peek_opt()  # Some(20)

    # Using free functions
    pq2 := pq_new()
    pq_push(pq2, 5)
    pq_push(pq2, 15)
    val := pq_pop(pq2)  # 5

    pq.drop()
    pq_free(pq2)
    0
}