R
C

PriorityQueue

v0.0.8tested

Priority queue backed by a binary heap with configurable comparator and optional max size

Signature

ts
class PriorityQueue<T> implements PriorityQueueLike<T>

Type Parameters

T

Properties

PropertyTypeDescription
lengthreadonlynumberGets the number of elements in the queue
isEmptyreadonlybooleanChecks if the queue is empty
isFullreadonlybooleanChecks if the queue is full

Methods

enqueue

Enqueues an element by priority

ts
public enqueue(element: T): void
ParameterTypeDescription
elementTThe element to enqueue
dequeue

Dequeues the highest-priority element

ts
public dequeue(): T | undefined
ReturnsT | undefinedThe highest-priority element, or `undefined` if empty
peek

Returns the highest-priority element without removing it

ts
public peek(): T | undefined
ReturnsT | undefinedThe highest-priority element, or `undefined` if empty
clear

Removes all elements from the queue

ts
public clear(): this
ReturnsthisThe queue instance for chaining
toArray

Returns a shallow copy of elements in heap order

ts
public toArray(): T[]
ReturnsT[]Array of elements
toString

Returns a string representation of the queue

ts
public toString(): string
ReturnsstringString representation
[Symbol.iterator]

Iterator over queue elements in heap order

ts
public* [Symbol.iterator](): Iterator<T>
ReturnsIterator<T, any, any>
[Symbol.asyncIterator]

Async iterator over queue elements in heap order

ts
public async* [Symbol.asyncIterator](): AsyncIterator<T>
ReturnsAsyncIterator<T, any, any>