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

Method remove_recursive

rust/src/delete_operations.rs:67–107  ·  view source on GitHub ↗
(&mut self, node: &NodeRef<K, V>, key: &K)

Source from the content-addressed store, hash-verified

65 /// Recursively remove a key with proper arena access.
66 #[inline]
67 fn remove_recursive(&mut self, node: &NodeRef<K, V>, key: &K) -> RemoveResult<V> {
68 match node {
69 NodeRef::Leaf(id, _) => {
70 self.get_leaf_mut(*id)
71 .map_or(RemoveResult::Updated(None, false), |leaf| {
72 let (removed_value, is_underfull) = leaf.remove(key);
73 RemoveResult::Updated(removed_value, is_underfull)
74 })
75 }
76 NodeRef::Branch(id, _) => {
77 let id = *id;
78
79 // First get child info without mutable borrow
80 let (child_index, child_ref) = match self.get_child_for_key(id, key) {
81 Some(info) => info,
82 None => return RemoveResult::Updated(None, false),
83 };
84
85 // Recursively remove
86 let child_result = self.remove_recursive(&child_ref, key);
87
88 // Handle the result
89 match child_result {
90 RemoveResult::Updated(removed_value, child_became_underfull) => {
91 // If child became underfull, try to rebalance
92 if removed_value.is_some() && child_became_underfull {
93 let _child_still_exists = self.rebalance_child(id, child_index);
94 }
95
96 // Only compute underfull if a removal actually happened
97 let is_underfull = if removed_value.is_some() {
98 self.is_node_underfull(&NodeRef::Branch(id, PhantomData))
99 } else {
100 false
101 };
102 RemoveResult::Updated(removed_value, is_underfull)
103 }
104 }
105 }
106 }
107 }
108
109 /// Collapse the root if it's a branch with only one child or no children.
110 fn collapse_root_if_needed(&mut self) {

Callers 1

removeMethod · 0.80

Calls 5

get_leaf_mutMethod · 0.80
get_child_for_keyMethod · 0.80
rebalance_childMethod · 0.80
is_node_underfullMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected