}
}
+ backward (): Iterable<T> {
+ return {
+ [Symbol.iterator]: (): Iterator<T> => {
+ let node = this.tail
+ return {
+ next: () => {
+ if (node == null) {
+ return {
+ value: undefined,
+ done: true
+ }
+ }
+ const ret = {
+ value: node.value,
+ done: false
+ }
+ node = node.prev as Node<T>
+ return ret
+ }
+ }
+ }
+ }
+ }
+
private incrementSize (): number {
++this.size
if (this.size > this.maxSize) {
/**
* Check the next worker node eligibility.
*
- * @param chosenWorkerNodeKey - The chosen worker node key.
+ * @param chosenNextWorkerNodeKey - The chosen worker node key.
*/
protected checkNextWorkerNodeEligibility (
- chosenWorkerNodeKey: number | undefined
+ chosenNextWorkerNodeKey: number | undefined
): void {
if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
this.nextWorkerNodeKey = undefined
this.previousWorkerNodeKey =
- chosenWorkerNodeKey ?? this.previousWorkerNodeKey
+ chosenNextWorkerNodeKey ?? this.previousWorkerNodeKey
}
}
++i
}
})
+
+ it('Verify backward() iterator behavior', () => {
+ const deque = new Deque()
+ deque.push(1)
+ deque.push(2)
+ deque.push(3)
+ let i = deque.size
+ for (const value of deque.backward()) {
+ expect(value).toBe(i)
+ --i
+ }
+ })
})