Expand description
§Features
Changeenum as an abstraction fordiff::Result,lcs_diff::DiffResult, andwu_diff::DiffResult;diff_changes(),diff_diff(),lcs_changes(),lcs_diff(),wu_changes(), andwu_diff()functions to calculate or process diffs betweenaandbslices via LCS (Longest Common Subsequence) or Wu diff algorithms into aVec<Change>patch()function to reproducebfrom theaslice andVec<Change>insert()andremove()functions to enable writing a customchangesfunction
§Example
use slice_diff_patch::*;
let a = vec!["one", "TWO", "three", "four"];
let b = vec!["zero", "one", "two", "four"];
let diff = diff_diff(&a, &b);
assert_eq!(
diff,
vec![
Change::Insert((0, "zero")),
Change::Remove(2),
Change::Update((2, "two")),
],
);
assert_eq!(patch(&a, &diff), b);
let lcs = lcs_diff(&a, &b);
assert_eq!(
lcs,
vec![
Change::Insert((0, "zero")),
Change::Update((2, "two")),
Change::Remove(3),
],
);
assert_eq!(patch(&a, &lcs), b);
let wu = wu_diff(&a, &b);
assert_eq!(
wu,
vec![
Change::Insert((0, "zero")),
Change::Remove(2),
Change::Update((2, "two")),
],
);
assert_eq!(patch(&a, &wu), b);§References
- Hunt, James W; Szymanski, Thomas G. (1977). “A fast algorithm for computing longest common subsequences” http://www.cs.ust.hk/mjg_lib/bibs/DPSu/DPSu.Files/HuSz77.pdf
- Wu, Sun; Manber, Udi; Myers, Gene (1989). “An O(NP) Sequence Comparison Algorithm” https://publications.mpi-cbg.de/Wu_1990_6334.pdf
- Department of Mathematics and Computer Science. University of Southern Denmark (January 12, 2017). “The Hunt-Szymanski Algorithm for LCS” https://imada.sdu.dk/~rolf/Edu/DM823/E16/HuntSzymanski.pdf
- diff crate
- lcs-diff crate
- wu-diff crate
- Wikipedia: Hunt–Szymanski algorithm
- Wikipedia: Bitap algorithm
- Practical use case analysis
Enums§
- Change
- Abstraction for
diff::Result,lcs_diff::DiffResult, andwu_diff::DiffResultthat excludes a variant for common sequence, stores a clone of inserted items, and indices relate iteratively toa.
Functions§
- diff_
changes - Convert a slice of
diff::Resultinto aVec<Change>. - diff_
diff - Calculate the diff between
aandbviadiff::sliceand convert to aVec<Change>. - insert
- Process an insert.
- lcs_
changes - Convert a slice of
lcs_diff::DiffResultinto aVec<Change>. - lcs_
diff - Calculate the diff between
aandbvialcs_diff::diffand convert to aVec<Change>. - patch
- Reproduce
bfrom theaslice andVec<Change>. - remove
- wu_
changes - Convert a slice of
wu_diff::DiffResultinto aVec<Change>. - wu_diff
- Calculate the diff between
aandbviawu_diff::diffand convert to aVec<Change>.