From: Jeff D. <da...@da...> - 2000-06-29 07:12:35
|
> > There's a (somewhat well documented) Perl implementation of the > > diff algorithm at: > > http://www.plover.com/~mjd/perl/diff/ > >Thanks for pointing this out. Actually, this afternoon, I discovered that there's a newer and more memory efficient version of Algorithm::Diff on the CPAN. (In the old version LCS_matrix() populates an m by n matrix; where m and n are the lengths of the files be diffed.) >I hacked around a little bit and came up with a somewhat simplified >php version of the perl-diff by mjd. I've done a bit more reading, and have looked closed at the GNU diffutils sources. This afternoon I hacked together my own PHP diff engine. I think it's working, though I'd like to test it a bit more. Here it is if you'd like to check it out. Features: o Memory requirements are linear in file size, rather than quadratic. o Fancy colorized diff output (either unified diffs or plain diffs). o Diffs can be serialized, deserialized, and applied to a file. (i.e. this code is ready to be used in a version control system.) Computation time is still quadratic in file size. I did not include in the code the heuristics which GNU diff uses to get around this, though it could be easily done. As long as the files involved are not more than a few hundred lines in length, it's probably not an issue. Jeff |