We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 38c728f commit 1f551a4Copy full SHA for 1f551a4
1 file changed
index.js
@@ -54,18 +54,16 @@ export default class TinyQueue {
54
const item = data[pos];
55
56
while (pos < halfLength) {
57
- let left = (pos << 1) + 1;
58
- let best = data[left];
59
- const right = left + 1;
+ let bestChild = (pos << 1) + 1; // initially it is the left child
+ const right = bestChild + 1;
60
61
- if (right < this.length && compare(data[right], best) < 0) {
62
- left = right;
63
- best = data[right];
+ if (right < this.length && compare(data[right], data[bestChild]) < 0) {
+ bestChild = right;
64
}
65
- if (compare(best, item) >= 0) break;
+ if (compare(data[bestChild], item) >= 0) break;
66
67
- data[pos] = best;
68
- pos = left;
+ data[pos] = data[bestChild];
+ pos = bestChild;
69
70
71
data[pos] = item;
0 commit comments