(self, val, index, heap, position)
| 40 | |
| 41 | # Update function if value of any node in min-heap decreases |
| 42 | def bottom_to_top(self, val, index, heap, position): |
| 43 | temp = position[index] |
| 44 | |
| 45 | while index != 0: |
| 46 | parent = int((index - 2) / 2) if index % 2 == 0 else int((index - 1) / 2) |
| 47 | |
| 48 | if val < heap[parent]: |
| 49 | heap[index] = heap[parent] |
| 50 | position[index] = position[parent] |
| 51 | self.set_position(position[parent], index) |
| 52 | else: |
| 53 | heap[index] = val |
| 54 | position[index] = temp |
| 55 | self.set_position(temp, index) |
| 56 | break |
| 57 | index = parent |
| 58 | else: |
| 59 | heap[0] = val |
| 60 | position[0] = temp |
| 61 | self.set_position(temp, 0) |
| 62 | |
| 63 | def heapify(self, heap, positions): |
| 64 | start = len(heap) // 2 - 1 |
no test coverage detected