Class MaxHeap<V>

Type Parameters

  • V = any

Hierarchy

Constructors

  • The constructor initializes a PriorityQueue with a custom comparator function.

    Type Parameters

    • V = any

    Parameters

    • Optional options: HeapOptions<V>

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

    Returns MaxHeap<V>

Properties

_priorityExtractor: ((val) => number)

Type declaration

    • (val): number
    • Parameters

      • val: V

      Returns number

Accessors

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

      • (val): number
      • Parameters

        • val: V

        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: V

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

    Returns Heap<V>

    The add method returns the instance of the Heap class.

    Throws

    if priority is not a valid number

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

    Parameters

    • node: V | HeapItem<V>

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

    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.

  • The peek function returns the top item in the priority queue without removing it.

    Parameters

    • Optional isItem: undefined

    Returns undefined | V

    The peek() method is returning either a HeapItem<V> object or null.Returns an val with the highest priority in the queue

  • The peek function returns the top item in the priority queue without removing it.

    Parameters

    • isItem: false

    Returns undefined | V

    The peek() method is returning either a HeapItem<V> object or null.Returns an val with the highest priority in the queue

  • The peek function returns the top item in the priority queue without removing it.

    Parameters

    • isItem: true

    Returns null | HeapItem<V>

    The peek() method is returning either a HeapItem<V> object or null.Returns an val with the highest priority in the queue

  • The peekLast function returns the last item in the heap.

    Parameters

    • Optional isItem: undefined

    Returns undefined | V

    The method peekLast() returns either a HeapItem<V> object or null.Returns an val with the lowest priority in the queue

  • The peekLast function returns the last item in the heap.

    Parameters

    • isItem: false

    Returns undefined | V

    The method peekLast() returns either a HeapItem<V> object or null.Returns an val with the lowest priority in the queue

  • The peekLast function returns the last item in the heap.

    Parameters

    • isItem: true

    Returns null | HeapItem<V>

    The method peekLast() returns either a HeapItem<V> object or null.Returns an val with the lowest priority in the queue

  • The poll function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

    Parameters

    • Optional isItem: undefined

    Returns undefined | V

    either a HeapItem object or null.

  • The poll function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

    Parameters

    • isItem: false

    Returns undefined | V

    either a HeapItem object or null.

  • The poll function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue

    Parameters

    • isItem: true

    Returns null | HeapItem<V>

    either a HeapItem object or null.

  • The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

    Parameters

    • Optional isItem: undefined

      The isItem parameter is a boolean flag that indicates whether the sorted result should be an array of HeapItem<V> objects or an array of the values (V) of those objects. If isItem is true, the sorted result will be an array of HeapItem @returns an array of either HeapItem, null, V, or undefined` values.

    Returns (undefined | V)[]

  • The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

    Parameters

    • isItem: false

      The isItem parameter is a boolean flag that indicates whether the sorted result should be an array of HeapItem<V> objects or an array of the values (V) of those objects. If isItem is true, the sorted result will be an array of HeapItem @returns an array of either HeapItem, null, V, or undefined` values.

    Returns (undefined | V)[]

  • The function sorts the elements in the priority queue and returns either the sorted items or their values depending on the value of the isItem parameter.

    Parameters

    • isItem: true

      The isItem parameter is a boolean flag that indicates whether the sorted result should be an array of HeapItem<V> objects or an array of the values (V) of those objects. If isItem is true, the sorted result will be an array of HeapItem @returns an array of either HeapItem, null, V, or undefined` values.

    Returns (null | HeapItem<V>)[]

  • The toArray function returns an array of HeapItem<V> objects.

    Parameters

    • Optional isItem: undefined

    Returns (undefined | V)[]

    An array of HeapItem objects.Returns a sorted list of vals

  • The toArray function returns an array of HeapItem<V> objects.

    Parameters

    • isItem: false

    Returns (undefined | V)[]

    An array of HeapItem objects.Returns a sorted list of vals

  • The toArray function returns an array of HeapItem<V> objects.

    Parameters

    • isItem: true

    Returns (null | HeapItem<V>)[]

    An array of HeapItem objects.Returns a sorted list of vals

Generated using TypeDoc