Spaces:
Paused
Paused
Download client/src/lib/circularBuffer.ts from PatternBreak/FacePoke: direct link, hf CLI and curl.
- Browser
- Download file 715 Bytes
-
https://huggingface.co/spaces/PatternBreak/FacePoke/resolve/main/client/src/lib/circularBuffer.ts
- Command line
-
hf download hf://spaces/PatternBreak/FacePoke/client/src/lib/circularBuffer.ts
-
curl -L -o circularBuffer.ts https://huggingface.co/spaces/PatternBreak/FacePoke/resolve/main/client/src/lib/circularBuffer.ts
715 Bytes
| /** | |
| * Circular buffer for storing and managing response times. | |
| */ | |
| export class CircularBuffer<T> { | |
| private buffer: T[]; | |
| private pointer: number; | |
| constructor(private capacity: number) { | |
| this.buffer = new Array<T>(capacity); | |
| this.pointer = 0; | |
| } | |
| /** | |
| * Adds an item to the buffer, overwriting the oldest item if full. | |
| * @param item - The item to add to the buffer. | |
| */ | |
| push(item: T): void { | |
| this.buffer[this.pointer] = item; | |
| this.pointer = (this.pointer + 1) % this.capacity; | |
| } | |
| /** | |
| * Retrieves all items currently in the buffer. | |
| * @returns An array of all items in the buffer. | |
| */ | |
| getAll(): T[] { | |
| return this.buffer.filter(item => item !== undefined); | |
| } | |
| } | |