Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #155455

Pinching and Peeling, from the edges to the middle. 

From Jeff-Relf.Me <@.>
Newsgroups alt.free.newsservers, comp.os.linux.advocacy, sci.physics, alt.astronomy
Subject Pinching and Peeling, from the edges to the middle. 
Date 2013-01-01 09:46 -0800
Organization Glorb Internet Services, http://www.glorb.com
Message-ID <Jeff-Relf.Me@Jan.1{9.46.AM.Seattle.2013}> (permalink)
References <Jeff-Relf.Me@Dec.30{6.20.PM.Seattle.2012}>

Cross-posted to 4 groups.

Show all headers | View raw


<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;'> 
As I said before, my diff routine skips past the unchanged part
at the beginning and ends of lines/files; top, bottom, left and right.
I call this "the Pinch".

Then it "peels off" ( and prints ) the differences at the ends...
Pinching and Peeling, from the edges to the middle.

Although the algorithm is simple, the finer deatials are not.
The core of it looks like this:

LnP F, _F ;  LnA BBx, EEx, _BBx, _EEx, BB_Sync, EE_Sync, _BB_Sync, _EE_Sync ;

#define white( P ) ( *P &lt;= 32 || *P == 0xA0 )
#define white⋀( P ) ( *P && *P &lt;= 32 || *P == 0xA0 )
#define  Same⋁Sync   ( Data⋁( F, EEx,  EE ), Data⋁( _F, _EEx,  _EE ), Same() )
#define  Same⋀Sync   ( Data⋀( F, BBx,  BB ), Data⋀( _F, _BBx,  _BB ), Same⋀() )

#define  Same⋁Pinch  ( Data⋁( F, BBx,  EE ), Data⋁( _F, _BBx,  _EE ), Same() )
#define  Same⋀Pinch  ( Data⋀( F, EEx, BBx ), Data⋀( _F, _EEx, _BBx ), Same⋀() )
          
Data⋁( LnP &amp;P, LnA &amp;PP, LnA EE ) { if ( P ) while( *P && white( P ) ) P++ ;
  while( ( !P || !*P ) && PP < EE ) P = ++PP >= EE ? 0 : *PP ;  }

Data⋀( LnP &amp;P, LnA &amp;PP, LnA BB ) { if ( P ) while( *P && white( P ) ) P++ ;
  while( ( !P || !*P ) && PP >= BB ) P = --PP < BB ? 0 : *PP ;  }

int Same() { if ( !F || !_F ) return 0 ; 
  while( *F && *F == *_F && !white( F ) ) F++, _F++ ;  return white( F ) && white( _F );  }

int Same⋀() { if ( !F || !_F ) return 0 ; 
  while( *F && *F == *_F && !white( F ) ) F++, _F++ ;  return !*F && !*_F || white⋀( F ) && white⋀( _F );  }

int SyncDwn( LnA BB, LnA EE, LnA _BB, LnA _EE ) { BB_Sync = BB, _BB_Sync = _BB ;
  F = _F = 0, EEx = BB - 1, _EEx = _BB - 1 ; while ( Same⋁Sync ) if ( !*F && !*_F ) return 1 ;  return 0 ;  }

int SyncUp( LnA BB, LnA EE, LnA _BB, LnA _EE ) { EE_Sync = EE, _EE_Sync = _EE ;
  F = _F = 0, BBx = EE, _BBx = _EE ; while ( Same⋀Sync ) if ( !*F && !*_F ) return 1 ;  return 0 ;  }

Pinch( LnA BB, LnA EE, LnA _BB, LnA _EE ) { F = _F = 0, BBx = BB - 1, _BBx = _BB - 1 ; while ( Same⋁Pinch );
  F = _F = 0, EEx = EE, _EEx = _EE ; while ( Same⋀Pinch );  EEx++, _EEx++ ;  }
          
#define EoFS_Dwn  ( S = BB_Slow < EE_Slow, _S = _BB_Slow < _EE_Slow, F = BB_Fast+1 < EE_Slow, _F = _BB_Fast+1 < _EE_Slow )
#define EoFS_Up   ( S = EE_Slow > BB_Slow, _S = _EE_Slow > _BB_Slow, F = EE_Fast-1 > BB_Slow, _F = _EE_Fast-1 > _BB_Slow )
#define Top_Fast  ( BB_Fast = BB_Slow, _BB_Fast = _BB_Slow )
#define Bot_Fast  ( EE_Fast = EE_Slow, _EE_Fast = _EE_Slow )

Peel( LnA BB, LnA EE, LnA _BB, LnA _EE ) { int rv, Top, Bot, S, _S, F, _F ;  LnP t, _t ;  
  LnA  BB_Slow, _BB_Slow,  BB_Fast, _BB_Fast,   EE_Slow, _EE_Slow, EE_Fast, _EE_Fast ;
  Top = Bot = 0, BB_Slow = BB, _BB_Slow = _BB, EE_Slow = EE, _EE_Slow = _EE, Top_Fast, Bot_Fast ;
   
  ⋅Top:    if ( Top ) goto ⋅Bot ;  EoFS_Dwn ;
  if ( !S && !_S ) { Top = 1, BB_Sync = BB_Slow, _BB_Sync = _BB_Slow ; goto ⋅Bot ;  }
  if ( F && _S ) if ( SyncDwn( BB_Fast, EE, _BB_Slow, _EE ) ) { Top = 1 ; goto ⋅Bot ;  } else BB_Fast++ ;
  if ( S && _F ) if ( rv = SyncDwn( BB_Slow, EE, _BB_Fast, _EE ) ) { Top = 1 ; goto ⋅Bot ;  } else _BB_Fast++ ;
  if ( EoFS_Dwn, !( F && _S || S && _F ) ) BB_Slow += S, _BB_Slow += _S, Top_Fast ;

  ⋅Bot:    if ( Bot ) goto Skip ;  EoFS_Up ; 
  if ( !S && !_S ) { Bot = 1, EE_Sync = EE_Slow, _EE_Sync = _EE_Slow ; goto ⋅Top ;  }
  if ( F && _S ) if ( SyncUp( BB, EE_Fast, _BB, _EE_Slow ) ) { Bot = 1 ; goto ⋅Top ;  } else EE_Fast-- ;
  if ( S && _F ) if ( rv = SyncUp( BB, EE_Slow, _BB, _EE_Fast ) ) { Bot = 1 ;  goto ⋅Top ;  } else _EE_Fast-- ;
  if ( EoFS_Up, !( F && _S || S && _F ) ) EE_Slow -= S, _EE_Slow -= _S, Bot_Fast ;
        
  Skip:    if ( Top && Bot ) return ;  goto ⋅Top ;  }

  <img Src="http://Jeff-Relf.Me/Diff.PNG" Alt="Text Comparison">

Back to comp.os.linux.advocacy | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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