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

Method reinsert_change

atomic-core/src/pristine/txn/write/mod.rs:1155–1264  ·  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

1153 }
1154
1155 fn reinsert_change(
1156 &mut self,
1157 view: &mut ViewState,
1158 change_id: NodeId,
1159 change_hash: &Hash,
1160 at_sequence: u64,
1161 ) -> PristineResult<()> {
1162 // Clamp sequence to valid range
1163 let insert_at = at_sequence.min(view.change_count);
1164
1165 // Shift all changes from insert_at onwards up by 1
1166 // Work backwards to avoid overwriting
1167 for s in (insert_at..view.change_count).rev() {
1168 // Get the change_id at this sequence
1169 let cid = {
1170 let table = self.txn.open_table(VIEW_CHANGES)?;
1171 let key = encode_view_seq(view.id, s);
1172 let result = table.get(&key)?;
1173 match result {
1174 Some(v) => {
1175 let id = NodeId::new(v.value());
1176 drop(v);
1177 id
1178 }
1179 None => continue,
1180 }
1181 };
1182
1183 // Remove old entry
1184 {
1185 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1186 let key = encode_view_seq(view.id, s);
1187 table.remove(&key)?;
1188 }
1189
1190 // Insert at new sequence (s + 1)
1191 {
1192 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1193 let key = encode_view_seq(view.id, s + 1);
1194 table.insert(&key, cid.get())?;
1195 }
1196
1197 // Update reverse mapping
1198 {
1199 let mut table = self.txn.open_table(REV_VIEW_CHANGES)?;
1200 let key = encode_view_seq(view.id, cid.get());
1201 table.insert(&key, s + 1)?;
1202 }
1203 }
1204
1205 // Insert the new change at the specified position
1206 {
1207 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1208 let key = encode_view_seq(view.id, insert_at);
1209 table.insert(&key, change_id.get())?;
1210 }
1211
1212 // 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