Merge remote-tracking branch 'mlochbaum/subset'

This commit is contained in:
dzaima 2022-11-02 23:17:56 +02:00
commit 70e7dcf38a
2 changed files with 26 additions and 7 deletions

View File

@ -363,6 +363,22 @@ static NOINLINE B zeroCells(B x) { // doesn't consume
return r;
}
void filter_ne_i32(i32* rp, i32* xp, usz len, usz sum, i32 val) {
usz b = bsp_max; TALLOC(i16, buf, b + b/16);
u64* wp = (u64*)(buf + b);
i32* rp0=rp;
CmpASFn cmp = CMP_AS_FN(ne, el_i32); B c = m_i32(val);
for (usz i=0; i<len; i+=b) {
bool last = b>len-i; if (last) b=len-i;
CMP_AS_CALL(cmp, wp, xp, c, b);
usz bs = last? sum-(rp-rp0) : bit_sum(wp,b);
where_block_u16(wp, (u16*)buf, b, bs);
for (usz j=0; j<bs; j++) rp[j] = xp[buf[j]];
rp+= bs; xp+= b;
}
TFREE(buf)
}
extern B take_c2(B, B, B);
static B compress(B w, B x, usz wia, u8 xl, u8 xt) {
u64* wp = bitarr_ptr(w);

View File

@ -461,6 +461,9 @@ B rand_deal_c2(B t, B w, B x) {
}
B ud_c1(B t, B x);
B slash_c1(B t, B x);
extern void filter_ne_i32(i32* dst, i32* src, usz len, usz sum, i32 val); // slash.c
B rand_subset_c2(B t, B w, B x) {
i32 wi = o2i(w);
i32 xi = o2i(x);
@ -474,7 +477,7 @@ B rand_subset_c2(B t, B w, B x) {
RAND_START;
if (wi > xi/8) {
// Bit set (as bytes)
TALLOC(u8, set, xi);
i8* set; B s = m_i8arrv(&set, xi);
bool invert = wi > xi/2;
i32 wn = invert ? xi-wi : wi;
for (i64 i = 0; i < xi; i++) set[i] = 0;
@ -483,10 +486,9 @@ B rand_subset_c2(B t, B w, B x) {
if (set[j]) j=i;
set[j] = 1;
}
i32* rp; r = m_i32arrv(&rp, wi);
if (!invert) { for (i64 i = 0; i < xi; i++) if ( set[i]) *rp++=i; }
else { for (i64 i = 0; i < xi; i++) if (!set[i]) *rp++=i; }
TFREE(set);
s = taga(cpyBitArr(s));
if (invert) s = bit_negate(s);
return slash_c1(t, s);
} else {
// Sorted "hash" set
u64 sh = 0;
@ -509,11 +511,12 @@ B rand_subset_c2(B t, B w, B x) {
}
}
i32* rp; r = m_i32arrv(&rp, wi);
for (u64 i = 0; i < sz; i++) if (hash[i]!=xi) *rp++=hash[i];
filter_ne_i32(rp, hash, sz, wi, xi);
TFREE(hash);
r = xi<=128? taga(cpyI8Arr(r)) : xi<=32768? taga(cpyI16Arr(r)) : r;
}
RAND_END;
return xi<=128? taga(cpyI8Arr(r)) : xi<=32768? taga(cpyI16Arr(r)) : r;
return r;
}
#if USE_VALGRIND