@figliolia/data-structures
Version:
Efficient data structures for every day programming
57 lines (56 loc) • 1.32 kB
TypeScript
/**
* Priority Queue
*
* A bucket queue that sorts elements based on the priority level specified
*
* ```typescript
* import { PriorityQueue } from "@figliolia/data-structures";
*
* const queue = new PriorityQueue<number>();
* queue.push(1, 3);
* queue.push(2, 2);
* queue.push(3, 1);
* queue.length // 3
* // queue = [[3], [2], [1]]
* while(!queue.isEmpty) {
* queue.pop() // 3, 2, 1
* }
* ```
*/
export declare class PriorityQueue<T> {
readonly buckets: T[][];
readonly maxPriority: number;
private readonly priorities;
constructor(max?: number);
/**
* Push
*
* Adds a new element to the queue at the specified priority level
*/
push(priority: number, value: T): void;
/**
* Pop
*
* Removes the last element added to the highest available priority
*/
pop(): T | undefined;
/**
* Poll
*
* Returns a reference to the last element added to the highest available priority
*/
poll(): T | undefined;
/**
* Length
*
* Returns the total number of items in the queue
*/
get length(): number;
/**
* Is Empty
*
* Returns true if the queue contains no items
*/
get isEmpty(): boolean;
[Symbol.iterator](): Generator<[priority: number, bucket: T[]]>;
}