import * as tsplus_module_1 from "@tsplus/stdlib/collections/mutable/DoublyLinkedList";
import * as tsplus_module_2 from "@tsplus/stdlib/collections/Chunk/builder";
import * as tsplus_module_3 from "@tsplus/stdlib/collections/Chunk/reverse";
import * as tsplus_module_4 from "@tsplus/stdlib/collections/Chunk/definition";
export class RingBuffer {
  constructor(size, ignoreFn) {
    this.size = size;
    this.ignoreFn = ignoreFn;
    this.values = new tsplus_module_1.DoublyLinkedList();
    this.ignored = 0;
  }

  push(value) {
    if (this.values.length - this.ignored >= this.size) {
      this.values.shift();
    }

    this.values.add(value);

    if (this.ignoreFn && this.ignoreFn(value)) {
      this.ignored++;
    }

    return this.values;
  }

  pop() {
    const popped = this.values.pop();

    if (popped && this.ignoreFn && this.ignoreFn(popped)) {
      this.ignored--;
    }

    return this.values;
  }

  toChunk() {
    const chunk = tsplus_module_2.builder();
    this.values.forEach(t => {
      chunk.append(t);
    });
    return chunk.build();
  }

  toChunkReversed() {
    return tsplus_module_4.from(tsplus_module_3.reverse(this.toChunk()));
  }

}
//# sourceMappingURL=RingBuffer.mjs.map