Thread View: alt.free.newsservers
2 messages
2 total messages
Started by Jeff-Relf.Me
Thu, 22 Nov 2012 00:39
--
Author: Jeff-Relf.Me
Date: Thu, 22 Nov 2012 00:39
Date: Thu, 22 Nov 2012 00:39
66 lines
4210 bytes
4210 bytes
<body style='background: black;'><pre style='background: black; font-family: DejaVu Sans Mono, Lucida Console, monospace, MS Mincho; padding: 1em; color: rgb( 128, 64, 0 ); font-size: 25px;'>
I recently rewrote my diff (text file comparison) routines.
I didn't know, much less use, standard algorithms/formats.
<A hRef="http://en.wikipedia.org/wiki/Diff#Usage">Here</A> WikiPedia provides example
inputs/outputs and explains the formats of the various outputs.
Curious, I ran them though my diff routines.
My output, <A hRef="http://Jeff-Relf.Me/Diff.PNG">shown here</A>, is much easier to read !
Green highlights the new stuff, purple the old.
Every block of "old" lines, « - », is paired with a block of "new", « + ».
Before comparing lines, leading/trailing whitespace is removed.
When reporting, the whitespace is shown as it was, unaltered.
Although unaltered/whole lines are reported,
( with intra⋅line changes/words highlighted ),
runs of whitespace ( newlines, tabs, spaces )
are treated as if they were just one space ( ASCII 32 ).
When reporting on a block of changed lines ( and/or intra⋅line changes )
runs of up to 3 unchanged lines ( and/or words ) are allowed, for context.
Besides adding context, it reduces the chance of "false" (poor) reporting.
Standard diff routines don't do that. Instead of simply allowing a run of
3 ( or fewer ) unchanged lines, they look for the longest runs first.
Of course, the last line in a file ( and/or last token in a line )
can match without the need for "the next 3 lines" to also match.
When highlighting changes within a line, the following determines
which two lines ( old vs. new ) should be compared.
// From <A hRef="http://Jeff-Relf.Me/X.CPP">X.CPP</A>, Visual C++.
if ( Cnt ) { // "Cnt" is the number of lines ( in "BB⋅Alts[]" )
// that might be comparible to the current line,
// "b" ( "Vx" is "b" broken into a list of tokens/words ).
LnP Word ; int WrdCnt, Len, SzVx, LenDiff, ⦿WrdCnt, ⦿Len, ⦿LenDiff, iBest ;
iBest = ⦿WrdCnt = ⦿Len = 0, ⦿LenDiff = 999, SzVx = szStr( b );
Loop( Cnt ) {
WrdCnt = Len = 0, rv = szStr( BB⋅Alts[ J ] ), LenDiff = abs( SzVx - rv );
LoopXx( Ln, Vx ) { if ( !( Word = P ) ) continue ;
LoopXx( Ln, Aa[ J ] ) { // How well does this line macth ?
if ( !P || P[-1] == 999 || !Eq( P, Word ) )
// The "int" before "P" ( a "word|Token" in a line of code )
// holds the "already matched" flag, 999.
continue ;
P[-1] = 999, WrdCnt++, Len += szStr( Word );
break; } }
if ( WrdCnt > ⦿WrdCnt // Pick the line with the most matching tokens.
|| WrdCnt == ⦿WrdCnt
&& (
Len > ⦿Len // A tie, choose the bigger matched⋅tokens.
|| Len == ⦿Len
&& LenDiff < ⦿LenDiff ) ) // A tie, go with similar line length.
⦿WrdCnt = WrdCnt, ⦿Len = Len, ⦿LenDiff = LenDiff, iBest = J ; }
Alt = BB⋅Alts[ iBest ], Vx₂ = Aa[ iBest ]; }
Re: My diffs are MUCH easier to read !
Author: Clogwog
Date: Thu, 22 Nov 2012 20:56
Date: Thu, 22 Nov 2012 20:56
10 lines
2007 bytes
2007 bytes
"Jeff-Relf.Me" <@.> schreef in bericht
news:Jeff-Relf.Me@Nov.21{4.39.PM.Seattle.2012}...
<body style='background: black;'><pre style='background: black;
font-family: DejaVu Sans Mono, Lucida Console, monospace, MS Mincho;
padding: 1em; color: rgb( 128, 64, 0 ); font-size: 25px;'>
I..............
*PLONK*
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads