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.
37 lines (36 loc) • 1.05 kB
TypeScript
/**
* Represents a circular buffer data structure.
* @template T The type of elements in the circular buffer.
*/
export declare class CircularBuffer<T> {
private buffer;
private head;
private tail;
private size;
private capacity;
/**
* Creates a circular buffer with a specified capacity.
* @param {number} capacity - The maximum number of items the buffer can hold.
*/
constructor(capacity: number);
/**
* Adds an item to the buffer.
* @param {T} item - The item to add.
*/
add(item: T): void;
/**
* Removes and returns the oldest item from the buffer.
* @returns {T | undefined} The oldest item, or undefined if the buffer is empty.
*/
remove(): T | undefined;
/**
* Returns the current size of the buffer.
* @returns {number} The number of items in the buffer.
*/
getSize(): number;
/**
* Checks if the buffer is empty.
* @returns {boolean} True if the buffer is empty, false otherwise.
*/
isEmpty(): boolean;
}