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

Method _rotate_right

algorithms/data_structures/b_tree.py:243–257  ·  view source on GitHub ↗

Take a key from the left 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

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.
245
246 Args:
247 parent_node: The parent node.
248 child_index: The index of the child receiving the key.
249 """
250 parent_key = parent_node.keys[child_index - 1]
251 new_parent_key = parent_node.children[child_index - 1].keys.pop()
252 parent_node.children[child_index].keys.insert(0, parent_key)
253 parent_node.keys[child_index - 1] = new_parent_key
254
255 if not parent_node.children[child_index - 1].is_leaf:
256 ownerless_child = parent_node.children[child_index - 1].children.pop()
257 parent_node.children[child_index].children.insert(0, ownerless_child)
258
259 def _merge(
260 self, parent_node: Node, to_merge_index: int, transferred_child_index: int

Callers 1

_repair_treeMethod · 0.95

Calls 2

popMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected