Recursively insert a key-value pair into the tree. Returns None for a simple insertion, or (new_node, separator_key) if a split occurred.
(
self, node: "Node", key: Any, value: Any
)
| 157 | self.root = new_root |
| 158 | |
| 159 | def _insert_recursive( |
| 160 | self, node: "Node", key: Any, value: Any |
| 161 | ) -> Optional[Tuple["Node", Any]]: |
| 162 | """ |
| 163 | Recursively insert a key-value pair into the tree. |
| 164 | Returns None for a simple insertion, or (new_node, separator_key) if a split occurred. |
| 165 | """ |
| 166 | if node.is_leaf(): |
| 167 | # Base case: insert into leaf |
| 168 | return self._insert_into_leaf(node, key, value) |
| 169 | |
| 170 | child_index = node.find_child_index(key) |
| 171 | child = node.children[child_index] |
| 172 | |
| 173 | split_result = self._insert_recursive(child, key, value) |
| 174 | if split_result is None: |
| 175 | return None |
| 176 | |
| 177 | new_child, separator_key = split_result |
| 178 | return self._insert_into_branch(node, child_index, separator_key, new_child) |
| 179 | |
| 180 | def _insert_into_leaf( |
| 181 | self, leaf: "LeafNode", key: Any, value: Any |
no test coverage detected