Class MaxHeap<T>

Type Parameters

  • T = number

Hierarchy

Constructors

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

    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 MaxHeap<T>

Properties

_priorityCb: ((val) => number)

Type declaration

    • (val): number
    • Parameters

      • val: T

      Returns number

Accessors

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

      • (val): number
      • Parameters

        • val: T

        Returns number

  • set priorityCb(v): void
  • Parameters

    • v: ((val) => number)
        • (val): number
        • Parameters

          • val: T

          Returns number

    Returns void

  • 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

    • val: T

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

    • 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

    Returns Heap<T>

    The add method returns the instance of the Heap class.

    Throws

    if priority is not a valid number

  • Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.

    Returns PriorityQueue<HeapItem<T>>

  • Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.

    Returns ((val) => number)

      • (val): number
      • Parameters

        • val: T

        Returns number

  • Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.

    Returns number

  • 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.

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

    Returns null | HeapItem<T>

    The peek() method is returning either a HeapItem<T> object or null.Returns an val with the highest 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

    Returns null | HeapItem<T>

    either a HeapItem object or null.

Generated using TypeDoc