@@ -13,19 +13,16 @@ export default class FlatQueue {
1313 this . length = 0 ;
1414 }
1515
16- /**
17- * Removes all items from the queue.
18- */
16+ /** Removes all items from the queue. */
1917 clear ( ) {
2018 this . length = 0 ;
2119 }
2220
2321 /**
2422 * Adds `item` to the queue with the specified `priority`.
2523 *
26- * `priority` must be a number. Items are sorted and returned from low to
27- * high priority. Multiple items with the same priority value can be added
28- * to the queue, but there is no guaranteed order between these items.
24+ * `priority` must be a number. Items are sorted and returned from low to high priority. Multiple items
25+ * with the same priority value can be added to the queue, but there is no guaranteed order between these items.
2926 *
3027 * @param {T } item
3128 * @param {number } priority
@@ -48,8 +45,7 @@ export default class FlatQueue {
4845
4946 /**
5047 * Removes and returns the item from the head of this queue, which is one of
51- * the items with the lowest priority. If this queue is empty, returns
52- * `undefined`.
48+ * the items with the lowest priority. If this queue is empty, returns `undefined`.
5349 */
5450 pop ( ) {
5551 if ( this . length === 0 ) return undefined ;
@@ -82,31 +78,25 @@ export default class FlatQueue {
8278 return top ;
8379 }
8480
85- /**
86- * Returns the item from the head of this queue without removing it. If this
87- * queue is empty, returns `undefined`.
88- */
81+ /** Returns the item from the head of this queue without removing it. If this queue is empty, returns `undefined`. */
8982 peek ( ) {
90- if ( this . length === 0 ) return undefined ;
91- return this . ids [ 0 ] ;
83+ return this . length > 0 ? this . ids [ 0 ] : undefined ;
9284 }
9385
9486 /**
9587 * Returns the priority value of the item at the head of this queue without
9688 * removing it. If this queue is empty, returns `undefined`.
9789 */
9890 peekValue ( ) {
99- if ( this . length === 0 ) return undefined ;
100- return this . values [ 0 ] ;
91+ return this . length > 0 ? this . values [ 0 ] : undefined ;
10192 }
10293
10394 /**
10495 * Shrinks the internal arrays to `this.length`.
10596 *
106- * `pop()` and `clear()` calls don't free memory automatically to avoid
107- * unnecessary resize operations. This also means that items that have been
108- * added to the queue can't be garbage collected until a new item is pushed
109- * in their place, or this method is called.
97+ * `pop()` and `clear()` calls don't free memory automatically to avoid unnecessary resize operations.
98+ * This also means that items that have been added to the queue can't be garbage collected until
99+ * a new item is pushed in their place, or this method is called.
110100 */
111101 shrink ( ) {
112102 this . ids . length = this . values . length = this . length ;
0 commit comments