(self, elem: T, weight: int)
| 118 | return elem |
| 119 | |
| 120 | def update_key(self, elem: T, weight: int) -> None: |
| 121 | # Update the weight of the given key |
| 122 | position = self.position_map[elem] |
| 123 | self.heap[position] = (elem, weight) |
| 124 | if position > 0: |
| 125 | parent_position = get_parent_position(position) |
| 126 | _, parent_weight = self.heap[parent_position] |
| 127 | if parent_weight > weight: |
| 128 | self._bubble_up(elem) |
| 129 | else: |
| 130 | self._bubble_down(elem) |
| 131 | else: |
| 132 | self._bubble_down(elem) |
| 133 | |
| 134 | def _bubble_up(self, elem: T) -> None: |
| 135 | # Place a node at the proper position (upward movement) [to be used internally |
no test coverage detected