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

Method borrow_from_right

python/bplustree/bplus_tree.py:877–890  ·  view source on GitHub ↗

Borrow the leftmost key and child from right sibling, returns new separator

(self, right_sibling: "BranchNode", separator_key: Any)

Source from the content-addressed store, hash-verified

875 return left_sibling.keys.pop()
876
877 def borrow_from_right(self, right_sibling: "BranchNode", separator_key: Any) -> Any:
878 """Borrow the leftmost key and child from right sibling, returns new separator"""
879 if not right_sibling.can_donate():
880 raise ValueError("Right sibling cannot donate")
881
882 # Take the separator key as our rightmost key
883 self.keys.append(separator_key)
884
885 # Take the leftmost child from right sibling
886 child = right_sibling.children.pop(0)
887 self.children.append(child)
888
889 # The leftmost key from right sibling becomes the new separator
890 return right_sibling.keys.pop(0)
891
892 def merge_with_right(self, right_sibling: "BranchNode", separator_key: Any) -> None:
893 """Merge this branch with its right sibling using the separator key"""

Callers 1

Calls 2

can_donateMethod · 0.45
popMethod · 0.45

Tested by 1