HSDiff (hunt_szymanski_diff v0.1.0)

Provides a Hunt–Szymanski-based line diff:

  1. Compute the LCS (Longest Common Subsequence) using the Hunt–Szymanski approach.
  2. 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_diff(left, right, lcs)

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(left, 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.

hunt_szymanski_lcs(left, right)

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.

optimize(diff)

See HSDiff.Optimize.optimize/1.

patch(old, diff)

See HSDiff.Patch.patch/2.