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/v.c

44 lines
4.7 KiB

#include"a.h" // ngn/k, (c) 2019-2022 ngn, GNU AGPLv3 - https://codeberg.org/ngn/k/raw/branch/master/LICENSE
#define c_(T,R,p) SN V c##T##R(OV*RE v,V*RE w,Nn)_(O T*RE a=v;R*RE r=w;i(PD(n,p),r[i]=a[i]))
#define cN(T,R,p) SN V c##T##R(OV*RE v,V*RE w,Nn)_(O T*RE a=v;R*RE r=w;i(PD(n,p),r[i]=a[i]==N##T?N##R:a[i]))
c_(B,H,r)c_(H,B,a)c_(B,I,r)c_(I,B,a)c_(L,B,a)c_(H,I,r)c_(I,H,a)c_(H,L,r)c_(L,H,a)c_(I,L,r)c_(L,I,a)cN(L,F,a)cN(F,L,a)
A1(flp,Xm(Ay=kv(&x);YA(I(yn>1,Ln=cfm(yA,yn);P(n<0,x(el1(y)))i(yn,Az=ya;I(ztt,y=mut(y);ya=rsz(n,z))))aM(x,y))YT(aM(x,e1f(enl,y)))en2(x,y))
XM(Ay=kv(&x);am(x,y))Xt(enl(enl(x)))P(!xtA,enl(x))Nm=xn;Ln=cfm(xA,m|!m);P(n==-1,enl(x))P(n<0,el1(x))Ct=_t(xx);I(t<tM,i(m,Ay=xa;B(yt-t,t=0)))E(t=0)Ay=aA(n);
P(!t,i(n|!n,Az=aA(m);j(m,zA[j]=ii(xA[j],i))I(!zn,zx=mkn(zx))ya=sqz(z))x(0);I(!yn,yx=mkn(yx))y)
I w=Tw[t];j(n|!n,Az=yA[j]=an(m,t);S4(w,i(m,zb=_B(xa)[j]),i(m,zh=_H(xa)[j]),i(m,zi=_I(xa)[j]),i(m|!m,zl=_L(xa)[j])I(w==4,I(!m,zx=mkn(_R(zx)))yA[j]=sqz(mRa(z)))))
x(0);I(!n,yx=mkn(yx))y)
V tilV(V*p,Ln,I w){L*a=p,v=T(0x706050403020100ll,0x3000200010000ll,1ll<<32,0)[w],d=T(0x808080808080808ll,0x4000400040004ll,2ll<<32|2,1)[w];LI(a)i(PD((n-1>>3-w)+1,a),a[i]=v;v+=d)}
AL(tilL,P(n<0,n==(I)n?add(ai(n),N(tilL(-n))):ed0())P(n>1<<30,ez0())Ax=an(n,tZ(n-1));tilV(xV,n,xt-tB);x)
A1(til,Xz(tilL(gl(x)))XZ(K1("{(*a)#'&'x#'1_a:|*\\|x,1}",x))XmM(x(_R(xx)))Xo(val(x))XS(K1("{x:\".\"/$x,`;`$(#x)_'(x~/:@[;!#x]')#$!.0#`}",x))et1(x))
A1(whr,Xz(whr(enl(x)))XA(K1("{$[`A~@x;(,&#'*'x),,'/x@\\:!0|/#'x:o'x;,&x]}",x))Xm(Ay=kv(&x);x(x1(Nx(whr(y)))))XM(et1(x))
XZ(I w=xt-tB;Ln=0;i(xn,Lv=iw(x,w,i);n+=v;P(n<0||v<0,ed1(x)))Ct=tZ(xn-!!xn);P(t>tI,ez1(x))Ay=an(n,t);
xe(S4(Tw[t],{B*a=yV;i(xn,j(iw(x,w,i),*a++=i))},{H*a=yV;i(xn,j(iw(x,w,i),*a++=i))},{I*a=yV;i(xn,j(iw(x,w,i),*a++=i))},)y))et1(x))
A1(rev,Xm(Ay=kv(&x);am(rev(x),rev(y)))XM(Ay=kv(&x);aM(x,e1f(rev,y)))Xt(x)P(xn<2,x)x=mut(x);Ii=0,j=xn-1,w=xw;W(i<j,S4(w,SWP(xb,xB[j]),SWP(xh,xH[j]),SWP(xi,xI[j]),SWP(xl,xL[j]))i++;j--)x)
A1(typ,x(as(TS[xt])))A1(len,x(az(xN)))N _N(Ax/*0*/)_(XT(xn)Xm(_N(xy))XM(_N(_x(xy)))1)
S A1(cSI,Q(xtS||xtI)Ct=tS^tI^xt;xr-1?x(aV(t,xn,xV)):AT(t,x))
A1(unq,XT(P(xn<2,x)P(xn<<xw<PG&&!xtA,K1("{x@&(x?x)=!#x}",x))P(xtB||xtC,C a[256]={};Ay=an(0,xt);i(xn,I(!a[(UI)xc],a[(UI)xc]=1;y=apc(y,xc)))x(y))XS(cSI(unq(cSI(x))))K1("{x@i@<i@:&@[;0;:;1]@~~':x@i:<x}",x))
XM(en1(x))Xm(unq(val(x)))Xz(Ln=gl(x);P(n<0,ed0())rndF(n))et1(x))
A2(fil,/*01*/YmMA(e2f(fil,x,y))YU(y==au?xR:y)Yt(fir(fil(x,enl(y))))K2("{@[y;&^y;:;x]}",x,y))
A2(exc,/*01*/Xt(fil(x,y))P(xtmM||ytmM,en1(y))Yt(exc(x,enl(y)))P(!xn||!yn,y(xR))Ik=rnk(x);k>0&&k==rnk(y)?K2("{x@&^y?x}",x,y):K2("{x@&~(!0),x~\\:y}/",x,y))
A wdn(Ax,Ni,Nj,Nn)_(Ct=xt;Q(xtZC);Ay=an(n,t+1);xe(T(&cBH,cHI,cIL,cLF,0,cBH)[t-tB](xV+TW[t]*i,yV,j-i);y))
A1(cC, XC(x)x=N(cB(x));Xt(ac((C)xv))AT(tC,mut(x)))
A1(cB, XB(x)x=N(cI(x));Xt(x)Ay=an(xn,tB);xe(cIB(xV,yV,yn);y))
A1(cH, XH(x)x=N(cI(x));Xt(x)Ay=an(xn,tH);xe(cIH(xV,yV,yn);y))
A1(cI, XI(x)Xzc(ai(gl(x)))XfF(cI(N(cL(x))))XZC(Ay=aI(xn);Ii=xt-tB;xe(T(&cBI,cHI,0,cLI,0,cBI)[i](xV,yV,yn);y))et1(x))
A1(cL,XlL(x)Xzc(al(gl(x)))Xt(fir(N(cL(enl(x)))))XF(Ay=aL(xn);xe(cFL(xV,yV,yn);y))x=N(cI(x));Ay=aL(xn);xe(cIL(xV,yV,yn);y))
A1(cF,XfF(x)Xzc(af(gl(x)))Xt(fir(N(cF(enl(x)))))x=N(cL(x));Ay=aF(xn);xe(cLF(xV,yV,yn);y))
A1(cS,XsS(x)XC(x=str0(x);x(sym(xV)))Xc(as(xv))XmMA(e1f(cS,x))et1(x))
A1(pI,Xc(pI(enl(x)))XC(x=str0(x);Qs=xV;P(!*s,x(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