From b2992a11b89c1f92e2c455eb19c4fe915f872291 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 25 Aug 2022 10:46:19 -0400 Subject: [PATCH] =?UTF-8?q?1-=20and=202-byte=20methods=20for=20monadic=20?= =?UTF-8?q?=E2=8A=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/selfsearch.c | 47 +++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index 2c219045..fa2a466b 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -91,6 +91,7 @@ B count_c1(B t, B x) { if (isAtm(x) || RNK(x)==0) thrM("⊒: Argument cannot have rank 0"); usz n = *SH(x); if (n==0) { decG(x); return emptyIVec(); } + if (n>(usz)I32_MAX+1) thrM("⊒: Argument length >2⋆31 not supported"); if (RNK(x)>1) x = toCells(x); u8 xe = TI(x,elType); @@ -113,10 +114,8 @@ B count_c1(B t, B x) { for (usz i=0; i(usz)I32_MAX+1) thrM("⊐: Argument length >2⋆31 not supported"); if (RNK(x)>1) x = toCells(x); u8 xe = TI(x,elType); + #define BRUTE(T) \ + i##T* xp = i##T##any_ptr(x); \ + i8* rp; B r = m_i8arrv(&rp, n); rp[0]=0; \ + TALLOC(i##T, uniq, n); uniq[0]=xp[0]; \ + for (usz i=1, u=1; i8 && n=16 && xe==el_i8 && n<=(usz)I32_MAX+1) { LOOKUP(8); } - if (n>=256 && xe==el_i16 && n<=(usz)I32_MAX+1) { LOOKUP(16); } + if (xe==el_i8) { if (n<12) { BRUTE(8); } else { LOOKUP(8); } } + if (xe==el_i16) { if (n<12) { BRUTE(16); } else { LOOKUP(16); } } #undef LOOKUP if (xe==el_i32) { + if (n<32) { BRUTE(32); } i32* xp = i32any_ptr(x); i32 min=I32_MAX, max=I32_MIN; for (usz i = 0; i < n; i++) { @@ -225,6 +237,7 @@ B indexOf_c1(B t, B x) { return r; } } + #undef BRUTE // // 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, n); // u64 size = n*2;