Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.advocacy > #155163
| From | Jeff-Relf.Me <@.> |
|---|---|
| Newsgroups | comp.os.linux.advocacy, alt.free.newsservers, sci.physics, alt.astronomy |
| Subject | Most often, the best code ( for me, and only me ) is the code I wrote. |
| Date | 2012-12-30 18:20 -0800 |
| Organization | Glorb Internet Services, http://www.glorb.com |
| Message-ID | <Jeff-Relf.Me@Dec.30{6.20.PM.Seattle.2012}> (permalink) |
Cross-posted to 4 groups.
<style> :not(:link):not(:visited){color:rgb(255,111,111)} :link{color:rgb(155,155,155)} :visited{color:rgb(155,155,0)} </style> <body bgcolor=black style='margin: 0'><pre style='color: rgb(255,111,111); padding:0 1em 1em 1em; font-size: 15px; font-family: DejaVu Sans Mono, Lucida Console, monospace, MS Mincho; background: black;'>
Most often, the best code ( for me, and only me ) is the code I wrote.
As a programmer, text comparison is like water; an essential, daily thing.
So I wrote my own diff routine ( as part of X.EXE, my console/newsreader ).
At it's heart, and right off the bat, my "diff" sort of "skips past"
the unchanged part at the beginning and the ends of both lines and files.
A run of whitespace, including "new lines" ( ASCII 13 and 10 ),
is treated as if it were a single space ( ASCII 32 ).
I could've stopped right there, if I wanted to,
as that is (almost) good enough; but I didn't.
The heart of the line/token comparison routine looks like this:
#define white( P ) ( *P <= 32 || *P == 0xA0 )
#define Data ( ToData( P, EEx, EE, SyncCnt ), ToData( _P, _EEx, _EE, _SyncCnt ), EEx < EE && _EEx < _EE )
ToData( LnP &P, LnA &EEx, LnA EE, int &SyncCnt ) { if ( P ) while( *P && white( P ) ) P++ ;
while( ( !P || !*P ) && EEx < EE ) ( ++EEx >= EE ? ( P = 0, 0 ) : ( P = *EEx, SyncCnt += !!*P ) ); }
LnA BBx, EEx, _BBx, _EEx ; int SyncCnt, _SyncCnt ;
int inSync( int minSyncCnt, LnA BB, LnA EE, LnA _BB, LnA _EE ) { int rv ; LnP P, _P ; LnA PP, _PP ;
BBx = PP = EEx = BB, _BBx = _PP = _EEx = _BB, SyncCnt = _SyncCnt = 0, P = _P = 0, EEx--, _EEx-- ;
while ( Data ) { while( *P && *P == *_P && !white( _P ) ) P++, _P++ ; if ( !white( P ) || !white( _P ) ) return 0 ;
if ( !*P && !*_P && ( SyncCnt + _SyncCnt ) / 2 >= minSyncCnt ) return Data, 1 ; } return 0 ; }
#define EoFS ( S = PP⋅Slow < EE, _S = _PP⋅Slow < _EE, F = PP⋅Fast < EE, _F = _PP⋅Fast < _EE )
ReSync( int minSyncCnt, LnA BB, LnA EE, LnA _BB, LnA _EE ) {
int S, _S, F, _F ; LnA PP⋅Slow, PP⋅Fast, _PP⋅Slow, _PP⋅Fast ;
PP⋅Slow = BB, _PP⋅Slow = _BB ; Top_: PP⋅Fast = BB, _PP⋅Fast = _BB ; Down:
if ( EoFS, !S && !_S ) { BBx = EEx = EE, _BBx = _EEx = _EE ; return ; }
if ( F && _S ) if ( inSync( minSyncCnt, PP⋅Fast, EE, _PP⋅Slow, _EE ) ) return; else PP⋅Fast++ ;
if ( S && _F ) if ( inSync( minSyncCnt, PP⋅Slow, EE, _PP⋅Fast, _EE ) ) return; else _PP⋅Fast++ ;
if ( EoFS, F && _S || S && _F ) goto Down ; PP⋅Slow += S, _PP⋅Slow += _S ; goto Top_ ; }
⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅
WhileSynced:
if ( Vx.PP >= Vx.ee || _Vx.PP >= _Vx.ee ) { VxPP゠( Diff⋅Ch, Vx.ee, _Vx.ee ), Str( D, L"%s", D2 ); return B⋅D ; }
if ( rv = inSync( 99, Vx.PP, Vx.ee, _Vx.PP, _Vx.ee ), VxPP゠( text⋅Ch, EEx, _EEx ), rv ) goto WhileSynced ;
ReSync( 2, Vx.PP, Vx.ee, _Vx.PP, _Vx.ee ), VxPP゠( Diff⋅Ch, BBx, _BBx ); goto WhileSynced ; }
<img Src="http://Jeff-Relf.Me/Diff.PNG" Alt="Text Comparison">
Back to comp.os.linux.advocacy | Previous | Next — Next in thread | Find similar | Unroll thread
Most often, the best code ( for me, and only me ) is the code I wrote. Jeff-Relf.Me <@.> - 2012-12-30 18:20 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Brad Guth <bradguth@gmail.com> - 2012-12-30 18:41 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. terrable <terrable@terrable.net> - 2012-12-31 07:13 -0600
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Brad Guth <bradguth@gmail.com> - 2012-12-31 06:10 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Brad Guth <bradguth@gmail.com> - 2013-01-02 08:15 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. coder <autom@ted.paranoia.feed> - 2013-01-02 15:23 -0600
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Rutles - China Blue Suede Schubert <chine.bleu@yahoo.com> - 2013-01-07 10:59 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. HVAC <hvac@physicist.net> - 2013-01-07 14:12 -0500
Mr. "terrable" is an anonymous, incoherent coward. Jeff-Relf.Me <@.> - 2012-12-31 08:17 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. xxein <xxein@att.net> - 2012-12-31 16:21 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. xxein <xxein@att.net> - 2012-12-31 16:33 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. "Phil Da Lick!" <phil_the_lick@SPAMMERSKISSMYARSE.hotmail.com> - 2013-01-02 12:45 +0000
Pinching and Peeling, from the edges to the middle. Jeff-Relf.Me <@.> - 2013-01-01 09:46 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Brad Guth <bradguth@gmail.com> - 2013-01-02 08:13 -0800
Most often, the best code ( for me, and only me ) is the code I wrote. Jeff-Relf.Me <@.> - 2013-01-02 10:15 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Sir Gregory Hall, Esq· <greghall@home.fåke> - 2013-01-02 14:12 -0500
Re: Most often, the best code ( for me, and only me ) is the code I wrote. Brad Guth <bradguth@gmail.com> - 2013-01-02 13:45 -0800
Re: Most often, the best code ( for me, and only me ) is the code I wrote. moroney@world.std.spaamtrap.com (Michael Moroney) - 2013-01-02 13:24 +0000
Newsgroups are GROUPS of people, not a solitary topic. Jeff-Relf.Me <@.> - 2013-01-02 09:56 -0800
csiph-web