MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / reinsert_change

Method reinsert_change

atomic-core/src/pristine/txn/write/mod.rs:1250–1359  ·  view source on GitHub ↗
(
        &mut self,
        view: &mut ViewState,
        change_id: NodeId,
        change_hash: &Hash,
        at_sequence: u64,
    )

Source from the content-addressed store, hash-verified

1248 }
1249
1250 fn reinsert_change(
1251 &mut self,
1252 view: &mut ViewState,
1253 change_id: NodeId,
1254 change_hash: &Hash,
1255 at_sequence: u64,
1256 ) -> PristineResult<()> {
1257 // Clamp sequence to valid range
1258 let insert_at = at_sequence.min(view.change_count);
1259
1260 // Shift all changes from insert_at onwards up by 1
1261 // Work backwards to avoid overwriting
1262 for s in (insert_at..view.change_count).rev() {
1263 // Get the change_id at this sequence
1264 let cid = {
1265 let table = self.txn.open_table(VIEW_CHANGES)?;
1266 let key = encode_view_seq(view.id, s);
1267 let result = table.get(&key)?;
1268 match result {
1269 Some(v) => {
1270 let id = NodeId::new(v.value());
1271 drop(v);
1272 id
1273 }
1274 None => continue,
1275 }
1276 };
1277
1278 // Remove old entry
1279 {
1280 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1281 let key = encode_view_seq(view.id, s);
1282 table.remove(&key)?;
1283 }
1284
1285 // Insert at new sequence (s + 1)
1286 {
1287 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1288 let key = encode_view_seq(view.id, s + 1);
1289 table.insert(&key, cid.get())?;
1290 }
1291
1292 // Update reverse mapping
1293 {
1294 let mut table = self.txn.open_table(REV_VIEW_CHANGES)?;
1295 let key = encode_view_seq(view.id, cid.get());
1296 table.insert(&key, s + 1)?;
1297 }
1298 }
1299
1300 // Insert the new change at the specified position
1301 {
1302 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1303 let key = encode_view_seq(view.id, insert_at);
1304 table.insert(&key, change_id.get())?;
1305 }
1306
1307 // Add reverse mapping

Callers 5

execute_reviseMethod · 0.45
execute_rewordMethod · 0.45
test_reinsert_changeFunction · 0.45

Calls 8

encode_view_seqFunction · 0.85
encode_view_merkleFunction · 0.85
getMethod · 0.65
removeMethod · 0.65
insertMethod · 0.45
get_externalMethod · 0.45
nextMethod · 0.45
as_bytesMethod · 0.45

Tested by 3

test_reinsert_changeFunction · 0.36