1 import { AbstractFixedQueue
} from
'./abstract-fixed-queue.js'
2 import type { IFixedQueue
} from
'./utility-types.js'
5 * Fixed priority queue.
6 * @typeParam T - Type of fixed priority queue data.
9 export class FixedPriorityQueue
<T
>
10 extends AbstractFixedQueue
<T
>
11 implements IFixedQueue
<T
> {
13 public enqueue (data
: T
, priority
?: number): number {
15 throw new Error('Fixed priority queue is full')
17 priority
= priority
?? 0
19 let index
= this.start
20 for (let i
= 0; i
< this.size
; i
++) {
21 if (this.nodeArray
[index
].priority
> priority
) {
22 this.nodeArray
.splice(index
, 0, { data
, priority
})
23 this.nodeArray
.length
= this.capacity
28 if (index
=== this.capacity
) {
33 let index
= this.start
+ this.size
34 if (index
>= this.capacity
) {
35 index
-= this.capacity
37 this.nodeArray
[index
] = { data
, priority
}