rhofour/elm-pairing-heap/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

PairingHeap

This is a simple pairing heap implementation written in Elm usable as a priority queue. This code is based heavily on the pseudocode available at the Wikipedia page.

Type and Constructor

type PairingHeap comparable a

A PairingHeap has comparable keys and values of an arbitrary type.

empty : PairingHeap comparable a

Create an empty PairingHeap.

Operations

( comparable, a )
-> PairingHeap comparable a
-> PairingHeap comparable a

Inserts a new element into a PairingHeap.

Complexity: O(1)

PairingHeap comparable a
-> PairingHeap comparable a
-> PairingHeap comparable a

Merges two PairingHeaps together into one new heap containing all of the key-value pairs from both inputs.

Complexity: O(1)

findMin : PairingHeap comparable a -> Maybe ( comparable, a )

Find the minimum value in a heap returning Nothing if the heap is empty.

Complexity: O(1)

findMin (fromList [(10, ()), (3, ()), (8, ())]) == Just 3
deleteMin : PairingHeap comparable a -> PairingHeap comparable a

Removes the minimum element from a PairingHeap returning a new heap without that element. This will return an empty heap if given an empty heap as input.

Complexity: O(log n)

Convenience functions

fromList : List ( comparable, a ) -> PairingHeap comparable a

This function turns a list of key-value pairs into a PairingHeap.

Complexity: O(n)

toSortedList : PairingHeap comparable a -> List ( comparable, a )

This function turns a PairingHeap into a sorted list of key-value pairs.

Complexity: O(n log n)