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