MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / update_item

Method update_item

data_structures/heap/heap_generic.py:79–88  ·  view source on GitHub ↗

Updates given item value in heap if present

(self, item: int, item_value: int)

Source from the content-addressed store, hash-verified

77 index, valid_parent = valid_parent, self._get_valid_parent(valid_parent)
78
79 def update_item(self, item: int, item_value: int) -> None:
80 """Updates given item value in heap if present"""
81 if item not in self.pos_map:
82 return
83 index = self.pos_map[item]
84 self.arr[index] = [item, self.key(item_value)]
85 # Make sure heap is right in both up and down direction.
86 # Ideally only one of them will make any change.
87 self._heapify_up(index)
88 self._heapify_down(index)
89
90 def delete_item(self, item: int) -> None:
91 """Deletes given item from heap if present"""

Callers

nothing calls this directly

Calls 2

_heapify_upMethod · 0.95
_heapify_downMethod · 0.95

Tested by

no test coverage detected