Skip to main content

histogram_diff_lines

Function histogram_diff_lines 

Source
pub fn histogram_diff_lines(
    old: &[DiffLine<'_>],
    new: &[DiffLine<'_>],
) -> Vec<DiffOp>
Expand description

Compute a line-level edit script transforming old into new using the histogram diff algorithm (as in git diff --histogram, derived from JGit).

Histogram diff is a patience-style unique-anchor algorithm with a fallback: it builds an occurrence histogram of old and, scanning new, picks the longest run of matching lines whose old line has the fewest occurrences (preferring truly unique lines, like patience, but still able to anchor on low-frequency lines when no globally-unique line exists). It then recurses on the regions on either side of that run, falling back to Myers only when no common line exists in a region. The result is a valid LCS-correct edit script with the same shape as myers_diff_lines.