(index: number)
| 34 | } |
| 35 | |
| 36 | private siftDown(index: number): void { |
| 37 | while (true) { |
| 38 | let minIndex = index |
| 39 | const leftChild = this.getLeftChildIndex(index) |
| 40 | const rightChild = this.getRightChildIndex(index) |
| 41 | |
| 42 | if ( |
| 43 | leftChild < this.heap.length && |
| 44 | this.heap[leftChild].score < this.heap[minIndex].score |
| 45 | ) { |
| 46 | minIndex = leftChild |
| 47 | } |
| 48 | |
| 49 | if ( |
| 50 | rightChild < this.heap.length && |
| 51 | this.heap[rightChild].score < this.heap[minIndex].score |
| 52 | ) { |
| 53 | minIndex = rightChild |
| 54 | } |
| 55 | |
| 56 | if (minIndex === index) { |
| 57 | break |
| 58 | } |
| 59 | |
| 60 | this.swap(index, minIndex) |
| 61 | index = minIndex |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | insert(item: T, score: number): void { |
| 66 | this.heap.push({ item, score }) |
no test coverage detected