From: Jérôme Benoit Date: Sun, 13 Jul 2025 18:21:37 +0000 (+0200) Subject: refactor(queue): cleanup variables namespace X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5434cce8cce124245882592ee9ab753b06cfaf41;p=poolifier.git refactor(queue): cleanup variables namespace Signed-off-by: Jérôme Benoit --- diff --git a/src/queues/abstract-fixed-queue.ts b/src/queues/abstract-fixed-queue.ts index 3d77377d1..b22b24860 100644 --- a/src/queues/abstract-fixed-queue.ts +++ b/src/queues/abstract-fixed-queue.ts @@ -66,16 +66,16 @@ export abstract class AbstractFixedQueue implements IFixedQueue { --this.size return true } - let physicalShiftIndex = currentPhysicalIndex + let shiftPhysicalIndex = currentPhysicalIndex for (let i = logicalIndex; i < this.size - 1; i++) { - let nextPhysicalIndex = physicalShiftIndex + 1 + let nextPhysicalIndex = shiftPhysicalIndex + 1 if (nextPhysicalIndex === this.capacity) { nextPhysicalIndex = 0 } - this.nodeArray[physicalShiftIndex] = this.nodeArray[nextPhysicalIndex] - physicalShiftIndex = nextPhysicalIndex + this.nodeArray[shiftPhysicalIndex] = this.nodeArray[nextPhysicalIndex] + shiftPhysicalIndex = nextPhysicalIndex } - this.nodeArray[physicalShiftIndex] = undefined + this.nodeArray[shiftPhysicalIndex] = undefined --this.size return true } diff --git a/src/queues/fixed-priority-queue.ts b/src/queues/fixed-priority-queue.ts index 35b262d6e..c5fc17aee 100644 --- a/src/queues/fixed-priority-queue.ts +++ b/src/queues/fixed-priority-queue.ts @@ -29,19 +29,20 @@ export class FixedPriorityQueue currentPhysicalIndex = 0 } } - let end = this.start + this.size - if (end >= this.capacity) { - end -= this.capacity + let endPhysicalIndex = this.start + this.size + if (endPhysicalIndex >= this.capacity) { + endPhysicalIndex -= this.capacity } if (insertionPhysicalIndex === -1) { - insertionPhysicalIndex = end + insertionPhysicalIndex = endPhysicalIndex } else { - let toShiftIndex = end - while (toShiftIndex !== insertionPhysicalIndex) { - const previousIndex = - toShiftIndex === 0 ? this.capacity - 1 : toShiftIndex - 1 - this.nodeArray[toShiftIndex] = this.nodeArray[previousIndex] - toShiftIndex = previousIndex + let shiftPhysicalIndex = endPhysicalIndex + while (shiftPhysicalIndex !== insertionPhysicalIndex) { + const previousPhysicalIndex = + shiftPhysicalIndex === 0 ? this.capacity - 1 : shiftPhysicalIndex - 1 + this.nodeArray[shiftPhysicalIndex] = + this.nodeArray[previousPhysicalIndex] + shiftPhysicalIndex = previousPhysicalIndex } } this.nodeArray[insertionPhysicalIndex] = { data, priority }