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

Method _insert_recursive

python/bplustree/bplus_tree.py:159–178  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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

Callers 1

__setitem__Method · 0.95

Calls 4

_insert_into_leafMethod · 0.95
_insert_into_branchMethod · 0.95
is_leafMethod · 0.45
find_child_indexMethod · 0.45

Tested by

no test coverage detected