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

Method remap_referenced_node_ids

atomic-core/src/change/ops.rs:330–435  ·  view source on GitHub ↗

Translate existing semantic identities while preserving ROOT placeholders. Resolve each distinct external owner once, before changing any operation. If resolution fails, `self` is unchanged. The caller supplies the owner mapping; this does not infer names from paths, application order or local numeric coincidences.

(
        &mut self,
        mut remap: impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
    )

Source from the content-addressed store, hash-verified

328 /// mapping; this does not infer names from paths, application order or local
329 /// numeric coincidences.
330 pub fn remap_referenced_node_ids<E>(
331 &mut self,
332 mut remap: impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
333 ) -> Result<(), E> {
334 let mapping: std::collections::BTreeMap<_, _> = self
335 .referenced_node_ids()
336 .into_iter()
337 .map(|id| remap(id).map(|resolved| (id, resolved)))
338 .collect::<Result<_, E>>()?;
339 let mut remap = |id| -> Result<crate::types::NodeId, E> {
340 // referenced_node_ids enumerates the same non-ROOT fields walked
341 // below. All fallible resolution finished before the first write.
342 Ok(mapping[&id])
343 };
344 fn trunk<E>(
345 id: &mut TrunkId,
346 f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
347 ) -> Result<(), E> {
348 if !id.change_id().is_root() {
349 *id = TrunkId::new(f(id.change_id())?, id.file_idx());
350 }
351 Ok(())
352 }
353 fn branch<E>(
354 id: &mut BranchId,
355 f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
356 ) -> Result<(), E> {
357 if !id.change_id().is_root() {
358 *id = BranchId::new(f(id.change_id())?, id.branch_idx());
359 }
360 Ok(())
361 }
362 fn leaf<E>(
363 id: &mut LeafId,
364 f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
365 ) -> Result<(), E> {
366 if !id.change_id().is_root() {
367 *id = LeafId::new(f(id.change_id())?, id.leaf_idx());
368 }
369 Ok(())
370 }
371 fn leaves<E>(
372 ops: &mut [LeafOp],
373 f: &mut impl FnMut(crate::types::NodeId) -> Result<crate::types::NodeId, E>,
374 ) -> Result<(), E> {
375 for op in ops {
376 match op {
377 LeafOp::Insert {
378 after: Some(id), ..
379 } => leaf(id, f)?,
380 LeafOp::Delete { leaf: id }
381 | LeafOp::Replace { leaf: id, .. }
382 | LeafOp::Restore { leaf: id } => leaf(id, f)?,
383 LeafOp::Insert { after: None, .. } => {}
384 }
385 }
386 Ok(())
387 }

Calls 4

branchFunction · 0.85
referenced_node_idsMethod · 0.80
leavesFunction · 0.50
into_iterMethod · 0.45