Unify search function preambles, so all have empty and rank>1 cases

This commit is contained in:
Marshall Lochbaum 2022-08-24 11:00:49 -04:00
parent 9d402c1bdd
commit efe2e86271

View File

@ -5,8 +5,9 @@
B memberOf_c1(B t, B x) {
if (isAtm(x) || RNK(x)==0) thrM("∊: Argument cannot have rank 0");
if (RNK(x)!=1) x = toCells(x);
if (RNK(x)>1) x = toCells(x);
usz xia = IA(x);
if (xia==0) { decG(x); return emptyIVec(); }
u8 xe = TI(x,elType);
#define LOOKUP(T) \
@ -82,6 +83,7 @@ B count_c1(B t, B x) {
if (isAtm(x) || RNK(x)==0) thrM("⊒: Argument cannot have rank 0");
if (RNK(x)>1) x = toCells(x);
usz xia = IA(x);
if (xia==0) { decG(x); return emptyIVec(); }
u8 xe = TI(x,elType);
#define LOOKUP(T) \
@ -110,11 +112,12 @@ B count_c1(B t, B x) {
extern B rt_indexOf;
B indexOf_c1(B t, B x) {
if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0");
if (isAtm(x) || RNK(x)==0) thrM("⊐: 𝕩 cannot have rank 0");
if (RNK(x)>1) x = toCells(x);
usz xia = IA(x);
if (xia==0) { decG(x); return emptyIVec(); }
u8 xe = TI(x,elType);
#define LOOKUP(T) \
usz tn = 1<<T, n = xia; \
u##T* xp = (u##T*)i##T##any_ptr(x); \
@ -128,11 +131,11 @@ B indexOf_c1(B t, B x) {
} \
decG(x); TFREE(tab); \
return r
if (RNK(x)==1 && xia>=16 && xe==el_i8 && xia<=(usz)I32_MAX+1) { LOOKUP(8); }
if (RNK(x)==1 && xia>=256 && xe==el_i16 && xia<=(usz)I32_MAX+1) { LOOKUP(16); }
if (xia>=16 && xe==el_i8 && xia<=(usz)I32_MAX+1) { LOOKUP(8); }
if (xia>=256 && xe==el_i16 && xia<=(usz)I32_MAX+1) { LOOKUP(16); }
#undef LOOKUP
if (RNK(x)==1 && xe==el_i32) {
if (xe==el_i32) {
i32* xp = i32any_ptr(x);
i32 min=I32_MAX, max=I32_MIN;
for (usz i = 0; i < xia; i++) {
@ -156,8 +159,7 @@ B indexOf_c1(B t, B x) {
return r;
}
}
// if (RNK(x)==1) { // relies on equal hashes implying equal objects, which has like a 2⋆¯64 chance of being false per item
// // u64 s = nsTime();
// // relies on equal hashes implying equal objects, which has like a 2⋆¯64 chance of being false per item
// i32* rp; B r = m_i32arrv(&rp, xia);
// u64 size = xia*2;
// wyhashmap_t idx[size];
@ -172,11 +174,7 @@ B indexOf_c1(B t, B x) {
// rp[i] = val[p];
// }
// dec(x);
// // u64 e = nsTime(); q1+= e-s;
// return r;
// }
if (RNK(x)==1) {
// u64 s = nsTime();
i32* rp; B r = m_i32arrv(&rp, xia);
H_b2i* map = m_b2i(64);
SGetU(x)
@ -187,18 +185,16 @@ B indexOf_c1(B t, B x) {
else rp[i] = map->a[p].val = ctr++;
}
free_b2i(map); decG(x);
// u64 e = nsTime(); q1+= e-s;
return r;
}
return c1(rt_indexOf, x);
}
extern B rt_find;
B find_c1(B t, B x) {
if (isAtm(x) || RNK(x)==0) thrM("⍷: Argument cannot have rank 0");
if (RNK(x)>1) return c1(rt_find, x);
usz xia = IA(x);
if (xia<=1) return x;
B xf = getFillQ(x);
if (RNK(x)!=1) return c1(rt_find, x);
B r = emptyHVec();
H_Sb* set = m_Sb(64);