es-next-tools
Version:
A comprehensive utility library for JavaScript and TypeScript that provides a wide range of functions for common programming tasks, including mathematical operations, date manipulations, array and object handling, string utilities, and more.
60 lines (59 loc) • 1.85 kB
TypeScript
/**
* Represents a queue data structure.
* @template T The type of elements in the queue.
* @example
* const queue = new Queue<number>();
* queue.enqueue(1).enqueue(2);
* console.log(queue.dequeue()); // 1
*/
export declare class Queue<T> {
private items;
/**
* Adds an item to the end of the queue.
* @param {T} item - The item to add to the queue.
* @returns {Queue<T>} The queue instance for chaining.
*/
enqueue(item: T): this;
/**
* Removes and returns the item at the front of the queue.
* @returns {T} The item at the front of the queue.
* @throws {Error} If the queue is empty.
*/
dequeue(): T;
/**
* Returns the number of items in the queue.
* @returns {number} The size of the queue.
*/
size(): number;
/**
* Returns the item at the front of the queue without removing it.
* @returns {T | undefined} The item at the front of the queue, or undefined if the queue is empty.
*/
peek(): T | undefined;
/**
* Checks if the queue is empty.
* @returns {boolean} True if the queue is empty, false otherwise.
*/
isEmpty(): boolean;
/**
* Checks if the queue contains a specific item.
* @param {T} item - The item to check for.
* @returns {boolean} True if the item is in the queue, false otherwise.
*/
contains(item: T): boolean;
/**
* Creates a copy of the queue.
* @returns {Queue<T>} A new queue instance with the same items.
*/
copy(): Queue<T>;
/**
* Serializes the queue to a JSON string.
* @returns {string} The serialized queue.
*/
serialize(): string;
/**
* Deserializes a JSON string to populate the queue.
* @param {string} data - The JSON string to deserialize.
*/
deserialize(data: string): void;
}