(pos)
| 69 | } |
| 70 | |
| 71 | percolateUp(pos) { |
| 72 | const heap = this.#heap; |
| 73 | const compare = this.#compare; |
| 74 | const setPosition = this.#setPosition; |
| 75 | const hasSetPosition = setPosition !== undefined; |
| 76 | const item = heap[pos]; |
| 77 | |
| 78 | while (pos > 1) { |
| 79 | const parent = pos >> 1; |
| 80 | const parentItem = heap[parent]; |
| 81 | if (compare(parentItem, item) <= 0) |
| 82 | break; |
| 83 | heap[pos] = parentItem; |
| 84 | if (hasSetPosition) |
| 85 | setPosition(parentItem, pos); |
| 86 | pos = parent; |
| 87 | } |
| 88 | |
| 89 | heap[pos] = item; |
| 90 | if (hasSetPosition) |
| 91 | setPosition(item, pos); |
| 92 | } |
| 93 | |
| 94 | removeAt(pos) { |
| 95 | const heap = this.#heap; |
no test coverage detected