forgetful-circular-buffer
v1.0.0
Published
A simple forgetful circular buffer
Downloads
6
Maintainers
Readme
Forgetful circular buffer
A simple forgetful circular buffer (or circular queue) in TypeScript
- Tiny and lightweight
- Dependency-free (uses devDependencies only)
- 100% unit test coverage
Usage
import { CircularBuffer } from "forgetful-circular-buffer";
const buffer = new CircularBuffer<number>(5);
console.log(buffer.isEmpty());
// true
buffer.write(1);
buffer.write(2);
buffer.write(3);
console.log(buffer.getCurrentSize());
// 3
console.log(buffer.read());
// 1
// buffer.readAll() returns a Generator
for (const item of buffer.readAll()) {
console.log(item);
}
// 2, 3
Also see the example