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

Method _insert_into_leaf

python/bplustree/bplus_tree.py:180–197  ·  view source on GitHub ↗

Insert into a leaf node. Returns None or (new_leaf, separator) if split.

(
        self, leaf: "LeafNode", key: Any, value: Any
    )

Source from the content-addressed store, hash-verified

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,

Callers 1

_insert_recursiveMethod · 0.95

Calls 4

split_and_insertMethod · 0.80
find_positionMethod · 0.45
is_fullMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected