* Get all items currently in the buffer, in order from oldest to newest.
()
| 53 | * Get all items currently in the buffer, in order from oldest to newest. |
| 54 | */ |
| 55 | toArray(): T[] { |
| 56 | if (this.size === 0) return [] |
| 57 | |
| 58 | const result: T[] = [] |
| 59 | const start = this.size < this.capacity ? 0 : this.head |
| 60 | |
| 61 | for (let i = 0; i < this.size; i++) { |
| 62 | const index = (start + i) % this.capacity |
| 63 | result.push(this.buffer[index]!) |
| 64 | } |
| 65 | |
| 66 | return result |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Clear all items from the buffer. |
no test coverage detected