tomas-abrahamsson / tdiff Goto Github PK
View Code? Open in Web Editor NEWDiff algorithm in Erlang
License: Other
Diff algorithm in Erlang
License: Other
Would you be so kind to add a tag on bbb54ce ? :) Thanks.
When comparing source code, it would be more natural (or convenient) to have:
[{eq,"A"},{ins," "},{eq,"/"},{ins," "},{eq,"B"},{del," "}] = tdiff:diff("A/B ", "A / B").
[{eq,"C("},{ins," "},{eq,"D"},{del," "}] = tdiff:diff("C(D ", "C( D").
[{eq,"E"},{ins," "},{eq,"+"},{del," "},{eq,"F"},{del," "}] = tdiff:diff("E+ F ", "E +F").
instead of the current diff output
[{eq,"A"},{ins," "},{eq,"/"},{del,"B"},{eq," "},{ins,"B"}] = tdiff:diff("A/B ", "A / B").
[{eq,"C("},{del,"D"},{eq," "},{ins,"D"}] = tdiff:diff("C(D ", "C( D").
[{eq,"E"},{del,"+"},{eq," "},{ins,"+"},{eq,"F"},{del," "}] = tdiff:diff("E+ F ", "E +F").
This somehow corresponds to giving less weight to whitespace changes when counting the 'edit cost'.
Since whitespace is lexically smaller than other text, it could be possible to favor whitespace changes without braking the code when no ambiguity exists.
Alternatively, it might be possible to favor the diff output which maximize the number of equal terms (also only if there is ambiguity).
Any idea where in the code to do this tweak?
I'm publishing Unite which depends on tdiff to Hex.pm. It would be very helpful if tdiff also existed on Hex.pm. Would it be possible for you to upload it? Alternatively, I can also fork it and upload it if you approve of that.
Here are a couple of test cases
t100() ->
Old = "A cat ate my hat",
New = "A dog ate my shoe",
P = tdiff:diff(Old, New),
New = tdiff:patch(Old, P),
yes.
t101() ->
Old = <<"A cat ate my hat">>,
New = <<"A dog ate my shoe">>,
P = tdiff:diff_binaries(Old, New),
New = tdiff:patch(Old, P),
yes.
This is what happens when I run them
1> test_tdiff:t100().
yes
2> test_tdiff:t101().
** exception error: no match of right hand side value ["A dog ate my shoe"]
in function test_tdiff:t101/0 (test_tdiff.erl, line 18)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.