Addressable Binary Heaps - v1.0.1
    Preparing search index...

    Class AbstractHeap<N>Abstract

    An abstract base class for implementing heap data structures.

    Provides a common interface for both min-heap and max-heap implementations.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get size(): number

      Returns the current number of elements in the heap.

      Returns number

      The number of elements in the heap.

    Methods

    • Makes the AbstractHeap iterable.

      Note: The traversal follows the order of the underlying array, not the priority order.

      Parameters

      • reversed: boolean

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

      Returns Generator<N, void, void>

      An iterator yielding heap elements in the specified order.

    • Adds a new node to the heap while maintaining the heap property.

      Parameters

      • node: N

        The node to add to the heap.

      Returns void

    • Decreases the key value of a heap element by a specified amount.

      Parameters

      • node: N

        The element to modify.

      • decreaseValue: N["key"]

        Amount to decrease the key by.

      Returns boolean

      true if element was found and modified, false otherwise.

    • Returns an iterator for traversing all elements in the heap.

      Note: The traversal follows the order of the underlying array, not the priority order.

      Parameters

      • Optionalreversed: boolean

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

      Returns Generator<N, void, void>

      An iterator yielding heap elements in the specified order.

    • Executes a callback function for each element in the heap.

      Note: The traversal follows the order of the underlying array, not the priority order.

      Parameters

      • callback: (node: N, index: number, heapInstance: AbstractHeap<N>) => void
          • (node: N, index: number, heapInstance: AbstractHeap<N>): void
          • Parameters

            • node: N

              Element of each iteration.

            • index: number

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

            • heapInstance: AbstractHeap<N>

              The heap instance being iterated.

            Returns void

      • OptionalthisArg: any

        A value to use as this when executing callback.

      Returns void

    • Increases the key value of a heap element by a specified amount.

      Parameters

      • node: N

        The element to modify.

      • increaseValue: N["key"]

        Amount to increase the key by.

      Returns boolean

      true if element was found and modified, false otherwise.

    • Returns an iterator for traversing just the key values in the heap.

      Note: The traversal follows the order of the underlying array, not the priority order.

      Parameters

      • reversed: boolean

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

      Returns Generator<N["key"], void, void>

    • Returns the top element of the heap without removing it.

      • For min-heaps, returns the minimum element.
      • For max-heaps, returns the maximum element.

      Returns undefined | N

      The top element or undefined if heap is empty.

    • Removes and returns the top element of the heap.

      • For min-heaps, removes the minimum element.
      • For max-heaps, removes the maximum element.

      Returns undefined | N

      The removed top element or undefined if heap is empty.

    • Removes a specific element from anywhere in the heap.

      Parameters

      • node: N

        The element to remove.

      Returns boolean

      true if element was found and removed, false if not found.