UNPKG

@graphty/algorithms

Version:

Graph algorithms library for browser environments implemented in TypeScript

60 lines 1.58 kB
/** * 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. */ export declare class PriorityQueue<T> { private heap; private compareFn; constructor(compareFn?: (a: number, b: number) => number); /** * Add an item with the given priority to the queue */ enqueue(item: T, priority: number): void; /** * Remove and return the item with the highest priority */ dequeue(): T | undefined; /** * View the item with the highest priority without removing it */ peek(): T | undefined; /** * Check if the queue is empty */ isEmpty(): boolean; /** * Get the number of items in the queue */ size(): number; /** * Update the priority of an item if it exists in the queue * Returns true if the item was found and updated */ updatePriority(item: T, newPriority: number): boolean; /** * Clear all items from the queue */ clear(): void; /** * Convert queue to array (for testing/debugging) */ toArray(): { item: T; priority: number; }[]; /** * Move element up the heap until heap property is satisfied */ private heapifyUp; /** * Move element down the heap until heap property is satisfied */ private heapifyDown; /** * Swap two elements in the heap */ private swap; } //# sourceMappingURL=priority-queue.d.ts.map