uid-pool
Version:
High-performance UUID and unique ID pooling for Node.js. Pre-generate IDs in background worker threads for O(1) synchronous acquisition. Drop-in replacement for uuid.v4() and nanoid() with 10-100x better performance under load.
48 lines • 1.24 kB
TypeScript
/**
* High-performance circular buffer implementation with O(1) enqueue/dequeue.
* Avoids Array.shift() which has O(n) complexity.
*/
export declare class CircularBuffer<T> {
private buffer;
private head;
private tail;
private size;
private readonly capacity;
constructor(capacity: number);
/**
* Add an item to the buffer (O(1) operation).
* Returns false if buffer is full.
*/
enqueue(item: T): boolean;
/**
* Add multiple items to the buffer efficiently.
* Returns number of items successfully added.
*/
enqueueBatch(items: T[]): number;
/**
* Remove and return an item from the buffer (O(1) operation).
* Returns undefined if buffer is empty.
*/
dequeue(): T | undefined;
/**
* Get the number of items currently in the buffer.
*/
getSize(): number;
/**
* Get the remaining capacity of the buffer.
*/
getAvailableSpace(): number;
/**
* Check if the buffer is empty.
*/
isEmpty(): boolean;
/**
* Check if the buffer is full.
*/
isFull(): boolean;
/**
* Clear all items from the buffer.
*/
clear(): void;
}
//# sourceMappingURL=circular-buffer.d.ts.map