Leftist Heap
A LeftistHeap is a persistent (immutable) priority queue. The first operation is O(1), and with and withoutFirst are O(log(n)). The latter two also produce a new LeftistHeap without modifying the original.
A LeftistHeap is either a leftistLeaf having no elements, or a LeftistInternal containing the heap's minimum (the values of the heap must be Comparable), a left subtree, and a right subtree. The rank of a heap is the length of the shortest path to a leaf. The rank of a heap's right subtree is always less than or equal to the rank of the heap's left subtree. Therefore, the shortest path to a leaf can always be found along the right spine. In fact, the rank can be defined as zero for a leaf, or the right subtree's rank + 1.
Author
Mark van Gulik
Parameters
The rank of the heap, which is the number of values along the right spine.
The number of values in the heap.
Functions
Merge this heap with another.
A heap with one more element.
Create a heap with a specific element removed. This is particularly efficient (O(log(N))) when the element is the minimal element, although withoutFirst is the preferred form.