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

Method new_root

rust/src/insert_operations.rs:15–28  ·  view source on GitHub ↗

Create a new root node when the current root splits. New roots are the only BranchNodes allowed to remain underfull.

(&mut self, new_node: NodeRef<K, V>, separator_key: K)

Source from the content-addressed store, hash-verified

13 /// Create a new root node when the current root splits.
14 /// New roots are the only BranchNodes allowed to remain underfull.
15 pub fn new_root(&mut self, new_node: NodeRef<K, V>, separator_key: K) -> BranchNode<K, V> {
16 let mut new_root = BranchNode::new(self.capacity);
17 new_root.keys.push(separator_key);
18
19 // Move the current root to be the left child
20 // Use a dummy NodeRef with NULL_NODE to avoid arena allocation
21 let dummy = NodeRef::Leaf(crate::types::NULL_NODE, PhantomData);
22 let old_root = std::mem::replace(&mut self.root, dummy);
23
24 new_root.children.push(old_root);
25 new_root.children.push(new_node);
26
27 new_root
28 }
29
30 /// Insert into a leaf node by ID.
31 fn insert_into_leaf(&mut self, leaf_id: NodeId, key: K, value: V) -> InsertResult<K, V> {

Callers 1

insertMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected