"use strict"
var __createBinding =
  (this && this.__createBinding) ||
  (Object.create
    ? function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        Object.defineProperty(o, k2, {
          enumerable: true,
          get: function () {
            return m[k]
          }
        })
      }
    : function (o, m, k, k2) {
        if (k2 === undefined) k2 = k
        o[k2] = m[k]
      })
var __setModuleDefault =
  (this && this.__setModuleDefault) ||
  (Object.create
    ? function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v })
      }
    : function (o, v) {
        o["default"] = v
      })
var __importStar =
  (this && this.__importStar) ||
  function (mod) {
    if (mod && mod.__esModule) return mod
    var result = {}
    if (mod != null)
      for (var k in mod)
        if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
          __createBinding(result, mod, k)
    __setModuleDefault(result, mod)
    return result
  }
Object.defineProperty(exports, "__esModule", { value: true })
exports.RingBuffer = void 0
// tracing: off
require("../../Operator")
const L = __importStar(require("../../Collections/Immutable/List"))
const DoublyLinkedList_1 = require("../DoublyLinkedList")
class RingBuffer {
  constructor(size, ignoreFn) {
    this.size = size
    this.ignoreFn = ignoreFn
    this.values = new DoublyLinkedList_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
  }
  get list() {
    const l = L.emptyPushable()
    this.values.forEach((t) => {
      L.push_(l, t)
    })
    return l
  }
  get listReverse() {
    return L.reverse(this.list)
  }
}
exports.RingBuffer = RingBuffer
//# sourceMappingURL=index.js.map
