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

Function diff

atomic-core/src/diff/patience.rs:80–98  ·  view source on GitHub ↗

Compute the diff between two sequences using the Patience algorithm. This algorithm often produces more intuitive diffs for source code by using unique lines as anchor points. # Arguments `old` - The original sequence `new` - The modified sequence # Returns A [`DiffResult`] containing the operations to transform old → new. # Algorithm 1. Find lines that appear exactly once in both sequences

(old: &[Line<'a>], new: &[Line<'a>])

Source from the content-addressed store, hash-verified

78/// 3. Use LIS as anchors and recursively diff regions between them
79/// 4. Fall back to Myers diff for regions with no unique matches
80pub fn diff<'a>(old: &[Line<'a>], new: &[Line<'a>]) -> DiffResult {
81 // Special cases
82 if old.is_empty() && new.is_empty() {
83 return DiffResult::new();
84 }
85 if old.is_empty() {
86 let mut result = DiffResult::new();
87 result.push(DiffOp::insert(0, 0, new.len()));
88 return result;
89 }
90 if new.is_empty() {
91 let mut result = DiffResult::new();
92 result.push(DiffOp::delete(0, 0, old.len()));
93 return result;
94 }
95
96 // Run the patience algorithm
97 patience_diff_recursive(old, new, 0, 0)
98}
99
100/// Recursively apply patience diff to a region.
101///

Callers 13

patience_diff_recursiveFunction · 0.70
test_empty_sequencesFunction · 0.70
test_insert_allFunction · 0.70
test_delete_allFunction · 0.70
test_identicalFunction · 0.70
test_single_insertFunction · 0.70
test_single_deleteFunction · 0.70
test_replaceFunction · 0.70
test_fallback_to_myersFunction · 0.70
test_complex_reorderingFunction · 0.70
test_preserves_orderFunction · 0.70

Calls 4

patience_diff_recursiveFunction · 0.85
is_emptyMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by 12

test_empty_sequencesFunction · 0.56
test_insert_allFunction · 0.56
test_delete_allFunction · 0.56
test_identicalFunction · 0.56
test_single_insertFunction · 0.56
test_single_deleteFunction · 0.56
test_replaceFunction · 0.56
test_fallback_to_myersFunction · 0.56
test_complex_reorderingFunction · 0.56
test_preserves_orderFunction · 0.56
test_edit_distanceFunction · 0.56