UNPKG

@figliolia/data-structures

Version:

Efficient data structures for every day programming

42 lines (41 loc) 1.06 kB
import { QuickList } from "./QuickList"; /** * Quick Queue * * A wrapper around the native Map that assigns an * auto-incrementing ID to each value added. It provides * a Queue-like interface with the ability to access and * remove items in 0(1) time * * ```typescript * const queue = new QuickQueue<() => void>(); * const uniqueID = queue.enqueue(() => {}); * * const FN = queue.dequeue() // Remove and return the first item on the queue * const FN = queue.get(uniqueID); // Get an item by ID * queue.delete(uniqueID) // Delete an item by ID * ``` */ export declare class QuickQueue<T> extends QuickList<T> { /** * Enqueue * * Adds an item to the queue and returns it's * unique ID */ enqueue(item: T): string; /** * Dequeue * * Removes the first item from the Bucket and * returns it */ dequeue(): T | undefined; /** * Peek * * Returns the first item from the Bucket or undefined * if the queue is empty */ peek(): [string, T] | undefined; }