PairingHeap

cats.collections.PairingHeap
See thePairingHeap companion object
sealed abstract class PairingHeap[A]

A PairingHeap is a heap with excellent empirical performance.

See: https://en.wikipedia.org/wiki/Pairing_heap in particular: https://en.wikipedia.org/wiki/Pairing_heap#Summary_of_running_times

Additionally, it supports an efficient O(1) combine operation

Attributes

Companion:
object
Source:
PairingHeap.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

def combine(that: PairingHeap[A])(implicit order: Order[A]): PairingHeap[A]

Merge two heaps, this is O(1) work

Merge two heaps, this is O(1) work

Attributes

Source:
PairingHeap.scala
def exists(fn: A => Boolean): Boolean

Check to see if a predicate is ever true worst case O(N) but stops at the first true

Check to see if a predicate is ever true worst case O(N) but stops at the first true

Attributes

Source:
PairingHeap.scala
def forall(fn: A => Boolean): Boolean

Check to see if a predicate is always true worst case O(N) but stops at the first false

Check to see if a predicate is always true worst case O(N) but stops at the first false

Attributes

Source:
PairingHeap.scala

Verifies if the heap is empty. O(1)

Verifies if the heap is empty. O(1)

Attributes

Source:
PairingHeap.scala

Returns min value on the heap, if it exists

Returns min value on the heap, if it exists

O(1)

Attributes

Source:
PairingHeap.scala
def size: Long

Returns the size of the heap. O(1)

Returns the size of the heap. O(1)

Attributes

Source:
PairingHeap.scala

Concrete methods

def +(x: A)(implicit order: Order[A]): PairingHeap[A]

Alias for add

Alias for add

Attributes

Source:
PairingHeap.scala
def add(x: A)(implicit order: Order[A]): PairingHeap[A]

insert an item into the heap O(1)

insert an item into the heap O(1)

Attributes

Source:
PairingHeap.scala
def addAll(as: Iterable[A])(implicit order: Order[A]): PairingHeap[A]

Attributes

Source:
PairingHeap.scala
def contains(a: A)(implicit order: Order[A]): Boolean

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:
PairingHeap.scala
def foldLeft[B](init: B)(fn: (B, A) => B)(implicit order: Order[A]): B

do a foldLeft in the same order as toList. requires an Order[A], which prevents us from making a Foldable[PairingHeap] instance.

do a foldLeft in the same order as toList. requires an Order[A], which prevents us from making a Foldable[PairingHeap] 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:
PairingHeap.scala

Return true if this is not empty O(1)

Return true if this is not empty O(1)

Attributes

Source:
PairingHeap.scala
def pop(implicit order: Order[A]): Option[(A, PairingHeap[A])]

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:
PairingHeap.scala
def remove(implicit order: Order[A]): PairingHeap[A]

if not empty, remove the min, else return empty this is thought to be O(log N) (but not proven to be so)

if not empty, remove the min, else return empty this is thought to be O(log N) (but not proven to be so)

Attributes

Source:
PairingHeap.scala
def toList(implicit order: Order[A]): List[A]

Returns a sorted list of the elements within the heap. O(N log N)

Returns a sorted list of the elements within the heap. O(N log N)

Attributes

Source:
PairingHeap.scala
def unorderedFold(implicit m: CommutativeMonoid[A]): A

Similar to unorderedFoldMap without a transformation

Similar to unorderedFoldMap without a transformation

Attributes

Source:
PairingHeap.scala
def unorderedFoldMap[B](fn: A => B)(implicit m: CommutativeMonoid[B]): B

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:
PairingHeap.scala