Options
All
  • Public
  • Public/Protected
  • All
Menu

Priority Queue implementation based on a binary heap. It has two methods enqueue and dequeue to manage its elements. It implements the CappedStructure interface to handle overflow of a capacity is set.

Type parameters

  • T

Hierarchy

  • PriorityQueue

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new PriorityQueue(capacity?: undefined | number): PriorityQueue
  • Constructor takes an optional capacity parameter. If set, the PriorityQueue won't accept new elements when the lengths reaches the capacity, until it is dequeued.

    Parameters

    • Optional capacity: undefined | number

      The maximum queue length before overflow.

    Returns PriorityQueue

Properties

capacity

capacity: number = -1

The maximum elements the structure can contain. It can be set via the constructor or setCapacity. Default value is -1 (no limit).

values

Accessors

length

  • get length(): number
  • The current amount of elements.

    Returns number

Methods

dequeue

  • Removes the element with highest priority

    Returns PriorityQueueNode<T> | undefined

    The removes element or undefined if it failed.

enqueue

  • Adds a value to the queue. Its position depends on the given priority. If the length already reached the (optional) capacity, enqueue won't perform and return undefined.

    Parameters

    • value: T

      The value associed to the element.

    • priority: number

    Returns PriorityQueueNode<T> | undefined

    The inserted element or undefined if it failed.

Generated using TypeDoc