Heap
is a Purely Functional Binary Heap. Binary Heaps are not common in the functional space, especially because their implementation depends on mutable arrays in order to gain in performance. This functional binary heap is based on Vladimir Kostyukov's paper and it does support the basic operations on a heap without compromising performance.
It is important to note that we can, in fact, to create the Binary Heap in order O(n) from a List
using the function heapify
.
Attributes
- Companion
- object
- Source
- Heap.scala
- Graph
-
- Supertypes
Members list
Value members
Abstract methods
Returns the height of the heap.
Verifies if the heap is empty.
Returns min value on the heap, if it exists
Returns the size of the heap.
Concrete methods
Alias for add
Alias for addAll
Alias for remove
Insert a new element into the heap. Order O(log n)
Attributes
- Source
- Heap.scala
This is O(N) in the worst case, but we use the heap property to be lazy
This is O(N) in the worst case, but we use the heap property to be lazy
Attributes
- Source
- Heap.scala
Check to see if a predicate is ever true
do a foldLeft in the same order as toList. requires an Order[A], which prevents us from making a Foldable[Heap] instance.
do a foldLeft in the same order as toList. requires an Order[A], which prevents us from making a Foldable[Heap] instance.
prefer unorderedFoldMap if you can express your operation as a commutative monoid since it is O(N) vs O(N log N) for this method
Attributes
- Source
- Heap.scala
Check to see if a predicate is always true
Returns min value on the heap, if it exists
Return true if this is not empty
Remove the min element from the heap (the root) and return it along with the updated heap. Order O(log n)
Remove the min element from the heap (the root) and return it along with the updated heap. Order O(log n)
Attributes
- Source
- Heap.scala
Remove the min element from the heap (the root). Order O(log n)
Returns a sorted list of the elements within the heap.
convert to a PairingHeap which can do fast merges, this is an O(N) operation
convert to a PairingHeap which can do fast merges, this is an O(N) operation
Attributes
- Source
- Heap.scala
Similar to unorderedFoldMap without a transformation
Aggregate with a commutative monoid, since the Heap is not totally ordered
Aggregate with a commutative monoid, since the Heap is not totally ordered
Attributes
- Source
- Heap.scala
Deprecated methods
Avoid this, it should really have been on the companion because this totally ignores this
.
Avoid this, it should really have been on the companion because this totally ignores this
.
Attributes
- Deprecated
- true
- Source
- Heap.scala