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