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

Method try_insert

rust/src/lib.rs:59–77  ·  view source on GitHub ↗

Get a reference to the value associated with a key. # Arguments `key` - The key to look up Insert with comprehensive error handling and rollback on failure

(&mut self, key: K, value: V)

Source from the content-addressed store, hash-verified

57 ///
58 /// Insert with comprehensive error handling and rollback on failure
59 pub fn try_insert(&mut self, key: K, value: V) -> ModifyResult<Option<V>>
60 where
61 K: Clone,
62 V: Clone,
63 {
64 // Validate tree state before insertion
65 if let Err(e) = self.check_invariants_detailed() {
66 return Err(BPlusTreeError::DataIntegrityError(e));
67 }
68
69 let old_value = self.insert(key, value);
70
71 // Validate tree state after insertion
72 if let Err(e) = self.check_invariants_detailed() {
73 return Err(BPlusTreeError::DataIntegrityError(e));
74 }
75
76 Ok(old_value)
77 }
78
79 /// Remove with comprehensive error handling
80 pub fn try_remove(&mut self, key: &K) -> ModifyResult<V> {

Calls 2

insertMethod · 0.45