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

Method batch_insert

rust/src/lib.rs:97–122  ·  view source on GitHub ↗

Batch insert operations with rollback on any failure

(&mut self, items: Vec<(K, V)>)

Source from the content-addressed store, hash-verified

95
96 /// Batch insert operations with rollback on any failure
97 pub fn batch_insert(&mut self, items: Vec<(K, V)>) -> ModifyResult<Vec<Option<V>>>
98 where
99 K: Clone,
100 V: Clone,
101 {
102 let mut results = Vec::new();
103 let mut inserted_keys = Vec::new();
104
105 for (key, value) in items {
106 match self.try_insert(key.clone(), value) {
107 Ok(old_value) => {
108 results.push(old_value);
109 inserted_keys.push(key);
110 }
111 Err(e) => {
112 // Rollback all successful insertions
113 for rollback_key in inserted_keys {
114 self.remove(&rollback_key);
115 }
116 return Err(e);
117 }
118 }
119 }
120
121 Ok(results)
122 }
123
124 // get_many method moved to get_operations.rs module
125

Callers 3

test_batch_insertFunction · 0.80
test_batch_insertFunction · 0.80

Calls 3

try_insertMethod · 0.80
cloneMethod · 0.80
removeMethod · 0.45

Tested by 3

test_batch_insertFunction · 0.64
test_batch_insertFunction · 0.64