Article View: alt.free.newsservers
Article #146824Re: Most often, the best code ( for me, and only me ) is the code I wrote.
From: xxein
Date: Tue, 01 Jan 2013 00:21
Date: Tue, 01 Jan 2013 00:21
43 lines
4859 bytes
4859 bytes
On Dec 30, 9:20Â pm, Jeff-Relf.Me <@.> wrote:
> Â 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 ; }
Technical Details
Message-ID:
<145ef576-cf68-4d68-a972-8275c0f2bb4c@10g2000yqk.googlegroups.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ee4no9964480qab.0!news-out.google.com!k2ni4226qap.0!nntp.google.com!ee4no10077871qab.0!postnews.google.com!10g2000yqk.googlegroups.com!not-for-mailReferences:
<Jeff-Relf.Me@Dec.30{6.20.PM.Seattle.2012}>Show Full Headers
Complete Article Headers
Message-ID: <145ef576-cf68-4d68-a972-8275c0f2bb4c@10g2000yqk.googlegroups.com>
Subject: Re: Most often, the best code ( for me, and only me ) is the code I wrote.
Date: Tue, 01 Jan 2013 00:21:56 +0000
From: xxein <xxein@att.net>
References: <Jeff-Relf.Me@Dec.30{6.20.PM.Seattle.2012}>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.free.newsservers.20150605.mbox.gz!border1.nntp.dca3.giganews.com!border2.nntp.dca3.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!ee4no9964480qab.0!news-out.google.com!k2ni4226qap.0!nntp.google.com!ee4no10077871qab.0!postnews.google.com!10g2000yqk.googlegroups.com!not-for-mail
X-Received: by 10.224.72.199 with SMTP id n7mr22901283qaj.5.1356999716964;
MIME-Version: 1.0
Received: by 10.49.15.38 with SMTP id u6mr6301630qec.8.1356999716938; Mon, 31
Newsgroups: comp.os.linux.advocacy, alt.free.newsservers, sci.physics, alt.astronomy
alt.astronomy
Complaints-To: groups-abuse@google.com
Injection-Info: 10g2000yqk.googlegroups.com; posting-host=66.229.156.164;
posting-account=5Th4nAoAAABvCDu6tWl6yI4h_GI2Uuon
NNTP-Posting-Host: 66.229.156.164
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11
(KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11,gzip(gfe)
Injection-Date: Tue, 01 Jan 2013 00:21:56 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Lines: 42
X-Original-Bytes: 4587