MCPcopy
hub / github.com/keon/algorithms / _rotate_left

Method _rotate_left

algorithms/data_structures/b_tree.py:227–241  ·  view source on GitHub ↗

Take a key from the right sibling and transfer it to the child. Args: parent_node: The parent node. child_index: The index of the child receiving the key.

(self, parent_node: Node, child_index: int)

Source from the content-addressed store, hash-verified

225 return True
226
227 def _rotate_left(self, parent_node: Node, child_index: int) -> None:
228 """Take a key from the right sibling and transfer it to the child.
229
230 Args:
231 parent_node: The parent node.
232 child_index: The index of the child receiving the key.
233 """
234 new_child_key = parent_node.keys[child_index]
235 new_parent_key = parent_node.children[child_index + 1].keys.pop(0)
236 parent_node.children[child_index].keys.append(new_child_key)
237 parent_node.keys[child_index] = new_parent_key
238
239 if not parent_node.children[child_index + 1].is_leaf:
240 ownerless_child = parent_node.children[child_index + 1].children.pop(0)
241 parent_node.children[child_index].children.append(ownerless_child)
242
243 def _rotate_right(self, parent_node: Node, child_index: int) -> None:
244 """Take a key from the left sibling and transfer it to the child.

Callers 1

_repair_treeMethod · 0.95

Calls 1

popMethod · 0.45

Tested by

no test coverage detected