LeftistHeap

sealed class LeftistHeap<Value : Comparable<Value>>

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

Functions

Link copied to clipboard
abstract fun merge(another: LeftistHeap<Value>): LeftistHeap<Value>
Link copied to clipboard
fun toList(): List<Value>
Link copied to clipboard
abstract fun with(newValue: Value): LeftistInternal<Value>
Link copied to clipboard
abstract fun without(value: Value): LeftistHeap<Value>

Properties

Link copied to clipboard
abstract val first: Value
Link copied to clipboard
val isEmpty: Boolean
Link copied to clipboard
val rank: Int
Link copied to clipboard
val size: Int
Link copied to clipboard
abstract val withoutFirst: LeftistHeap<Value>

Inheritors

Link copied to clipboard