HSDiff (hunt_szymanski_diff v0.1.0)
Provides a Hunt–Szymanski-based line diff:
- Compute the LCS (Longest Common Subsequence) using the Hunt–Szymanski approach.
- Build a diff result (eq/del/ins) from that LCS.
Typically used for large lists of lines where changes are relatively sparse. This version also handles cases where left/right differ in length or contain multiple occurrences of the same line.
Summary
Functions
Build a [eq: [...], del: [...], ins: [...]] diff from left
, right
,
and lcs
lines, using pointer arithmetic with a reduce_while
call.
diff/2 entry point
Compute the LCS of two lists (commonly lines) via Hunt–Szymanski.
Functions
Build a [eq: [...], del: [...], ins: [...]] diff from left
, right
,
and lcs
lines, using pointer arithmetic with a reduce_while
call.
We return {:cont, {acc, i, j}}
to keep going,
or {:halt, {acc, i, j}}
if we detect the LCS line can't be found.
After the reduce, we handle leftover lines in left
or right
.
diff/2 entry point:
diff(left, right)
If left
and right
are strings, we split them by into lists of lines.
If
left
and right
are already lists, we pass them along.
Compute the LCS of two lists (commonly lines) via Hunt–Szymanski.
Returns just the list of common elements in order.
You can then convert that LCS into a diff using build_diff/3
or your own logic.
See HSDiff.Patch.patch/2
.