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

Method borrow_from_left

python/bplustree/bplus_tree.py:862–875  ·  view source on GitHub ↗

Borrow the rightmost key and child from left sibling, returns new separator

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

Source from the content-addressed store, hash-verified

860 return len(self.keys) > min_keys
861
862 def borrow_from_left(self, left_sibling: "BranchNode", separator_key: Any) -> Any:
863 """Borrow the rightmost key and child from left sibling, returns new separator"""
864 if not left_sibling.can_donate():
865 raise ValueError("Left sibling cannot donate")
866
867 # Take the separator key as our leftmost key
868 self.keys.insert(0, separator_key)
869
870 # Take the rightmost child from left sibling
871 child = left_sibling.children.pop()
872 self.children.insert(0, child)
873
874 # The rightmost key from left sibling becomes the new separator
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"""

Callers 1

Calls 3

can_donateMethod · 0.45
insertMethod · 0.45
popMethod · 0.45

Tested by 1