Walk the line order recorded by one effective closure. Ambient AFTER rows may have been reparented by a different view and are not a baseline.
(
after: &std::collections::BTreeMap<
atomic_core::crdt::BranchId,
Option<atomic_core::crdt::BranchId>,
>,
)
| 731 | /// Walk the line order recorded by one effective closure. Ambient AFTER |
| 732 | /// rows may have been reparented by a different view and are not a baseline. |
| 733 | pub(super) fn semantic_branch_order( |
| 734 | after: &std::collections::BTreeMap< |
| 735 | atomic_core::crdt::BranchId, |
| 736 | Option<atomic_core::crdt::BranchId>, |
| 737 | >, |
| 738 | ) -> Result<Vec<atomic_core::crdt::BranchId>, String> { |
| 739 | let mut successors = std::collections::BTreeMap::<_, Vec<_>>::new(); |
| 740 | for (branch, predecessor) in after { |
| 741 | if predecessor.is_some_and(|id| !after.contains_key(&id)) { |
| 742 | return Err(format!( |
| 743 | "semantic branch {branch:?} has a predecessor outside its closure" |
| 744 | )); |
| 745 | } |
| 746 | successors.entry(*predecessor).or_default().push(*branch); |
| 747 | } |
| 748 | let mut stack = successors.remove(&None).unwrap_or_default(); |
| 749 | stack.reverse(); |
| 750 | let mut ordered = Vec::with_capacity(after.len()); |
| 751 | while let Some(branch) = stack.pop() { |
| 752 | ordered.push(branch); |
| 753 | if let Some(mut children) = successors.remove(&Some(branch)) { |
| 754 | children.reverse(); |
| 755 | stack.extend(children); |
| 756 | } |
| 757 | } |
| 758 | if ordered.len() != after.len() { |
| 759 | return Err("semantic closure contains a cyclic line order".into()); |
| 760 | } |
| 761 | Ok(ordered) |
| 762 | } |
| 763 | |
| 764 | /// A whole-file resolution supersedes every line identity observed in its |
| 765 | /// parent closure. A line that one replay considers dead can still be alive |
no test coverage detected