A concrete implementation of a min-heap.

Type Parameters

Hierarchy (View Summary)

Constructors

Accessors

  • get size(): number

    Getter method that returns heap size.

    Returns number

Methods

  • Returns an iterator for traversing the heap.

    Parameters

    • Optionalreversed: boolean = false

      If true, the iterator will traverse the heap in reverse order.

    Returns Generator<N, void, unknown>

    A generator that yields heap elements in the requested order.

  • Decreases the key value of a heap element.

    Parameters

    • node: N

      The element whose key value will be decreased.

    • decreaseValue: number

      The value of decrease.

    Returns boolean

    true or false depending on the outcome of the decrease process.

  • Returns an iterator for traversing the heap elements.

    Parameters

    • Optionalreversed: boolean = false

      If true, the iterator will traverse the heap in reverse order.

    Returns Generator<N, void, unknown>

  • Executes a provided function once per element in the heap.

    Parameters

    • callbackFn: (node: N, index: number, heapInstance: MinHeap<N>) => void
        • (node: N, index: number, heapInstance: MinHeap<N>): void
        • Parameters

          • node: N

            Element of each iteration.

          • index: number

            The index of the current element being processed in the heap.

          • heapInstance: MinHeap<N>

            The heap instance being iterated.

          Returns void

    • OptionalthisArg: any

      A value to use as this when executing callbackFn.

    Returns void

  • Increases the key value of a heap element.

    Parameters

    • node: N

      The element whose key value will be increased.

    • increaseValue: number

      The value of increase.

    Returns boolean

    true or false depending on the outcome of the increase process.

  • Returns an iterator for traversing the heap element keys.

    Parameters

    • Optionalreversed: boolean = false

      If true, the iterator will traverse the heap in reverse order.

    Returns Generator<number, void, unknown>

  • Removes an element from the heap.

    Parameters

    • node: N

      The element to remove.

    Returns boolean

    true or false depending on the outcome of the removal process.