Class MinHeap<T>

Type Parameters

  • T = number

Hierarchy

Constructors

  • The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem objects.

    Type Parameters

    • T = number

    Parameters

    • Optional options: HeapOptions<T>

      The options parameter is an optional object that can be passed to the constructor. It is of type HeapOptions<T>, which is a generic type that represents the options for the heap.

    Returns MinHeap<T>

Properties

_pq: PriorityQueue<HeapItem<T>>
_priorityExtractor: ((val) => number)

Type declaration

    • (val): number
    • Parameters

      • val: T

      Returns number

Accessors

  • get pq(): PriorityQueue<HeapItem<T>>
  • Returns PriorityQueue<HeapItem<T>>

  • get priorityExtractor(): ((val) => number)
  • Returns ((val) => number)

      • (val): number
      • Parameters

        • val: T

        Returns number

  • get size(): number
  • The function returns the size of a priority queue.

    Returns number

    The size of the priority queue.

Methods

  • The add function adds an val to a priority queue with an optional priority value.

    Parameters

    • Optional priority: number

      The priority parameter is an optional number that represents the priority of the val being added to the heap. If the val parameter is a number, then the priority parameter is set to the value of val. If the val parameter is not a number, then the

    • Optional val: T

      The val parameter represents the value that you want to add to the heap. It can be of any type.

    Returns Heap<T>

    The add method returns the instance of the Heap class.

    Throws

    if priority is not a valid number

  • The clear function clears the priority queue.

    Returns void

  • The function checks if a given node or value exists in the priority queue.

    Parameters

    • node: T | HeapItem<T>

      The parameter node can be of type T or HeapItem<T>.

    Returns boolean

    a boolean value.

  • The function checks if a priority queue is empty.

    Returns boolean

    A boolean value indicating whether the size of the priority queue is less than 1.

  • Parameters

    • Optional isItem: undefined

    Returns undefined | T

  • Parameters

    • isItem: false

    Returns undefined | T

  • Parameters

    • isItem: true

    Returns null | HeapItem<T>

  • Parameters

    • Optional isItem: undefined

    Returns undefined | T

  • Parameters

    • isItem: false

    Returns undefined | T

  • Parameters

    • isItem: true

    Returns null | HeapItem<T>

  • Parameters

    • Optional isItem: undefined

    Returns undefined | T

  • Parameters

    • isItem: false

    Returns undefined | T

  • Parameters

    • isItem: true

    Returns null | HeapItem<T>

  • Parameters

    • Optional isItem: undefined

    Returns (undefined | T)[]

  • Parameters

    • isItem: false

    Returns (undefined | T)[]

  • Parameters

    • isItem: true

    Returns (null | HeapItem<T>)[]

  • Parameters

    • Optional isItem: undefined

    Returns (undefined | T)[]

  • Parameters

    • isItem: false

    Returns (undefined | T)[]

  • Parameters

    • isItem: true

    Returns (null | HeapItem<T>)[]

Generated using TypeDoc