(heap: Array<MinHeapEntry>)
| 4018 | } |
| 4019 | |
| 4020 | const minHeapPop = (heap: Array<MinHeapEntry>): MinHeapEntry | undefined => { |
| 4021 | const first = heap[0] |
| 4022 | const last = heap.pop() |
| 4023 | if (last === undefined || heap.length === 0) { |
| 4024 | return first |
| 4025 | } |
| 4026 | let index = 0 |
| 4027 | while (true) { |
| 4028 | const left = index * 2 + 1 |
| 4029 | if (left >= heap.length) { |
| 4030 | break |
| 4031 | } |
| 4032 | const right = left + 1 |
| 4033 | const child = right < heap.length && minHeapLessThan(heap[right], heap[left]) ? right : left |
| 4034 | if (!minHeapLessThan(heap[child], last)) { |
| 4035 | break |
| 4036 | } |
| 4037 | heap[index] = heap[child] |
| 4038 | index = child |
| 4039 | } |
| 4040 | heap[index] = last |
| 4041 | return first |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * Configuration for finding a shortest path with Dijkstra's algorithm. |
no test coverage detected