@@ -10,16 +10,22 @@ import type { IFixedQueue } from './queue-types.ts'
1010export class FixedPriorityQueue < T > extends AbstractFixedQueue < T >
1111 implements IFixedQueue < T > {
1212 private readonly agingFactor : number
13+ private readonly loadExponent : number
1314
1415 /**
1516 * Constructs a FixedPriorityQueue.
1617 * @param size - Fixed queue size. @defaultValue defaultQueueSize
1718 * @param agingFactor - Aging factor to apply to items in priority points per millisecond. A higher value makes items age faster.
1819 * @returns IFixedQueue.
1920 */
20- public constructor ( size ?: number , agingFactor = 0.001 ) {
21+ public constructor (
22+ size ?: number ,
23+ agingFactor = 0.001 ,
24+ loadExponent = 1.0 / 1.5 ,
25+ ) {
2126 super ( size )
2227 this . agingFactor = agingFactor
28+ this . loadExponent = loadExponent
2329 }
2430
2531 /** @inheritdoc */
@@ -29,12 +35,14 @@ export class FixedPriorityQueue<T> extends AbstractFixedQueue<T>
2935 }
3036 priority = priority ?? 0
3137 const now = performance . now ( )
38+ const effectiveAgingFactor = this . agingFactor *
39+ ( 1 + ( ( this . size + 1 ) / this . capacity ) ** this . loadExponent )
3240 let insertionPhysicalIndex = - 1
3341 let currentPhysicalIndex = this . start
3442 for ( let i = 0 ; i < this . size ; i ++ ) {
3543 const node = this . nodeArray [ currentPhysicalIndex ] !
3644 const nodeEffectivePriority = node . priority -
37- ( now - node . timestamp ) * this . agingFactor
45+ ( now - node . timestamp ) * effectiveAgingFactor
3846 if ( nodeEffectivePriority > priority ) {
3947 insertionPhysicalIndex = currentPhysicalIndex
4048 break
0 commit comments