From 5434cce8cce124245882592ee9ab753b06cfaf41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 13 Jul 2025 20:21:37 +0200 Subject: [PATCH] refactor(queue): cleanup variables namespace MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/queues/abstract-fixed-queue.ts | 10 +++++----- src/queues/fixed-priority-queue.ts | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) 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 } -- 2.43.0