@thermopylae/lib.cache
Version:
28 lines (27 loc) • 618 B
JavaScript
class CircularBuffer {
storage;
capacity;
constructor(capacity) {
this.storage = new Set();
this.capacity = capacity;
}
get size() {
return this.storage.size;
}
add(element) {
if (this.storage.size === this.capacity) {
this.storage.delete(this.storage.values().next().value);
}
this.storage.add(element);
}
has(element) {
return this.storage.has(element);
}
delete(element) {
return this.storage.delete(element);
}
clear() {
this.storage.clear();
}
}
export { CircularBuffer };