Heap

sealed abstract
class Heap[A]

An efficient, asymptotically optimal, implementation of priority queues extended with support for efficient size.

The implementation of 'Heap' is based on bootstrapped skew binomial heaps as described by: G. Brodal and C. Okasaki , "Optimal Purely Functional Priority Queues", Journal of Functional Programming 6:839-857 (1996),

Based on the heaps Haskell library by Edward Kmett

Companion
object
class Object
trait Matchable
class Any

Value members

Abstract methods

def fold[B](empty: => B, nonempty: (Int, (A, A) => Boolean, Tree[Ranked[A]]) => B): B

Concrete methods

final
def +(a: A)(implicit o: Order[A]): Heap[A]

Alias for insert

Alias for insert

def adjustMin(f: A => A): Heap[A]
def break(p: A => Boolean): (Heap[A], Heap[A])

Returns a tuple where the first element is a heap consisting of the longest prefix of least elements in this heap that do not satisfy the given predicate, and the second element is the remainder of the elements. O(n log n)

Returns a tuple where the first element is a heap consisting of the longest prefix of least elements in this heap that do not satisfy the given predicate, and the second element is the remainder of the elements. O(n log n)

def deleteMin: Heap[A]

Delete the minimum key from the heap and return the resulting heap. O(log n)

Delete the minimum key from the heap and return the resulting heap. O(log n)

def drop(n: Int): Heap[A]

Return a heap consisting of all the members of this heap except for the least n. O(n log n)

Return a heap consisting of all the members of this heap except for the least n. O(n log n)

def dropWhile(p: A => Boolean): Heap[A]

Returns a heap consisting of the longest prefix of least elements of this heap that do not satisfy the predicate. O(n log n)

Returns a heap consisting of the longest prefix of least elements of this heap that do not satisfy the predicate. O(n log n)

def exists(f: A => Boolean): Boolean
def filter(p: A => Boolean): Heap[A]

Filter the heap, retaining only values that satisfy the predicate. O(n)

Filter the heap, retaining only values that satisfy the predicate. O(n)

def flatMap[B : Order](f: A => Heap[B]): Heap[B]

Construct heaps from each element in this heap and union them together into a new heap. O(n)

Construct heaps from each element in this heap and union them together into a new heap. O(n)

def foldRight[B](z: B)(f: (A, => B) => B): B
def forall(f: A => Boolean): Boolean
def foreach(f: A => Unit): Unit
def insert(a: A)(implicit o: Order[A]): Heap[A]

Insert a new value into the heap. O(1)

Insert a new value into the heap. O(1)

def insertAll(as: IterableOnce[A])(implicit o: Order[A]): Heap[A]
def insertAllF[F[_]](as: F[A])(implicit F: Foldable[F], o: Order[A]): Heap[A]
def isEmpty: Boolean

Is the heap empty? O(1)

Is the heap empty? O(1)

def map[B : Order](f: A => B): Heap[B]

Map a function over the heap, returning a new heap ordered appropriately. O(n)

Map a function over the heap, returning a new heap ordered appropriately. O(n)

def minimum: A

Get the minimum key on the (nonempty) heap. O(1)

Get the minimum key on the (nonempty) heap. O(1)

def minimumO: Option[A]

Get the minimum key on the (nonempty) heap. O(1)

Get the minimum key on the (nonempty) heap. O(1)

final
def nonEmpty: Boolean

Is the heap populated? O(1)

Is the heap populated? O(1)

def nub: Heap[A]

Remove duplicate entries from the heap. O(n log n)

Remove duplicate entries from the heap. O(n log n)

def partition(p: A => Boolean): (Heap[A], Heap[A])

Partition the heap according to a predicate. The first heap contains all elements that satisfy the predicate. The second contains all elements that fail the predicate. O(n)

Partition the heap according to a predicate. The first heap contains all elements that satisfy the predicate. The second contains all elements that fail the predicate. O(n)

def size: Int

The number of elements in the heap. O(1)

The number of elements in the heap. O(1)

def span(p: A => Boolean): (Heap[A], Heap[A])

Returns a tuple where the first element is a heap consisting of the longest prefix of least elements in this heap that satisfy the given predicate and the second element is the remainder of the elements. O(n log n)

Returns a tuple where the first element is a heap consisting of the longest prefix of least elements in this heap that satisfy the given predicate and the second element is the remainder of the elements. O(n log n)

def split(a: A): (Heap[A], Heap[A], Heap[A])

Partition the heap of the elements that are less than, equal to, and greater than a given value. O(n)

Partition the heap of the elements that are less than, equal to, and greater than a given value. O(n)

def splitAt(n: Int): (Heap[A], Heap[A])

Split into two heaps, the first containing the n least elements, the second containing the n greatest elements. O(n log n)

Split into two heaps, the first containing the n least elements, the second containing the n greatest elements. O(n log n)

def take(n: Int): Heap[A]

Return a heap consisting of the least n elements of this heap. O(n log n)

Return a heap consisting of the least n elements of this heap. O(n log n)

def takeWhile(p: A => Boolean): Heap[A]

Returns a heap consisting of the longest prefix of least elements of this heap that satisfy the predicate. O(n log n)

Returns a heap consisting of the longest prefix of least elements of this heap that satisfy the predicate. O(n log n)

def toIList: IList[A]
def toList: List[A]
def toStream: Stream[A]
override
def toString: String
Definition Classes
Any
def toUnsortedList: List[A]
def traverse[F[_] : Applicative, B : Order](f: A => F[B]): F[Heap[B]]

Traverse the elements of the heap in sorted order and produce a new heap with applicative effects. O(n log n)

Traverse the elements of the heap in sorted order and produce a new heap with applicative effects. O(n log n)

def uncons: Option[(A, Heap[A])]

Split the heap into the minimum element and the remainder. O(log n)

Split the heap into the minimum element and the remainder. O(log n)

def union(as: Heap[A]): Heap[A]

Meld the values from two heaps into one heap. O(1)

Meld the values from two heaps into one heap. O(1)