TOC Toolkit API - v0.1.0
    Preparing search index...

    Class BinaryHeap<T>

    A priority queue. pop returns the smallest item by the comparator, which returns a negative number when its first argument comes first, as the comparator of Array.sort does. Two items that compare as equal come out in no fixed order, so a caller that needs one puts a sequence number into its items.

    push and pop take time logarithmic in the number of items, and peek takes constant time. A heap with a budget charges one Resource.Cells for each item of its largest size so far, so an item that takes the place of a popped one is free.

    Type Parameters

    • T extends NonNullable<unknown>
    Index
    • Type Parameters

      • T extends {}

      Parameters

      • compare: (first: T, second: T) => number
      • Optionalbudget: Budget

      Returns BinaryHeap<T>

    • get size(): number

      The number of items.

      Returns number

    • Returns the smallest item without removing it, or undefined when the heap is empty.

      Returns Maybe<T>

    • Adds an item.

      Parameters

      • item: T

      Returns void

    • Removes and returns the smallest item, or returns undefined when the heap is empty.

      Returns Maybe<T>