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

Method reinsert_change

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

680 }
681
682 fn reinsert_change(
683 &mut self,
684 view: &mut ViewState,
685 change_id: NodeId,
686 change_hash: &Hash,
687 at_sequence: u64,
688 ) -> PristineResult<()> {
689 // Clamp sequence to valid range
690 let insert_at = at_sequence.min(view.change_count);
691
692 // Shift all changes from insert_at onwards up by 1
693 // Work backwards to avoid overwriting
694 for s in (insert_at..view.change_count).rev() {
695 // Get the change_id at this sequence
696 let cid = {
697 let table = self.txn.open_table(VIEW_CHANGES)?;
698 let key = encode_view_seq(view.id, s);
699 let result = table.get(&key)?;
700 match result {
701 Some(v) => {
702 let id = NodeId::new(v.value());
703 drop(v);
704 id
705 }
706 None => continue,
707 }
708 };
709
710 // Remove old entry
711 {
712 let mut table = self.txn.open_table(VIEW_CHANGES)?;
713 let key = encode_view_seq(view.id, s);
714 table.remove(&key)?;
715 }
716
717 // Insert at new sequence (s + 1)
718 {
719 let mut table = self.txn.open_table(VIEW_CHANGES)?;
720 let key = encode_view_seq(view.id, s + 1);
721 table.insert(&key, cid.get())?;
722 }
723
724 // Update reverse mapping
725 {
726 let mut table = self.txn.open_table(REV_VIEW_CHANGES)?;
727 let key = encode_view_seq(view.id, cid.get());
728 table.insert(&key, s + 1)?;
729 }
730 }
731
732 // Insert the new change at the specified position
733 {
734 let mut table = self.txn.open_table(VIEW_CHANGES)?;
735 let key = encode_view_seq(view.id, insert_at);
736 table.insert(&key, change_id.get())?;
737 }
738
739 // 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