Options
All
  • Public
  • Public/Protected
  • All
Menu

A queue that pops element based on their given priority.

import { PriorityQueue } from "scl"

The queue will return elements with a lower priority first. If you want the reverse, simply invert the function that is used to compare two elements.

The following table summarises the time complexity of the most commonly used properties.

Property name Worst-case
add() O(log(n))
deleteAt() O(log(n))
peek() O(1)
pop() O(log(n))
size O(1)

Examples

see

Queue

see

Stack

Type parameters

  • T

Hierarchy

  • PriorityQueue

Implements

Index

Constructors

constructor

  • new PriorityQueue<T>(opts?: Iterable<T> | BinaryMinHeap<T> | HeapOptions<T>): PriorityQueue<T>
  • Construct a new prioriry queue.

    const q = new PriorityQueue<number>({
      capacity: 1024,
      compare: (a, b) => a < b,
      elements: [1, 2, 3]
    })
    

    Type parameters

    • T

    Parameters

    • opts: Iterable<T> | BinaryMinHeap<T> | HeapOptions<T> = ...

    Returns PriorityQueue<T>

Accessors

size

  • get size(): number
  • Count the amount of elements in the collection.

    ⚠️ In most cases, this should be an O(1) operation. However, there are cases where this can be an O(n) operation. Therefore, it is recommended to always cache the result in a local variable.

    Returns number

Methods

[Symbol.iterator]

  • [Symbol.iterator](): Generator<T, void, unknown>
  • Returns an object which is able to sift through the values in this collection.

    The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.

    Returns Generator<T, void, unknown>

add

  • add(element: T): [boolean, Cursor<T>]

clear

  • clear(): void
  • Remove all elements from this collection, effectively setting the collection to the empty collection.

    Returns void

clone

delete

  • delete(element: T): boolean

deleteAll

  • deleteAll(element: T): number

deleteAt

  • deleteAt(cursor: VectorCursor<T>): void

deleteAtIndex

  • deleteAtIndex(index: number): void

has

  • has(element: T): boolean

peek

  • peek(): T

pop

  • pop(): T
  • Get the next element in the order defined by the queue and remove it from the collection.

    Returns T

toRange

  • toRange(): VectorRange<T>

Legend

  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method

Generated using TypeDoc