From: Jérôme Benoit Date: Tue, 28 May 2024 20:58:18 +0000 (+0200) Subject: docs: refine queueing code comment X-Git-Tag: v4.0.13~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=13ed544a17e9b0e3a8447cfea17964709cdaffa1;p=poolifier.git docs: refine queueing code comment Signed-off-by: Jérôme Benoit --- diff --git a/src/fixed-priority-queue.ts b/src/fixed-priority-queue.ts index 2d851ca4..a248aa7e 100644 --- a/src/fixed-priority-queue.ts +++ b/src/fixed-priority-queue.ts @@ -65,6 +65,7 @@ export class FixedPriorityQueue { * @param data - Data to enqueue. * @param priority - Priority of the data. Lower values have higher priority. * @returns The new size of the priority queue. + * @throws If the fixed priority queue is full. */ public enqueue (data: T, priority?: number): number { if (this.full()) { @@ -74,8 +75,10 @@ export class FixedPriorityQueue { let index = this.start let inserted = false for (let i = 0; i < this.size; i++) { - if (this.nodeArray[index]?.priority > priority) { + if (this.nodeArray[index].priority > priority) { this.nodeArray.splice(index, 0, { data, priority }) + this.nodeArray.length !== this.capacity && + (this.nodeArray.length = this.capacity) inserted = true break } @@ -84,8 +87,6 @@ export class FixedPriorityQueue { index = 0 } } - this.nodeArray.length !== this.capacity && - (this.nodeArray.length = this.capacity) if (!inserted) { let index = this.start + this.size if (index >= this.capacity) { diff --git a/src/priority-queue.ts b/src/priority-queue.ts index ce96b4e8..0f75e52b 100644 --- a/src/priority-queue.ts +++ b/src/priority-queue.ts @@ -27,6 +27,7 @@ export class PriorityQueue { private head!: PriorityQueueNode private tail!: PriorityQueueNode private readonly bucketSize: number + /** The priority queue maximum size. */ public maxSize!: number /** @@ -49,7 +50,7 @@ export class PriorityQueue { } /** - * The size of the priority queue. + * The priority queue size. */ public get size (): number { let node: PriorityQueueNode | undefined = this.tail