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>])
| 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 |
| 80 | pub 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 | /// |