fast ⍷𝕩 & ∊𝕩 on fl_asc+fl_dsc 𝕩
This commit is contained in:
parent
7eb9212388
commit
7326348c79
@ -42,6 +42,7 @@ extern B ud_c1(B, B);
|
||||
extern B sub_c2(B, B, B);
|
||||
extern B mul_c2(B, B, B);
|
||||
extern B indexOf_c2(B, B, B);
|
||||
extern B take_c2(B, B, B);
|
||||
extern B scan_add_bool(B x, u64 ia);
|
||||
extern B scan_max_num(B x, u8 xe, u64 ia);
|
||||
|
||||
@ -59,6 +60,13 @@ extern NOINLINE void memset64(u64* p, u64 v, usz l);
|
||||
#define TRY_HASHTAB_RET(NAME, W, RET) (void)0;
|
||||
#endif
|
||||
|
||||
static u8 fast_sameness(B x, u8 xe) { // 0: unknown; 1: all same; 2: all different
|
||||
assert(IA(x)>0);
|
||||
if (!FL_HAS_ALL(x, fl_asc|fl_dsc)) return 0;
|
||||
B x0 = IGetU(x,0);
|
||||
return equal(x0, x0)? 1 : 2;
|
||||
}
|
||||
|
||||
static inline bool use_sorted(B x, u8 logw) {
|
||||
if (!FL_HAS(x, fl_asc|fl_dsc)) return 0;
|
||||
if (logw==6) return TI(x, elType) == el_f64;
|
||||
@ -161,10 +169,18 @@ B memberOf_c1(B t, B x) {
|
||||
rp[0]=1; if (i<n) bitp_set(rp, i, 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
u8 sameness = fast_sameness(x, TI(x,elType));
|
||||
if (sameness == 1) goto allSame;
|
||||
if (RARE(sameness == 2)) {
|
||||
decG(x);
|
||||
return taga(arr_shVec(allOnes(n)));
|
||||
}
|
||||
|
||||
if (use_sorted(x, lw)) {
|
||||
return shift_ne(x, n, lw, 1);
|
||||
}
|
||||
#define BRUTE(T) \
|
||||
#define BRUTE(T) assert(n <= 64); \
|
||||
i##T* xp = xv; \
|
||||
u64 rv = 1; \
|
||||
for (usz i=1; i<n; i++) { \
|
||||
@ -258,6 +274,7 @@ B memberOf_c1(B t, B x) {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
allSame:;
|
||||
decG(x);
|
||||
Arr* r = allZeroes(n);
|
||||
bitarrv_ptr((TyArr*) r)[0] = 1;
|
||||
@ -498,6 +515,9 @@ B find_c1(B t, B x) {
|
||||
usz n = *SH(x);
|
||||
if (n<=1) return x;
|
||||
u8 xe = TI(x,elType);
|
||||
u8 sameness = fast_sameness(x, xe);
|
||||
if (sameness == 1) return C2(take, m_i32(1), x);
|
||||
if (RARE(sameness == 2)) return x;
|
||||
if (xe==el_bit && RNK(x)==1) {
|
||||
u64* xp = bitany_ptr(x);
|
||||
u64 x0 = 1 & *xp;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user