MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / _redistribute_from_right

Method _redistribute_from_right

python/bplustree/bplus_tree.py:341–355  ·  view source on GitHub ↗

Redistribute keys from right sibling to child

(self, parent: "BranchNode", child_index: int)

Source from the content-addressed store, hash-verified

339 parent.keys[child_index - 1] = new_separator
340
341 def _redistribute_from_right(self, parent: "BranchNode", child_index: int) -> None:
342 """Redistribute keys from right sibling to child"""
343 child = parent.children[child_index]
344 right_sibling = parent.children[child_index + 1]
345
346 if child.is_leaf():
347 # Leaf redistribution
348 child.borrow_from_right(right_sibling)
349 # Update separator key in parent
350 parent.keys[child_index] = right_sibling.keys[0]
351 else:
352 # Branch redistribution
353 separator_key = parent.keys[child_index]
354 new_separator = child.borrow_from_right(right_sibling, separator_key)
355 parent.keys[child_index] = new_separator
356
357 def _merge_with_sibling(self, parent: "BranchNode", child_index: int) -> None:
358 """Merge an underfull child with one of its siblings"""

Callers 1

_handle_underflowMethod · 0.95

Calls 2

is_leafMethod · 0.45
borrow_from_rightMethod · 0.45

Tested by

no test coverage detected