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

Method reinsert_change

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

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