X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Ffixed-priority-queue.ts;h=1cc1480a1b5521d18369cff68a4c2282971f6f85;hb=df01d9a8a7053a4ff33e704cd5493f0a7bc4e2e7;hp=792f23d7e1347558cfdb55d30bc1436ad848ecdf;hpb=fcfc3353eb4053c02f64c80a14ae142d44388a71;p=poolifier.git diff --git a/src/fixed-priority-queue.ts b/src/fixed-priority-queue.ts index 792f23d7..1cc1480a 100644 --- a/src/fixed-priority-queue.ts +++ b/src/fixed-priority-queue.ts @@ -5,7 +5,6 @@ export const defaultQueueSize = 2048 /** * Fixed priority queue node. - * * @typeParam T - Type of priority queue node data. * @internal */ @@ -16,13 +15,12 @@ export interface FixedPriorityQueueNode { /** * Fixed priority queue. - * * @typeParam T - Type of fixed priority queue data. * @internal */ export class FixedPriorityQueue { private start!: number - private readonly nodeArray: Array> + private readonly nodeArray: FixedPriorityQueueNode[] /** The fixed priority queue capacity. */ public readonly capacity: number /** The fixed priority queue size. */ @@ -32,7 +30,6 @@ export class FixedPriorityQueue { /** * Constructs a fixed priority queue. - * * @param size - Fixed priority queue size. @defaultValue defaultQueueSize * @param enablePriority - Whether to enable priority. @defaultValue false * @returns FixedPriorityQueue. @@ -47,7 +44,6 @@ export class FixedPriorityQueue { /** * Checks if the fixed priority queue is empty. - * * @returns `true` if the fixed priority queue is empty, `false` otherwise. */ public empty (): boolean { @@ -56,7 +52,6 @@ export class FixedPriorityQueue { /** * Checks if the fixed priority queue is full. - * * @returns `true` if the fixed priority queue is full, `false` otherwise. */ public full (): boolean { @@ -65,7 +60,6 @@ export class FixedPriorityQueue { /** * Enqueue data into the fixed priority queue. - * * @param data - Data to enqueue. * @param priority - Priority of the data. Lower values have higher priority. * @returns The new size of the priority queue. @@ -82,8 +76,7 @@ export class FixedPriorityQueue { for (let i = 0; i < this.size; i++) { if (this.nodeArray[index].priority > priority) { this.nodeArray.splice(index, 0, { data, priority }) - this.nodeArray.length !== this.capacity && - (this.nodeArray.length = this.capacity) + this.nodeArray.length = this.capacity inserted = true break } @@ -105,7 +98,6 @@ export class FixedPriorityQueue { /** * Gets data from the fixed priority queue. - * * @param index - The index of the data to get. * @returns The data at the index or `undefined` if the fixed priority queue is empty or the index is out of bounds. */ @@ -122,7 +114,6 @@ export class FixedPriorityQueue { /** * Dequeue data from the fixed priority queue. - * * @returns The dequeued data or `undefined` if the priority queue is empty. */ public dequeue (): T | undefined { @@ -148,7 +139,6 @@ export class FixedPriorityQueue { /** * Returns an iterator for the fixed priority queue. - * * @returns An iterator for the fixed priority queue. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols */ @@ -160,7 +150,7 @@ export class FixedPriorityQueue { if (i >= this.size) { return { value: undefined, - done: true + done: true, } } const value = this.nodeArray[index].data @@ -171,25 +161,26 @@ export class FixedPriorityQueue { } return { value, - done: false + done: false, } - } + }, } } /** * Checks the queue size. - * * @param size - Queue size. */ private checkSize (size: number): void { if (!Number.isSafeInteger(size)) { throw new TypeError( - `Invalid fixed priority queue size: '${size}' is not an integer` + `Invalid fixed priority queue size: '${size.toString()}' is not an integer` ) } if (size < 0) { - throw new RangeError(`Invalid fixed priority queue size: ${size} < 0`) + throw new RangeError( + `Invalid fixed priority queue size: ${size.toString()} < 0` + ) } } }