(heap: Heap<T>)
| 25 | } |
| 26 | |
| 27 | export function pop<T: Node>(heap: Heap<T>): T | null { |
| 28 | if (heap.length === 0) { |
| 29 | return null; |
| 30 | } |
| 31 | const first = heap[0]; |
| 32 | const last = heap.pop(); |
| 33 | if (last !== first) { |
| 34 | // $FlowFixMe[incompatible-type] |
| 35 | heap[0] = last; |
| 36 | // $FlowFixMe[incompatible-call] |
| 37 | siftDown(heap, last, 0); |
| 38 | } |
| 39 | return first; |
| 40 | } |
| 41 | |
| 42 | function siftUp<T: Node>(heap: Heap<T>, node: T, i: number): void { |
| 43 | let index = i; |
no test coverage detected