Skip to content

PriorityQueue

Defined in: packages/data/src/priority-queue/priority-queue.ts:21

An unbounded priority queue.

For a capacity, use BoundedPriorityQueue (throws when full) or BlockingPriorityQueue (waits).

T extends DefinedValue

The type of elements in the priority queue.

P = number

The type of priority associated with each element.

new PriorityQueue<T, P>(precedes?, iterable?, options?): PriorityQueue<T, P>

Defined in: packages/data/src/priority-queue/priority-queue.ts:28

OrderPredicate<P> = ...

Iterable<[T, P], any, any>

PriorityQueueOptions<T, P>

PriorityQueue<T, P>

readonly precedes: OrderPredicate<P>

Defined in: packages/data/src/priority-queue/priority-queue.ts:29

Strict weak ordering over priorities: precedes(a, b) means a outranks b.

IPriorityQueue.precedes

[iterator](): Iterator<T>

Defined in: packages/data/src/priority-queue/priority-queue.ts:45

Iterator<T>

IPriorityQueue.[iterator]


clear(): void

Defined in: packages/data/src/priority-queue/priority-queue.ts:51

Removes all elements from the collection.

void

IPriorityQueue.clear


count(): number

Defined in: packages/data/src/priority-queue/priority-queue.ts:55

The number of elements in the collection.

A method, not a getter: its async counterpart needs a round trip to the backing store, and a member must have the same shape in both.

number

IPriorityQueue.count


entries(): IterableIterator<PriorityEntry<T, P>>

Defined in: packages/data/src/priority-queue/priority-queue.ts:164

Drains a copy of the heap in priority order, leaving this queue untouched — the storage’s own iteration order is heap order, not priority order.

IterableIterator<PriorityEntry<T, P>>

IPriorityQueue.entries


extract(): T | undefined

Defined in: packages/data/src/priority-queue/priority-queue.ts:71

Removes and returns the item with the highest priority from the priority queue.

T | undefined

The item with the highest priority, or undefined if the queue is empty.

IPriorityQueue.extract


insert(priority, value): void

Defined in: packages/data/src/priority-queue/priority-queue.ts:59

Inserts an item with its associated priority into the priority queue.

P

The priority of the item to insert.

T

void

IPriorityQueue.insert


insertAll(priority, items): void

Defined in: packages/data/src/priority-queue/priority-queue.ts:64

Inserts every item at the same priority into the priority queue.

P

The priority shared by all the items to insert.

readonly T[]

The items to insert.

void

IPriorityQueue.insertAll


peek(): T | undefined

Defined in: packages/data/src/priority-queue/priority-queue.ts:89

Returns the item with the highest priority without removing it from the queue.

T | undefined

The item with the highest priority, or undefined if the queue is empty.

IPriorityQueue.peek


remove(condition): boolean

Defined in: packages/data/src/priority-queue/priority-queue.ts:132

Removes the first entry matching condition, restoring the heap property afterward.

Not part of IPriorityQueue — reaching into the middle of a priority queue by value is a real, occasionally needed capability (e.g. unregistering a previously inserted handler), but not one every consumer needs, matching the extra removeFirst-style surface the list classes carry beyond their own slim interfaces.

Predicate<[T, P]>

A predicate over an entry’s value and priority.

boolean

true if a matching entry was found and removed.


setPriority(item, priority): boolean

Defined in: packages/data/src/priority-queue/priority-queue.ts:93

Updates the priority of an existing item in the priority queue.

T

The item whose priority is to be updated.

P

The new priority of the item.

boolean

true if the item was found and its priority updated, false otherwise.

IPriorityQueue.setPriority