private items: Record<number, T>
private head: number
private tail: number
+ private max: number
public constructor () {
this.items = {}
this.head = 0
this.tail = 0
+ this.max = 0
}
/**
return this.tail - this.head
}
+ /**
+ * Get the maximum size of the queue.
+ *
+ * @returns The maximum size of the queue.
+ * @readonly
+ */
+ public get maxSize (): number {
+ return this.max
+ }
+
/**
* Enqueue an item.
*
public enqueue (item: T): number {
this.items[this.tail] = item
this.tail++
+ if (this.size > this.max) this.max = this.size
return this.size
}
}
return item
}
+
+ /**
+ * Peek at the first item.
+ */
+ public peek (): T | undefined {
+ if (this.size <= 0) return undefined
+ return this.items[this.head]
+ }
}