Insert into a leaf node. Returns None or (new_leaf, separator) if split.
(
self, leaf: "LeafNode", key: Any, value: Any
)
| 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 |
| 182 | ) -> Optional[Tuple["LeafNode", Any]]: |
| 183 | """Insert into a leaf node. Returns None or (new_leaf, separator) if split.""" |
| 184 | pos, exists = leaf.find_position(key) |
| 185 | |
| 186 | # If key exists, just update (no split needed) |
| 187 | if exists: |
| 188 | leaf.values[pos] = value |
| 189 | return None |
| 190 | |
| 191 | # If leaf is not full, simple insertion |
| 192 | if not leaf.is_full(): |
| 193 | leaf.insert(key, value) |
| 194 | return None |
| 195 | |
| 196 | # Leaf is full, need to split |
| 197 | return leaf.split_and_insert(key, value) |
| 198 | |
| 199 | def _insert_into_branch( |
| 200 | self, |
no test coverage detected