float x0=0; int g=0; int tx=300,ty=40; char Oi = char(183), Ou='+'; // MANAGE LABELS Labels Lab = new Labels(); class Labels { int m=0; int nI=16; int [] I = new int [nI]; int free=0; Labels() {for(int i=0;im) m=free; return(r);} void release(int k) {I[k]=free; free=k;} void write() {for(int i=0;i"+G.N,tx,ty); else text(O+"("+T.N+","+F.N+"): tt="+tt+", c1="+c1+", c2="+c2+", c3="+c3+", c="+max(c1,c2,c3),tx,ty); }; } else if(O!=' ') {L.reveal(); R.reveal();}; }; int depth() {int d=0; if (O!=' ') d=1+max(L.depth(),R.depth()); return(d);} void pivot() {if(O!=' ') {if (mouse().disTo(P)cL) {node N; N=L; L=R; R=N; }; return(1+max(cL,cR)); } void pO() {if(O==' ') {c1=0; c2=0; c3=0; tt=true;} else {L.pO(); R.pO(); if (flipCost()L.f1) {node N; N=L; L=R; R=N; }; t1=max(L.t1,L.t2,R.t1); t2=R.t2; f1=L.f1; f2=max(L.f2,R.f1+1,R.f2);}; if(O==Ou) {if(R.t1>L.t1) {node N; N=L; L=R; R=N; }; f1=max(L.f1,L.f2,R.f1); f2=R.f2; t1=L.t1; t2=max(L.t2,R.t1+1,R.t2); }; } void pOsaved2() { if(O==' ') {f=0; t=0; c=0;} else {L.pO(); R.pO();}; if(O==Oi) {if(R.t>L.t) {node N; N=L; L=R; R=N; }; t=L.t; f=max(L.c,R.f); c=max(L.c,R.c,R.f+1);}; if(O==Ou) {if(R.f>L.f) {node N; N=L; L=R; R=N; }; f=L.f; t=max(L.c,R.t); c=max(L.c,R.c,R.t+1);}; } void pOsaved() { if(O==' ') {f=0; t=0;} else {L.pO(); R.pO();}; if(O==Oi) {if(R.f>L.f) {node N; N=L; L=R; R=N; }; t=max(1+L.t,R.t); f=max(L.f,R.f); }; if(O==Ou) {if(R.t>L.t) {node N; N=L; L=R; R=N; }; f=max(1+L.f,R.f); t=max(L.t,R.t); }; } void drawBlist() { if(O==' ') { SG=G; EG=G; TG=G; FG=G; t1=0; t2=0; f1=0; f2=0;} else { L.drawBlist(); R.drawBlist(); if(O==Oi) {SG=L.SG; EG=R.EG; FG=L.FG; TG=R.TG; t1=max(L.t1,L.t2,R.t1); t2=R.t2; f1=L.f1; f2=max(L.f2,R.f1+1,R.f2); L.EG.drawTI(R.SG); L.EG.drawFF(R.FG,R.f1+1);}; if(O==Ou) {SG=L.SG; EG=R.EG; FG=R.FG; TG=L.TG; f1=max(L.f1,L.f2,R.f1); f2=R.f2; t1=L.t1; t2=max(L.t2,R.t1+1,R.t2);L.EG.drawFI(R.SG); L.EG.drawTT(R.TG,R.t1+1);}; }; } } // end node // ARCHIVAL void fromString() {if (S[0].length()==0) return; println("parsing "); println("<"+S[0]+"> "+S[0].length()+" chars"); ng=0; Gs.nG=0; Ns.nR=0; g=0; Ns.nR++; node N=make(); println(); println("done"); Ns.R[0]= N; ng=Gs.nG; Buttons.B[0].V=ng; resize(); } void fromStringR() {if (S[0].length()==0) return; println("parsingR "); println("<"+S[0]+"> "+S[0].length()+" chars"); ng=0; Gs.nG=0; Ns.nR=0; g=0; Ns.nR++; node N=makeR(); println(); println("done"); Ns.R[0]= N; ng=Gs.nG; Buttons.B[0].V=ng; resize(); } node make() { node N = new node(); N.T=Gs.t; N.F=Gs.f; char C=S[0].charAt(0); if(C=='+') C=Ou; if(C=='x') C=Oi; if(C=='.') C=Oi; S[0]=S[0].substring(1); if((C!=Ou)&&(C!=Oi)) {Gs.addGate(name(g++)); N.G=Gs.G[Gs.nG-1]; N.O=' ';} else {N.O=C; N.L=make(); N.R=make(); } return(N); } node makeR() { node N = new node(); N.T=Gs.t; N.F=Gs.f; if(S[0].length()==0) {println(); println("Rempty"); return(N);} else { char C=S[0].charAt(0); if(C=='+') C=Ou; if(C=='.') C=Oi; S[0]=S[0].substring(1); print(C); if((C!=Ou)&&(C!=Oi)) {Gs.addGate(C); N.G=Gs.G[Gs.nG-1]; N.O=' ';} else {N.O=C; N.L=makeR(); N.R=makeR(); } return(N); } }