C
PriorityQueue
v0.0.8testedPriority queue backed by a binary heap with configurable comparator and optional max size
Signature
ts
class PriorityQueue<T> implements PriorityQueueLike<T>Type Parameters
TProperties
| Property | Type | Description |
|---|---|---|
lengthreadonly | number | Gets the number of elements in the queue |
isEmptyreadonly | boolean | Checks if the queue is empty |
isFullreadonly | boolean | Checks if the queue is full |
Methods
enqueueEnqueues an element by priority
ts
public enqueue(element: T): void| Parameter | Type | Description |
|---|---|---|
element | T | The element to enqueue |
dequeueDequeues the highest-priority element
ts
public dequeue(): T | undefinedReturns
T | undefinedThe highest-priority element, or `undefined` if emptypeekReturns the highest-priority element without removing it
ts
public peek(): T | undefinedReturns
T | undefinedThe highest-priority element, or `undefined` if emptyclearRemoves all elements from the queue
ts
public clear(): thisReturns
thisThe queue instance for chainingtoArrayReturns a shallow copy of elements in heap order
ts
public toArray(): T[]Returns
T[]Array of elementstoStringReturns a string representation of the queue
ts
public toString(): stringReturns
stringString representation[Symbol.iterator]Iterator over queue elements in heap order
ts
public* [Symbol.iterator](): Iterator<T>Returns
Iterator<T, any, any>[Symbol.asyncIterator]Async iterator over queue elements in heap order
ts
public async* [Symbol.asyncIterator](): AsyncIterator<T>Returns
AsyncIterator<T, any, any>