HAN-ASD-DT / priority-queue / PriorityQueue

A priority queue for Elm.

A priority queue is an

abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority.

The implementation we provide here is based on Okasaki's leftist heaps. See Purely Functional Data Structures for more information.

Priority

Throughout this package priority will mean a function that assigns a integer value to an element. Lower values indicate higher priority and vice versa.

Types


type alias PriorityQueue a =
Kernel.PriorityQueue a

The abstract datatype of this package.


type alias Priority a =
Kernel.Priority a

A function that assigns a priority to elements.

Lower values correspond to higher priority.

Building

empty : Priority a -> PriorityQueue a

Create an empty PriorityQueue.

insert : a -> PriorityQueue a -> PriorityQueue a

Insert an element into the PriorityQueue

fromList : Priority a -> List a -> PriorityQueue a

Creates a PriorityQueue from a given list of elements.

Must be given a priority function, i.e. a function that assigns the priority to elements.

Query

head : PriorityQueue a -> Maybe a

Return the element of the PriorityQueue with the highest priority.

Returns Nothing when the queue is empty.

tail : PriorityQueue a -> PriorityQueue a

Return the PriorityQueue that remains when the head is removed.

take : Basics.Int -> PriorityQueue a -> List a

Return the first n elements of the PriorityQueue with the highest priority

drop : Basics.Int -> PriorityQueue a -> PriorityQueue a

Returns a new PriorityQueue with the first n elements dropped.

isEmpty : PriorityQueue a -> Basics.Bool

Determine if the PriorityQueue is empty.

Conversion

toList : PriorityQueue a -> List a

Returns all the elements in a PriorityQueue as a List.

The order will be determined by the priority, higher priority elements before lower priority elements.