From 65729b19f8371b8034d61c7771c8ece6e3692260 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 11 May 2024 19:35:01 +0200 Subject: [PATCH] refactor: cleanup priority queue size handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc.cjs | 1 + src/priority-queue.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ef9e86c0..af3c350b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -45,6 +45,7 @@ module.exports = defineConfig({ 'cpus', 'cryptographically', 'ctx', + 'decrement', 'deprecations', 'deque', 'dequeue', diff --git a/src/priority-queue.ts b/src/priority-queue.ts index 1c0d8c92..e68fe37d 100644 --- a/src/priority-queue.ts +++ b/src/priority-queue.ts @@ -91,9 +91,7 @@ export class PriorityQueue { --bucket } } - if (this.size > 0) { - --this.size - } + this.decrementSize() return this.nodeArray.shift()?.data } @@ -160,4 +158,16 @@ export class PriorityQueue { } return this.size } + + /** + * Decrements the size of the priority queue. + * + * @returns The new size of the priority queue. + */ + private decrementSize (): number { + if (this.size > 0) { + --this.size + } + return this.size + } } -- 2.34.1