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

Method remove

rust/src/delete_operations.rs:44–57  ·  view source on GitHub ↗

Remove a key from the tree and return its associated value. # Arguments `key` - The key to remove from the tree # Returns `Some(value)` - The value that was associated with the key `None` - If the key was not present in the tree # Examples ``` use bplustree::BPlusTreeMap; let mut tree = BPlusTreeMap::new(4).unwrap(); tree.insert(1, "one"); tree.insert(2, "two"); assert_eq!(tree.remove(&1), So

(&mut self, key: &K)

Source from the content-addressed store, hash-verified

42 /// # Panics
43 /// Never panics - all operations are memory safe
44 pub fn remove(&mut self, key: &K) -> Option<V> {
45 // Use remove_recursive to handle the removal
46 let result = self.remove_recursive(&self.root.clone(), key);
47
48 match result {
49 RemoveResult::Updated(removed_value, _root_became_underfull) => {
50 // Check if root needs collapsing after removal
51 if removed_value.is_some() {
52 self.collapse_root_if_needed();
53 }
54 removed_value
55 }
56 }
57 }
58
59 /// Remove a key from the tree, returning an error if the key doesn't exist.
60 /// This is equivalent to Python's `del tree[key]`.

Calls 3

remove_recursiveMethod · 0.80
cloneMethod · 0.80