deep squeeze

This commit is contained in:
dzaima 2021-09-17 14:46:03 +03:00
parent 7f6740ec07
commit 663c318219
2 changed files with 16 additions and 0 deletions

View File

@ -569,6 +569,21 @@ B any_squeeze(B x) {
return x;
}
B squeeze_deep(B x) {
x = any_squeeze(x);
if (TI(x,elType)!=el_B) return x;
usz ia = a(x)->ia;
usz i=0; HArr_p r = m_harrs(ia,&i);
B* xp = arr_bptr(x);
if (xp!=NULL) {
while (i < ia) { r.a[i] = squeeze_deep(inc(xp[i])); i++; }
} else {
SGet(x);
while (i < ia) { r.a[i] = squeeze_deep(Get(x,i)); i++; }
}
return any_squeeze(harr_fcd(r, x));
}
B bqn_merge(B x) {
assert(isArr(x));
usz xia = a(x)->ia;

View File

@ -140,6 +140,7 @@ B bqn_merge(B x); // consumes
B any_squeeze(B x); // consumes; accepts any array, returns one with the smallest type (doesn't recurse!)
B num_squeeze(B x); // consumes; accepts any array, but only tries to squeeze numerical values; doesn't check for fl_squoze
B chr_squeeze(B x); // consumes; accepts any array, but only tries to squeeze character values; doesn't check for fl_squoze
B squeeze_deep(B x); // consumes; accepts any object, returns an object with all hashable parts squeezed
static inline B num_squeezeChk(B x) { return FL_HAS(x,fl_squoze)? x : num_squeeze(x); }
static inline B chr_squeezeChk(B x) { return FL_HAS(x,fl_squoze)? x : chr_squeeze(x); }
B def_fn_uc1(B t, B o, B x);