- dequeue (): T | undefined {
- if (this.size() <= 0) return undefined
- const item = this.items[this.head]
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
- delete this.items[this.head]
- this.head++
- if (this.head === this.tail) {
- this.head = 0
- this.tail = 0
+ /**
+ * Dequeue an item.
+ *
+ * @returns The dequeued item or `undefined` if the queue is empty.
+ */
+ public dequeue (): T | undefined {
+ if (this.size <= 0) {
+ return undefined
+ }
+ const item = this.items[this.offset]
+ if (++this.offset * 2 >= this.items.length) {
+ this.items = this.items.slice(this.offset)
+ this.offset = 0