* Get the most recent N items from the buffer. * Returns fewer items if the buffer contains less than N items.
(count: number)
| 37 | * Returns fewer items if the buffer contains less than N items. |
| 38 | */ |
| 39 | getRecent(count: number): T[] { |
| 40 | const result: T[] = [] |
| 41 | const start = this.size < this.capacity ? 0 : this.head |
| 42 | const available = Math.min(count, this.size) |
| 43 | |
| 44 | for (let i = 0; i < available; i++) { |
| 45 | const index = (start + this.size - available + i) % this.capacity |
| 46 | result.push(this.buffer[index]!) |
| 47 | } |
| 48 | |
| 49 | return result |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get all items currently in the buffer, in order from oldest to newest. |
no test coverage detected