@technobuddha/library
Version:
A large library of useful functions
56 lines (55 loc) • 1.59 kB
TypeScript
/**
* A simple priority queue
* @group Utility
* @category Classes
*/
export declare class PriorityQueue<T> {
private comparator;
/**
* Creates a new PriorityQueue.
*
* @param comparator - Function to compare two elements and puts them in priority order. Takes two elements as arguments and returns a number greater, less
* then or equal to zero.
* @param contents - Initial contents of the queue
*/
constructor(comparator: (a: T, b: T) => number, contents?: Iterable<T>);
private readonly contents;
private sorted;
private sort;
/**
* Add an element to the queue
* @param o - element to be added
*/
push(...o: T[]): void;
/**
* Return and remove the highest priority item from the queue
*
* @returns queue element
*/
pop(): T | undefined;
/**
* Iterate through all elements in the queue
*
* @returns generator function
*/
[Symbol.iterator](): Iterator<T>;
/**
* Determine the number of items in the queue
*
* @returns number of element in the queue
*/
get size(): number;
/**
* Transform all elements in the queue
*
* @param f - Function to transform each element of the queue
* @returns array of transformed queue elements
*/
map<S>(f: (value: T, index: number, array: T[]) => S): S[];
/**
* Change the function used to order the queue
*
* @param newComparator - function to compare elements of the queue
*/
reorder(newComparator: (a: T, b: T) => number): void;
}