UNPKG

@panyam/priorityq

Version:

A Priority Queue implementation with O(1) lookups for lookup by value.

24 lines (23 loc) 803 B
import { Comparator, Handle, Storage } from "./storage"; declare type KeyType = string | number; declare type KeyFunc<T> = (value: T) => KeyType; export declare class PQ<T> { keyFunc: KeyFunc<T>; storage: Storage<T>; handlesByValue: Map<KeyType, [Handle<T>, number]>; constructor(comparatorOrStorage: Comparator<T> | Storage<T>, keyFunc?: KeyFunc<T>); get top(): Handle<T>; pop(): T | null; push(value: T): Handle<T>; heapify(values: IterableIterator<T>): void; adjustValue(value: T): void; adjust(handle: Handle<T>): void; removeValue(value: T): void; remove(handle: Handle<T>): void; findByKey(key: KeyType): Handle<T> | null; find(value: T): Handle<T> | null; get size(): number; get isEmpty(): boolean; clear(): void; } export {};