Borrow the rightmost key and child from left sibling, returns new separator
(self, left_sibling: "BranchNode", separator_key: Any)
| 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""" |