@graphty/algorithms / index / PriorityQueue
Class: PriorityQueue<T> ​
Defined in: data-structures/priority-queue.ts:7
Priority Queue implementation using a binary heap
Optimized for graph algorithms requiring efficient priority-based operations. Uses a min-heap by default but supports custom comparison functions.
Type Parameters ​
T ​
T
Constructors ​
Constructor ​
new PriorityQueue<
T>(compareFn?):PriorityQueue<T>
Defined in: data-structures/priority-queue.ts:15
Creates a new PriorityQueue instance.
Parameters ​
compareFn? ​
(a, b) => number
Custom comparison function for priorities. Returns negative if a has higher priority than b.
Returns ​
PriorityQueue<T>
Methods ​
clear() ​
clear():
void
Defined in: data-structures/priority-queue.ts:119
Clear all items from the queue
Returns ​
void
dequeue() ​
dequeue():
T|undefined
Defined in: data-structures/priority-queue.ts:36
Remove and return the item with the highest priority
Returns ​
T | undefined
The item with the highest priority, or undefined if the queue is empty
enqueue() ​
enqueue(
item,priority):void
Defined in: data-structures/priority-queue.ts:26
Add an item with the given priority to the queue
Parameters ​
item ​
T
The item to add to the queue
priority ​
number
The priority value for the item (lower values have higher priority in min-heap)
Returns ​
void
isEmpty() ​
isEmpty():
boolean
Defined in: data-structures/priority-queue.ts:73
Check if the queue is empty
Returns ​
boolean
True if the queue has no items, false otherwise
peek() ​
peek():
T|undefined
Defined in: data-structures/priority-queue.ts:64
View the item with the highest priority without removing it
Returns ​
T | undefined
The item with the highest priority, or undefined if the queue is empty
size() ​
size():
number
Defined in: data-structures/priority-queue.ts:81
Get the number of items in the queue
Returns ​
number
The number of items currently in the queue
toArray() ​
toArray():
object[]
Defined in: data-structures/priority-queue.ts:127
Convert queue to array (for testing/debugging)
Returns ​
object[]
An array of all items with their priorities
updatePriority() ​
updatePriority(
item,newPriority):boolean
Defined in: data-structures/priority-queue.ts:91
Update the priority of an item if it exists in the queue
Parameters ​
item ​
T
The item whose priority should be updated
newPriority ​
number
The new priority value for the item
Returns ​
boolean
True if the item was found and updated, false otherwise