native unit∊vector
This commit is contained in:
parent
9480ee9da2
commit
a6deb4b691
@ -232,6 +232,8 @@ B indexOf_c2(B t, B w, B x) {
|
|||||||
return c2(rt_indexOf, w, x);
|
return c2(rt_indexOf, w, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
B enclosed_0;
|
||||||
|
B enclosed_1;
|
||||||
extern B rt_memberOf;
|
extern B rt_memberOf;
|
||||||
B memberOf_c1(B t, B x) {
|
B memberOf_c1(B t, B x) {
|
||||||
if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0");
|
if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0");
|
||||||
@ -246,18 +248,47 @@ B memberOf_c1(B t, B x) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
B memberOf_c2(B t, B w, B x) {
|
B memberOf_c2(B t, B w, B x) {
|
||||||
if (!isArr(w) || rnk(w)!=1 || !isArr(x) || rnk(x)!=1) return c2(rt_memberOf, w, x);
|
if (isAtm(x) || rnk(x)!=1) goto bad;
|
||||||
usz wia = a(w)->ia;
|
if (isAtm(w)) goto single;
|
||||||
usz xia = a(x)->ia;
|
ur wr = rnk(w);
|
||||||
// TODO O(wia×xia) for small wia or xia
|
if (wr==0) {
|
||||||
H_Sb* set = m_Sb(64);
|
B w0 = IGet(w, 0);
|
||||||
bool had;
|
dec(w);
|
||||||
SGetU(x)
|
w = w0;
|
||||||
SGetU(w)
|
goto single;
|
||||||
for (usz i = 0; i < xia; i++) mk_Sb(&set, GetU(x,i), &had);
|
}
|
||||||
u64* rp; B r = m_bitarrv(&rp, wia);
|
if (wr==1) goto many;
|
||||||
for (usz i = 0; i < wia; i++) bitp_set(rp, i, has_Sb(set, GetU(w,i)));
|
goto bad;
|
||||||
free_Sb(set); decG(w);decG(x);
|
|
||||||
|
bad: return c2(rt_memberOf, w, x);
|
||||||
|
|
||||||
|
B r;
|
||||||
|
single: {
|
||||||
|
usz xia = a(x)->ia;
|
||||||
|
SGetU(x)
|
||||||
|
for (usz i = 0; i < xia; i++) if (equal(GetU(x, i), w)) { r = inc(enclosed_1); goto dec_wx; }
|
||||||
|
r = inc(enclosed_0);
|
||||||
|
dec_wx:; dec(w);
|
||||||
|
goto dec_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
many: {
|
||||||
|
usz xia = a(x)->ia;
|
||||||
|
usz wia = a(w)->ia;
|
||||||
|
// TODO O(wia×xia) for small wia or xia
|
||||||
|
H_Sb* set = m_Sb(64);
|
||||||
|
SGetU(x) SGetU(w)
|
||||||
|
bool had;
|
||||||
|
for (usz i = 0; i < xia; i++) mk_Sb(&set, GetU(x,i), &had);
|
||||||
|
u64* rp; r = m_bitarrv(&rp, wia);
|
||||||
|
for (usz i = 0; i < wia; i++) bitp_set(rp, i, has_Sb(set, GetU(w,i)));
|
||||||
|
free_Sb(set); decG(w);
|
||||||
|
goto dec_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
dec_x:;
|
||||||
|
decG(x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,6 +400,8 @@ void profiler_freeMap(void* mapRaw) {
|
|||||||
void fun_gcFn() {
|
void fun_gcFn() {
|
||||||
if (prevImports!=NULL) mm_visitP(prevImports);
|
if (prevImports!=NULL) mm_visitP(prevImports);
|
||||||
if (globalNames!=NULL) mm_visitP(globalNames);
|
if (globalNames!=NULL) mm_visitP(globalNames);
|
||||||
|
mm_visit(enclosed_0);
|
||||||
|
mm_visit(enclosed_1);
|
||||||
mm_visit(globalNameList);
|
mm_visit(globalNameList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,4 +419,6 @@ void fns_init() {
|
|||||||
TIi(t_funBI,fn_uc1) = funBI_uc1;
|
TIi(t_funBI,fn_uc1) = funBI_uc1;
|
||||||
TIi(t_funBI,fn_ucw) = funBI_ucw;
|
TIi(t_funBI,fn_ucw) = funBI_ucw;
|
||||||
TIi(t_funBI,fn_im) = funBI_im;
|
TIi(t_funBI,fn_im) = funBI_im;
|
||||||
|
{ u64* p; Arr* a=m_bitarrp(&p, 1); arr_shAlloc(a,0); *p= 0; enclosed_0=taga(a); }
|
||||||
|
{ u64* p; Arr* a=m_bitarrp(&p, 1); arr_shAlloc(a,0); *p=~0ULL; enclosed_1=taga(a); }
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user