@dcoffey/espells
Version:
Pure JS/TS spellchecker, using Hunspell dictionaries. Based on Spylls.
40 lines (39 loc) • 1.38 kB
TypeScript
/**
* Wrapper around a normal array that uses a comparator function to ensure
* that the lowest index in the array is of the minimum priority.
*
* @typeParam T - The type of object to be stored in the list.
*/
export declare class PriorityList<T> {
/** The comparator function that is used to sort the list. */
cmp: (a: T, b: T) => number;
/** The actual list that is being wrapped around. */
data: T[];
/**
* @param cmp - The comparator function that the list will be sorted
* with. Returning a negative value from this function indicates that
* `a` has a lower priority than `b`, while a positive value indicates
* that `a` has a higher priority than `b`.
*/
constructor(cmp: (a: T, b: T) => number);
/** Length of the list. */
get length(): number;
/** Returns the lowest priority in the list. */
peek(): T;
/**
* Adds a new value to the list.
*
* @param val - The value to be added.
*/
push(val: T): number;
/** Removes the lowest priority item in the list. */
pop(): T;
/**
* Completely sorts the list using a comparator function and returns the
* actual internal array.
*
* @param cmp - The comparator function to use. Defaults to the one the
* list was instantiated with.
*/
sort(cmp?: (a: T, b: T) => number): T[];
}