UNPKG

@technobuddha/library

Version:
53 lines (52 loc) 1.55 kB
/** * A simple priority queue */ export declare class PriorityQueue<T> { private comparator; /** * @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](): Generator<T, void, undefined>; /** * 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 transforme 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; } export default PriorityQueue;