Skip to content

std.pqueue

arena binary heap; O(log n) push/pop; order = any type with less()

pub Min :: struct($T: type) {
marker: u8,
}

smallest first

pub less :: fn(self: *Self, a: T, b: T) -> bool
pub Max :: struct($T: type) {
marker: u8,
}

largest first

pub less :: fn(self: *Self, a: T, b: T) -> bool
pub By :: struct($T: type) {
f: fn(T, T) -> bool,
}

first by f(a, b): true if a comes before b

pub less :: fn(self: *Self, a: T, b: T) -> bool
pub PriorityQueue :: struct($T: type, $C: type) {
region: *Arena,
data: []T,
count: usize,
order: C,
}
  • region: where it grows (borrowed)
  • data: heap, data[0] first; cap == data.len
pub len :: fn(self: *Self) -> usize
pub is_empty :: fn(self: *Self) -> bool
pub peek :: fn(self: *Self) -> ?T

next pop result, left in place; null if empty

pub push :: fn(self: *Self, item: T)
pub push_all :: fn(self: *Self, items: []const T)

push each of items

pub pop :: fn(self: *Self) -> ?T

take the first; null if empty

pub items :: fn(self: *Self) -> []T

unordered; valid until the next push

pub clear :: fn(self: *Self)
pub with :: fn($T: type, $C: type, a: *Arena, order: C) -> PriorityQueue(T, C)

queue in a; order decides what comes first

pub min :: fn($T: type, a: *Arena) -> PriorityQueue(T, Min(T))

smallest first

pub max :: fn($T: type, a: *Arena) -> PriorityQueue(T, Max(T))

largest first

pub by :: fn($T: type, a: *Arena, less: fn(T, T) -> bool) -> PriorityQueue(T, By(T))

first by less(a, b): true if a comes before b