X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpriority-queue.ts;h=1c0d8c929967b2fa52f728f7b395ed013f044fda;hb=53208d1a2f99d14a1fa854910411e2a69d5ce29f;hp=64b5a9248a804130107b810c412bf4c978ae8cd9;hpb=5d9133ae9ef83c5f69e26daf8dcfea584884d9c4;p=poolifier.git diff --git a/src/priority-queue.ts b/src/priority-queue.ts index 64b5a924..1c0d8c92 100644 --- a/src/priority-queue.ts +++ b/src/priority-queue.ts @@ -26,6 +26,13 @@ export class PriorityQueue { /** The maximum size of the priority queue. */ public maxSize!: number + /** + * The number of filled prioritized buckets. + */ + public get buckets (): number { + return this.k === Infinity ? 1 : Math.trunc(this.nodeArray.length / this.k) + } + /** * Constructs a priority queue. * @@ -51,10 +58,7 @@ export class PriorityQueue { */ public enqueue (data: T, priority?: number): number { priority = priority ?? 0 - const startIndex = - this.k === Infinity || this.nodeArray.length / this.k < 1 - ? 0 - : Math.trunc(this.nodeArray.length / this.k) * this.k + const startIndex = this.k === Infinity ? 0 : this.buckets * this.k let inserted = false for (let index = startIndex; index < this.nodeArray.length; index++) { if (this.nodeArray[index].priority > priority) {