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)
| 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> { |