11// Based on: https://github.com/mourner/flatqueue/blob/main/index.js
22// Could not use the original package because it doesn't support CommonJs.
33export class FlatQueue < GItem > {
4- private ids : Array < GItem | undefined > ;
5- private values : Array < number > ;
4+ private _ids : Array < GItem | undefined > ;
5+ private _values : Array < number > ;
66 private _length : number ;
77
88 constructor ( ) {
9- this . ids = [ ] ;
10- this . values = [ ] ;
9+ this . _ids = [ ] ;
10+ this . _values = [ ] ;
1111 this . _length = 0 ;
1212 }
1313
@@ -30,17 +30,17 @@ export class FlatQueue<GItem> {
3030
3131 while ( pos > 0 ) {
3232 const parent = ( pos - 1 ) >> 1 ;
33- const parentValue = this . values [ parent ] as number ;
33+ const parentValue = this . _values [ parent ] as number ;
3434 if ( priority >= parentValue ) {
3535 break ;
3636 }
37- this . ids [ pos ] = this . ids [ parent ] ;
38- this . values [ pos ] = parentValue ;
37+ this . _ids [ pos ] = this . _ids [ parent ] ;
38+ this . _values [ pos ] = parentValue ;
3939 pos = parent ;
4040 }
4141
42- this . ids [ pos ] = id ;
43- this . values [ pos ] = priority ;
42+ this . _ids [ pos ] = id ;
43+ this . _values [ pos ] = priority ;
4444 }
4545
4646 /**
@@ -53,14 +53,14 @@ export class FlatQueue<GItem> {
5353 return null ;
5454 }
5555
56- const top = this . ids [ 0 ] ;
56+ const top = this . _ids [ 0 ] ;
5757 this . _length -- ;
5858
5959 if ( this . _length > 0 ) {
60- const id = this . ids [ this . _length ] as GItem ;
61- const value = this . values [ this . _length ] as number ;
62- this . ids [ 0 ] = id ;
63- this . values [ 0 ] = value ;
60+ const id = this . _ids [ this . _length ] as GItem ;
61+ const value = this . _values [ this . _length ] as number ;
62+ this . _ids [ 0 ] = id ;
63+ this . _values [ 0 ] = value ;
6464
6565 const halfLength = this . _length >> 1 ;
6666 let pos = 0 ;
@@ -70,15 +70,15 @@ export class FlatQueue<GItem> {
7070 const right = left + 1 ;
7171
7272 // Initialize with left child values
73- let bestIndex = this . ids [ left ] as GItem ;
74- let bestValue = this . values [ left ] as number ;
73+ let bestIndex = this . _ids [ left ] as GItem ;
74+ let bestValue = this . _values [ left ] as number ;
7575
7676 // Check if right child exists and has lower priority
77- const rightValue = this . values [ right ] as number ;
77+ const rightValue = this . _values [ right ] as number ;
7878
7979 if ( right < this . _length && rightValue < bestValue ) {
8080 left = right ;
81- bestIndex = this . ids [ right ] as GItem ;
81+ bestIndex = this . _ids [ right ] as GItem ;
8282 bestValue = rightValue ;
8383 }
8484
@@ -88,14 +88,14 @@ export class FlatQueue<GItem> {
8888 }
8989
9090 // Move best child up
91- this . ids [ pos ] = bestIndex ;
92- this . values [ pos ] = bestValue ;
91+ this . _ids [ pos ] = bestIndex ;
92+ this . _values [ pos ] = bestValue ;
9393 pos = left ;
9494 }
9595
9696 // Place the current item at its new position
97- this . ids [ pos ] = id ;
98- this . values [ pos ] = value ;
97+ this . _ids [ pos ] = id ;
98+ this . _values [ pos ] = value ;
9999 }
100100
101101 return top ?? null ;
0 commit comments