Class MinHeap<T>

Type Parameters

  • T

Hierarchy

Constructors

Properties

Accessors

Methods

Constructors

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

    Type Parameters

    • T

    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>>
_priorityCb: ((element) => number)

Type declaration

    • (element): number
    • Parameters

      • element: T

      Returns number

Accessors

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

    Returns number

    The size of the priority queue.

Methods

  • 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 offer function adds an element to a priority queue with an optional priority value.

    Parameters

    • element: T

      The element 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 element being offered to the heap. If the element parameter is a number, then the priority parameter is set to the value of element. If the element parameter is not a number, then the

    Returns Heap<T>

    The offer method returns the instance of the Heap class.

    Throws

    if priority is not a valid number

  • 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 element with the highest priority in the queue

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

    Returns null | HeapItem<T>

    The method peekLast() returns either a HeapItem<T> object or null.Returns an element 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 element with the highest priority in the queue

    Returns null | HeapItem<T>

    either a HeapItem object or null.

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

    Returns HeapItem<T>[]

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

Generated using TypeDoc