Skip to content

Commit f244049

Browse files
Reducing code complexity
1 parent d168bf0 commit f244049

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/data_structures/priority_queue.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ class PriorityQueue {
5555
*/
5656
_fixBottomHeap(idx) {
5757
let changeIdx = idx;
58-
let childIdx = idx * 2 + 1;
59-
let rightChildIdx = idx * 2 + 2;
60-
while (childIdx <= rightChildIdx) {
61-
if (childIdx < this._size && this.comparison(
58+
let maxChildIdx = Math.min(idx*2 + 2, this._size - 1);
59+
for (let childIdx = idx*2 + 1; childIdx <= maxChildIdx; childIdx++) {
60+
if (this.comparison(
6261
this._priorityHeap[childIdx], this._priorityHeap[changeIdx])) {
6362
changeIdx = childIdx;
6463
}
65-
childIdx++;
6664
}
6765

6866
if (changeIdx != idx) {

0 commit comments

Comments
 (0)