{"size": 669, "ext": "js", "max_stars_repo_path": "node_modules/fast-fifo/index.js", "max_stars_repo_name": "vikusss/sub4.3", "max_stars_repo_stars_event_min_datetime": "2020-02-23T13:33:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T18:28:02.000Z", "max_issues_repo_path": "node_modules/fast-fifo/index.js", "max_issues_repo_name": "vikusss/sub4.3", "max_issues_repo_issues_event_min_datetime": "2020-02-25T17:12:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T07:15:28.000Z", "max_forks_repo_path": "node_modules/fast-fifo/index.js", "max_forks_repo_name": "vikusss/sub4.3", "max_forks_repo_forks_event_min_datetime": "2020-03-07T05:36:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:56:48.000Z"}
{"max_stars_count": 106, "max_issues_count": 14, "max_forks_count": 24, "avg_line_length": 20.2727272727, "max_line_length": 72, "alphanum_fraction": 0.5784753363}
const FixedFIFO = require('./fixed-size')

module.exports = class FastFIFO {
  constructor (hwm) {
    this.hwm = hwm || 16
    this.head = new FixedFIFO(this.hwm)
    this.tail = this.head
  }

  push (val) {
    if (!this.head.push(val)) {
      const prev = this.head
      this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length)
      this.head.push(val)
    }
  }

  shift () {
    const val = this.tail.shift()
    if (val === undefined && this.tail.next) {
      const next = this.tail.next
      this.tail.next = null
      this.tail = next
      return this.tail.shift()
    }
    return val
  }

  isEmpty () {
    return this.head.isEmpty()
  }
}
