(pos)
| 36 | } |
| 37 | |
| 38 | percolateDown(pos) { |
| 39 | const compare = this.#compare; |
| 40 | const setPosition = this.#setPosition; |
| 41 | const hasSetPosition = setPosition !== undefined; |
| 42 | const heap = this.#heap; |
| 43 | const size = this.#size; |
| 44 | const hsize = size >> 1; |
| 45 | const item = heap[pos]; |
| 46 | |
| 47 | while (pos <= hsize) { |
| 48 | let child = pos << 1; |
| 49 | const nextChild = child + 1; |
| 50 | let childItem = heap[child]; |
| 51 | |
| 52 | if (nextChild <= size && compare(heap[nextChild], childItem) < 0) { |
| 53 | child = nextChild; |
| 54 | childItem = heap[nextChild]; |
| 55 | } |
| 56 | |
| 57 | if (compare(item, childItem) <= 0) break; |
| 58 | |
| 59 | if (hasSetPosition) |
| 60 | setPosition(childItem, pos); |
| 61 | |
| 62 | heap[pos] = childItem; |
| 63 | pos = child; |
| 64 | } |
| 65 | |
| 66 | heap[pos] = item; |
| 67 | if (hasSetPosition) |
| 68 | setPosition(item, pos); |
| 69 | } |
| 70 | |
| 71 | percolateUp(pos) { |
| 72 | const heap = this.#heap; |
no test coverage detected