gleamy/priority_queue
This module provides an implementation of a priority queue data structure based on the pairing heap. It allows efficient insertion, removal, and access to the minimum element in the queue.
Types
Functions
pub fn from_list(
list: List(a),
compare: fn(a, a) -> Order,
) -> Heap(a)
Creates a new priority queue from a list of elements and a comparison function.
pub fn is_empty(queue: Heap(a)) -> Bool
Checks whether the priority queue is empty or not.
pub fn new(compare: fn(a, a) -> Order) -> Heap(a)
Creates a new empty priority queue with the provided comparison function.
pub fn peek(from queue: Heap(a)) -> Result(a, Nil)
Returns the minimum element in the priority queue without removing it.
pub fn pop(from queue: Heap(a)) -> Result(#(a, Heap(a)), Nil)
Removes and returns the minimum element from the priority queue, along with the new queue.
pub fn push(onto queue: Heap(a), this item: a) -> Heap(a)
Inserts a new element into the priority queue.
pub fn reorder(
queue: Heap(a),
compare: fn(a, a) -> Order,
) -> Heap(a)
Rebuilds the priority queue with a new comparison function.