S sp(S k)//symbol from phrase: string interning, Ks(sp("aaa")). This should be called before introducing any sym to the instance { //We are using this to ensure any two 'character-identical' symbols are in fact represented by the same pointer S //See Knuth Algorithm 6.2.2T #define LINK(n,x) (n)->c[((x)+1)/2] // -1 => 0 , 1 => 1 if(!k)R 0;//used in glue. used in _2m_4. used in parse. Probably a good argument to keep since it's exposed for libraries via 2: dyadic N t=SYMBOLS, s=t->c[1],p=s,q=p,r; I a,x; if(!s){s=t->c[1]=newN();P(!s,(S)ME);s->k=sdup(k); if(!s->k){free(s);t->c[1]=0;ME;} R s->k;} // <-- strdup here and below while(q) { if(!(a=SC(k,p->k))){R p->k;}//In the usual tree put: p->k=k,p->v=v before returning if(!(q=LINK(p,a))){q=newN();P(!q,(S)ME);q->k=sdup(k);if(!q->k){free(q);ME; R 0;} LINK(p,a)=q;break;}//Usual tree would q->v=v. mmo else if(q->b){t=p;s=q;} p=q; } a=0>SC(k,s->k)?-1:1; r=p=LINK(s,a); while(p!=q){x=SC(k,p->k); p->b=x;p=LINK(p,x);} if(!s->b){s->b=a;R p->k;} else if(s->b==-a){s->b=0; R p->k;} if(r->b==a){p=r; LINK(s,a)=LINK(r,-a); LINK(r,-a)=s; s->b=r->b=0;} else if(r->b==-a) { p=LINK(r,-a); LINK(r,-a)=LINK(p,a); LINK(p,a)=r; LINK(s,a)=LINK(p,-a); LINK(p,-a)=s; if (p->b== a){s->b=-a; r->b=0;} else if(p->b== 0){s->b= 0; r->b=0;} else if(p->b==-a){s->b= 0; r->b=a;} p->b=0; } t->c[s==t->c[1]?1:0]=p; R q->k; }
bool PNS_DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, PNS_ITEM* aEndItem ) { if( !m_fitOk ) return false; if( m_currentTrace.CP().SegmentCount() < 1 || m_currentTrace.CN().SegmentCount() < 1 ) return false; if( m_currentTrace.CP().SegmentCount() > 1 ) m_initialDiagonal = !DIRECTION_45( m_currentTrace.CP().CSegment( -2 ) ).IsDiagonal(); PNS_TOPOLOGY topo( m_lastNode ); if( !m_snapOnTarget && !m_currentTrace.EndsWithVias() ) { SHAPE_LINE_CHAIN newP( m_currentTrace.CP() ); SHAPE_LINE_CHAIN newN( m_currentTrace.CN() ); if( newP.SegmentCount() > 1 && newN.SegmentCount() > 1 ) { newP.Remove( -1, -1 ); newN.Remove( -1, -1 ); } m_currentTrace.SetShape( newP, newN ); } if( m_currentTrace.EndsWithVias() ) { m_lastNode->Add( m_currentTrace.PLine().Via().Clone() ); m_lastNode->Add( m_currentTrace.NLine().Via().Clone() ); m_chainedPlacement = false; } else { m_chainedPlacement = !m_snapOnTarget; } PNS_LINE lineP( m_currentTrace.PLine() ); PNS_LINE lineN( m_currentTrace.NLine() ); m_lastNode->Add( &lineP ); m_lastNode->Add( &lineN ); topo.SimplifyLine( &lineP ); topo.SimplifyLine( &lineN ); m_prevPair = m_currentTrace.EndingPrimitives(); Router()->CommitRouting( m_lastNode ); m_lastNode = NULL; m_placingVia = false; if( m_snapOnTarget ) { m_idle = true; return true; } else { initPlacement(); return false; } }