You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
k/h.c

44 lines
4.0 KiB

#include"a.h" // ngn/k, (c) 2019-2022 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
A1(rs0,rsz(0,x))
SN A flt(Ax,Ay,Cb/*01b*/)_(P(xK-1,er1(y))Ym(K("{(!y)[i]!(.y)i:&z~/:x@.y}",xR,y,ai(b)))
x=Ny(x1(yR));x=xN?Ny(cL(x)):x(oB);P(!xtt&&xN-yN,el1(x(y)))Az=rs0(yR);i(yN,Ln=gl(ii(x,i));B(b&&n-(UI)n,z=ed1(z))j(b?n:!n,zq(ii(y,i))))x(y(z)))
V cyc(V*a,Nm,Nn){Q(m);W(2*m<=n,Mc(a+m,a,m);m*=2)I(n>m,Mc(a+m,a,n-m))}
ALA(rsz,/*1*/Xt(rsz(n,enl(x)))XM(Ay=kv(&x),z=az(n);aM(x,Nx(z(r2(RSH,z,y)))))Xm(Ay=kv(&x);x=Ny(rsz(n,x));y=Nx(rsz(n,y));am(x,y))Q(xtT)P(n==NL,x)P(!xn,rsz(n,enl(fir(x))))
I r=n<0;n*=1-2*r;Ay=an(n,xt);N w=xW,m=xn*w,k=n%xn*w,l=n*w;I(!r,Mc(yV,xV,min(m,l)))J(l<=m,Mc(yV,xV+m-l,l))E(Mc(yV,xV+m-k,k);Mc(yV+k,xV,m-k))cyc(yV,m,l);
I(!n&&ytA,yx=mkn(_R(xx)))x(ytA?sqz(mRa(y)):y))
A slc(Ax/*0*/,Ni,Nj)_(Q(xtT&&i<=j&&i<=xn)Nn=j-i;Ay=an(n,xt);Mc(yV,xV+i*xW,n*xW);XA(P(!n,yx=mkn(_R(xx));y)sqz(mRa(y)))y)
S ALA(chp,/*1*/P(n<0,ed1(x))Lm=(xn+n-1)/n;Ay=aA(m);i(m|!m,ya=slc(x,n*i,min(xn,n*i+n)))x(0);I(!m,yx=mkn(yx))y)
S A2(rsh,/*01*/YmM(en1(y))Yt(rsh(x,enl(y)))Q(xtZ);N r=xn;P(!r,fir(y))P(r>256,ez1(y))x=Ny(cL(xR));L s[r];Mc(s,xV,r<<3);x(0);
I(r==2,P(*s==NL,chp(s[1],y))P(s[1]==NL,K2("{$[(0<x)&~x!#y;(x;(-x)!#y)#y;((-x)!(#y)*!x)_y]}",az(*s),y)))P(r==1&&*s==NL,y)I(!yn,y=enl(fir(y)))
L p[r],m=1;i(r,L d=s[r-1-i];P(d<0||m*d<0,ed1(y))p[i]=m*=max(1,d))y=N(rsz(m,y));i(r-1,L d=s[r-1-i];I(d,y=N(chp(max(1,d),y)))E(y=N(e1f(rs0,chp(1,y)))))rsz(*s,y))
A2(hsh,/*01*/Xz(rsz(gl_(x),y))XU(flt(x,y,1))XT(P(ytm||ytM&&xtS,y(a2t(xR,y1(xR),yt)))XZ(rsh(x,y))et1(y))et1(y))
ALA(drp,/*n1*/XT(P(n==NL,rs0(x))P(-n<(UL)xn&&xr==1,I(xtA,mrn(-n,xA+xn+n))AN(xn+n,x))x(slc(x,max(0,min((L)xn,n)),max(0,min((L)xn,xn+n)))))
Xm(Ay=kv(&x);am(Ny(drp(n,x)),Nx(drp(n,y))))XM(Ay=kv(&x);aM(x,Nx(e2f(und,az(n),y))))er1(x))
S AAL(rmv,XT(P(!in(i,xn),x)Ay=an(xn-1,xt);Mc(yV,xV,i*xW);Mc(yV+i*xW,xV+i*xW+xW,(xn-i-1)*xW);I(xtA,I(!yn,yx=mkn(_R(xx)))y=sqz(mRa(y)))x(y))et1(x))
S A2(cut,/*01*/Q(xtZ)Q(ytMT)K2("{y$[|/0<':x,#y;`err\"domain\";x+!'1_-':x,#y]}",x,y))
A2(und,/*01*/Xz(drp(gl_(x),y))XU(flt(x,y,0))Xm(y=N(fnd(xx,y));yR;am(und(xx,y),und(xy,y)))P(xtZ&&ytMT,cut(x,y))P(xtMT&&ytz,rmv(xR,gl(y)))
Ym(K2("{((!y)^x)#y}",x,y))YM(flp(N(und(x,flp(y)))))et1(y))
A1(enl,Xi(aV(tZ(xv),1,&x))XU(aA1(x))XP(aV(TT[xt],1,&x))Xt(x(aV(TT[xt],1,xV)))Xm(Ay=kv(&x);aM(x,e1f(enl,y)))aA1(x))
A2(cat11,P(xtT&&ytT,P(!yn,y(x))P(!xn,x(y))I(xtZ&&ytzZ,N(sup(&x,&y)))I(xt-yt,x=cA(x);y=cA(y))Nm=xn,n=yn,w=xW;x=room(m+n,x);Mc(xV+m*w,yV,n*w);I(ytA,yr-1?mRa(y):AZ(y))y(x))
P(xtm&&ytm,y(a4(x,yx,av,yy)))Xmt(cat11(enl(x),y))Ymt(apd(x,y))
P(xtM||ytM,P(xtT||ytT,x=Ny(cA(x));y=Nx(cA(y));cat11(x,y))P(!xtM||!ytM,et2(x,y))P(!mtc_(xx,yx),ed2(x,y))Az=e2f(cat,xy,_R(yy));x(y(z?aM(_R(xx),z):0)))Q(0);0)
A2(cat,/*01*/cat11(xR,y))
A2(apd,/*11*/Q(xtMT);Nn=xN;P(!n,enl(x(y)))
P(xtB&&yti&&yv==(B)yv||xtC&&ytc,apc(x,yv))
P(xtH&&yti&&yv==(H)yv,x=room(n+1,x);xH[n]=yv;x)
P(xtI&&yti||xtS&&yts ,x=room(n+1,x);xI[n]=yv;x)
P(xtL&&yti ,x=room(n+1,x);xL[n]=yv;x)
P(xtL&&ytl||xtF&&ytf ,x=room(n+1,x);xL[n]=gl(y);x)
P(xtZ&&ytz,N(sup(&x,&y));apd(x,y))
XM(P(!ytm||!mtc_(xx,yx),apd(Ny(cA(x)),y))x=mut(x);Az=xy=mut(xy);i(zn|!zn,_q(za,ii(yy,i)))I(!zn,zx=mkn(zx))y(x))
P(!xtA&&(!ytt||xt-TT[yt]),apd(Ny(cA(x)),y))
Lv=xtA?(L)y:gl(y);apv(x,&v))
A apv(Ax/*1*/,OV*v )_(Q(xtT); Nn=xn;x=room(n+1,x);Mc(xV+n*xW,v,xW);x)
A apc(Ax/*1*/,Cc )_(Q(xtC||xtB);Nn=xn;x=room(n+1,x);xC[n]=c;x)
A cts(Ax/*1*/,Qs,Nm)_(Q(xtC); Nn=xn;x=room(n+m,x);Mc(xV+n,s,m);x)
S A insL(Ax,Li,Lj,Ay)_(YU(insL(x,i,j,Nx(y(y1(slc(x,i,j))))))Xmt(et2(x,y))Ymt(insL(x,i,j,enl(y)))P(xtM||ytM,en2(x,y))
P(!in(i,j+1)||!in(j,xN+1),ei2(x,y))P(xtZ&&ytZ&&xt-yt,N(sup(&x,&y));insL(x,i,j,y))P(xt-yt,insL(cA(x),i,j,cA(y)))
Az=an(xn-j+i+yn,xt);Mc(zV,xV,i*xW);Mc(zV+i*xW,yV,yn*xW);Mc(zV+(i+yn)*xW,xV+j*xW,(xn-j)*xW);
I(xtR,I(xr-1,mRn(i,xA);mRn(xn-j,xA+j))E(mrn(j-i,xA+i);AZ(x))I(yr-1,mRa(y))E(AZ(y)))x(y(z)))
A3(ins3,/*100*/Yz(Li=gl_(y);insL(x,i,i,zR))YZ(P(yn-2,el1(x))insL(x,gl_(ii(y,0)),gl_(ii(y,1)),zR))et1(x))
AA(ins,/*10..0*/Ax=*a;P(n==3,ins3(x,a[1],a[2]))en1(x))