js-heap-data-structures
Version:
A comprehensive JavaScript implementation of Min Heap and Max Heap data structures with practical utilities
65 lines (64 loc) • 1.78 kB
TypeScript
export = PriorityQueue;
/**
* Priority Queue implementation using Max Heap
*/
declare class PriorityQueue {
constructor(compareFn?: null);
heap: any[];
compare: (a: any, b: any) => boolean;
/**
* Add an item with priority
* @param {*} item - The item to add
* @param {number} priority - The priority of the item
*/
enqueue(item: any, priority: number): void;
/**
* Remove and return the highest priority item
* @returns {*} The highest priority item
* @throws {Error} If queue is empty
*/
dequeue(): any;
/**
* Get the highest priority item without removing it
* @returns {*} The highest priority item
* @throws {Error} If queue is empty
*/
peek(): any;
/**
* Get the priority of the highest priority item
* @returns {number} The highest priority
* @throws {Error} If queue is empty
*/
peekPriority(): number;
/**
* Check if queue is empty
* @returns {boolean} True if queue is empty
*/
isEmpty(): boolean;
/**
* Get size of queue
* @returns {number} Size of queue
*/
size(): number;
/**
* Clear the queue
*/
clear(): void;
/**
* Get all items as array (for debugging)
* @returns {Array} Array of {item, priority} objects
*/
toArray(): any[];
getParentIndex(index: any): number;
getLeftChildIndex(index: any): number;
getRightChildIndex(index: any): number;
hasParent(index: any): boolean;
hasLeftChild(index: any): boolean;
hasRightChild(index: any): boolean;
parent(index: any): any;
leftChild(index: any): any;
rightChild(index: any): any;
swap(index1: any, index2: any): void;
heapifyUp(): void;
heapifyDown(): void;
}