@devgrid/common
Version:
Some useful primitives
36 lines • 803 B
JavaScript
export class ListBuffer {
constructor() {
this.head = null;
this.tail = null;
this.size = 0;
}
push(value) {
const node = { value, next: null };
if (!this.tail) {
this.head = this.tail = node;
}
else {
this.tail.next = node;
this.tail = node;
}
this.size++;
}
shift() {
if (!this.head)
return undefined;
const value = this.head.value;
this.head = this.head.next;
if (!this.head)
this.tail = null;
this.size--;
return value;
}
get length() {
return this.size;
}
clear() {
this.head = this.tail = null;
this.size = 0;
}
}
//# sourceMappingURL=list-buffer.js.map