module.exports = class SeekOffsets extends Map {
  set(topic, partition, offset) {
    super.set([topic, partition], offset)
  }

  has(topic, partition) {
    return Array.from(this.keys()).some(([t, p]) => t === topic && p === partition)
  }

  pop() {
    if (this.size === 0) {
      return
    }

    const [key, offset] = Array.from(this.entries())
      .reverse()
      .pop()
    this.delete(key)
    const [topic, partition] = key
    return { topic, partition, offset }
  }
}

module.exports = class SeekOffsets extends Map {
  set(topic, partition, offset) {
    super.set([topic, partition], offset)
  }

  has(topic, partition) {
    return Array.from(this.keys()).some(([t, p]) => t === topic && p === partition)
  }

  pop() {
    if (this.size === 0) {
      return
    }

    const [key, offset] = this.entries().next().value
    this.delete(key)
    const [topic, partition] = key
    return { topic, partition, offset }
  }
}

Simplify and speed up the SeekOffsets code
Simplify and speed up the SeekOffsets code

Replace the complex and inefficient O(n)-ish logic with a simpler
O(1) approach.
We don't need to make an array of all entries, reverse that, and then pop
one element -- we only need to know the first key/value pair.
