Use the correct complement algorithm for the hash set
This commit is contained in:
parent
619b9827de
commit
3546419816
@ -326,11 +326,6 @@ B rand_subset_c2(B t, B w, B x) {
|
|||||||
bool invert = wi > xi/2;
|
bool invert = wi > xi/2;
|
||||||
i32 wn = invert ? xi-wi : wi;
|
i32 wn = invert ? xi-wi : wi;
|
||||||
RAND_START;
|
RAND_START;
|
||||||
#define FILTER(COND, SIZE, ELT) \
|
|
||||||
for (u64 i = 0; i < SIZE; i++) if (COND) *rp++=ELT;
|
|
||||||
#define OUTPUT(COND, S,E) \
|
|
||||||
i32* rp; r = m_i32arrv(&rp, wi); \
|
|
||||||
if (invert) { FILTER(!(COND), S,E); } else { FILTER(COND, S,E); }
|
|
||||||
if (wn > xi/8) {
|
if (wn > xi/8) {
|
||||||
// Bit set (as bytes)
|
// Bit set (as bytes)
|
||||||
TALLOC(u8, set, xi);
|
TALLOC(u8, set, xi);
|
||||||
@ -340,7 +335,9 @@ B rand_subset_c2(B t, B w, B x) {
|
|||||||
if (set[j]) j=i;
|
if (set[j]) j=i;
|
||||||
set[j] = 1;
|
set[j] = 1;
|
||||||
}
|
}
|
||||||
OUTPUT(set[i], xi, i);
|
i32* rp; r = m_i32arrv(&rp, wi);
|
||||||
|
if (!invert) { for (u64 i = 0; i < xi; i++) if ( set[i]) *rp++=i; }
|
||||||
|
else { for (u64 i = 0; i < xi; i++) if (!set[i]) *rp++=i; }
|
||||||
TFREE(set);
|
TFREE(set);
|
||||||
} else {
|
} else {
|
||||||
// Sorted "hash" set
|
// Sorted "hash" set
|
||||||
@ -363,11 +360,19 @@ B rand_subset_c2(B t, B w, B x) {
|
|||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OUTPUT(hash[i]!=xi, sz, hash[i]);
|
i32* rp; r = m_i32arrv(&rp, wi);
|
||||||
|
if (!invert) {
|
||||||
|
for (u64 i = 0; i < sz; i++) if (hash[i]!=xi) *rp++=hash[i];
|
||||||
|
} else {
|
||||||
|
i32 e = 0;
|
||||||
|
for (u64 i = 0; i < sz; i++) {
|
||||||
|
i32 f = hash[i];
|
||||||
|
if (f!=xi) { while (e<f) *rp++=e++; e++; }
|
||||||
|
}
|
||||||
|
while (e<xi) *rp++=e++;
|
||||||
|
}
|
||||||
TFREE(hash);
|
TFREE(hash);
|
||||||
}
|
}
|
||||||
#undef FILT
|
|
||||||
#undef OUTPUT
|
|
||||||
RAND_END;
|
RAND_END;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user