Commit b6c18e4
committed
Fix replacements mispairing deletions and insertions when second seq is longer
When deep-diff places all insertions at the last index of the original
sequence, early deletions couldn't find their matching insertion because
replacements only checked positions d and d-1. Add a fallback that finds
the nearest insertion key > d, but only when all indices between d and
that key are also being deleted (no surviving elements in between).
This ensures correct positional pairing without false matches.
Example: (diff '({:a 1} {:b 1}) '({:a 2} {:b 2} {:c 2}))
Before (wrong):
[Deletion{:a 1} {Deletion{:b} 1, Insertion{:a} 2} Insertion{:b 2} Insertion{:c 2}]
After (correct):
[{:a Mismatch{1→2}} {:b Mismatch{1→2}} Insertion{:c 2}]1 parent cb8385f commit b6c18e4
File tree
2 files changed
+19
-6
lines changed- src/lambdaisland/deep_diff2
- test/lambdaisland/deep_diff2
2 files changed
+19
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
307 | 312 | | |
308 | 313 | | |
309 | 314 | | |
| |||
0 commit comments