squeeze •rand.Subset result

This commit is contained in:
dzaima 2022-09-01 18:25:10 +03:00
parent b386531b30
commit 1c43ad6431

View File

@ -461,19 +461,19 @@ B rand_deal_c2(B t, B w, B x) {
return r; return r;
} }
B ud_c1(B t, B w);
B rand_subset_c2(B t, B w, B x) { B rand_subset_c2(B t, B w, B x) {
i32 wi = o2i(w); i32 wi = o2i(w);
i32 xi = o2i(x); i32 xi = o2i(x);
if (RARE(wi<0)) thrM("(rand).Subset: 𝕨 cannot be negative"); if (RARE(wi<0)) thrM("(rand).Subset: 𝕨 cannot be negative");
if (RARE(xi<0)) thrM("(rand).Subset: 𝕩 cannot be negative"); if (RARE(xi<0)) thrM("(rand).Subset: 𝕩 cannot be negative");
if (RARE(wi>xi)) thrM("(rand).Subset: 𝕨 cannot exceed 𝕩"); if (RARE(wi>xi)) thrM("(rand).Subset: 𝕨 cannot exceed 𝕩");
if (wi==xi) {
if (wi==0) return emptyIVec(); if (wi==0) return emptyIVec();
B r; return ud_c1(t, x); // Only one complete subset; will hang without this
if (wi==xi) { // Only one complete subset; will hang without this
i32* rp; r = m_i32arrv(&rp, wi);
for (i64 i = 0; i < wi; i++) rp[i] = i;
return r;
} }
B r;
RAND_START; RAND_START;
if (wi > xi/8) { if (wi > xi/8) {
// Bit set (as bytes) // Bit set (as bytes)
@ -516,7 +516,7 @@ B rand_subset_c2(B t, B w, B x) {
TFREE(hash); TFREE(hash);
} }
RAND_END; RAND_END;
return r; return xi<=128? taga(cpyI8Arr(r)) : xi<=32768? taga(cpyI16Arr(r)) : r;
} }
#if USE_VALGRIND #if USE_VALGRIND