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

The Queue(a) type represents a priority queue of elements of type a.

pub type Queue(a) =
  pairing_heap.Heap(a)

Values

pub fn count(queue: pairing_heap.Heap(a)) -> Int

Returns the number of elements in the priority queue.

pub fn from_list(
  list: List(a),
  compare: fn(a, a) -> order.Order,
) -> pairing_heap.Heap(a)

Creates a new priority queue from a list of elements and a comparison function.

pub fn is_empty(queue: pairing_heap.Heap(a)) -> Bool

Checks whether the priority queue is empty or not.

pub fn new(
  compare: fn(a, a) -> order.Order,
) -> pairing_heap.Heap(a)

Creates a new empty priority queue with the provided comparison function.

pub fn peek(from queue: pairing_heap.Heap(a)) -> Result(a, Nil)

Returns the minimum element in the priority queue without removing it.

pub fn pop(
  from queue: pairing_heap.Heap(a),
) -> Result(#(a, pairing_heap.Heap(a)), Nil)

Removes and returns the minimum element from the priority queue, along with the new queue.

pub fn push(
  onto queue: pairing_heap.Heap(a),
  this item: a,
) -> pairing_heap.Heap(a)

Inserts a new element into the priority queue.

pub fn reorder(
  queue: pairing_heap.Heap(a),
  compare: fn(a, a) -> order.Order,
) -> pairing_heap.Heap(a)

Rebuilds the priority queue with a new comparison function.

pub fn to_list(queue: pairing_heap.Heap(a)) -> List(a)

Converts the priority queue to a list, preserving the order of elements.

Search Document