* Double the backing capacity, linearizing the circular layout.
()
| 137 | * Double the backing capacity, linearizing the circular layout. |
| 138 | */ |
| 139 | #grow() { |
| 140 | const newCapacity = (this.#mask + 1) * 2; |
| 141 | const newBacking = new Array(newCapacity); |
| 142 | for (let i = 0; i < this.#size; i++) { |
| 143 | newBacking[i] = this.#backing[(this.#head + i) & this.#mask]; |
| 144 | } |
| 145 | this.#backing = newBacking; |
| 146 | this.#head = 0; |
| 147 | this.#mask = newCapacity - 1; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | module.exports = { RingBuffer }; |