diff --git a/src/fns.c b/src/fns.c index cd9c59a0..ba1ec3af 100644 --- a/src/fns.c +++ b/src/fns.c @@ -223,30 +223,30 @@ B indexOf_c1(B t, B x) { if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0"); usz xia = a(x)->ia; if (xia==0) { dec(x); return inc(bi_emptyIVec); } - // if (rnk(x)==1 && TI(x).elType==el_i32) { - // i32* xp = i32any_ptr(x); - // i32 min=I32_MAX, max=I32_MIN; - // for (usz i = 0; i < xia; i++) { - // i32 c = xp[i]; - // if (cmax) max = c; - // } - // i32 dst = 1 + max-(i64)min; - // if ((dstmax) max = c; + } + i32 dst = 1 + max-(i64)min; + if ((dstia; + usz xia = a(x)->ia; + // TODO O(wia×xia) for small wia + i32* rp; B r = m_i32arrv(&rp, xia); + H_b2i* map = m_b2i(64); + BS2B xgetU = TI(x).getU; + BS2B wgetU = TI(w).getU; + for (usz i = 0; i < wia; i++) { + bool had; u64 p = mk_b2i(&map, wgetU(w,i), &had); + if (!had) map->a[p].val = i; + } + for (usz i = 0; i < xia; i++) rp[i] = getD_b2i(map, xgetU(x,i), wia); + free_b2i(map); dec(w); dec(x); + return r; } B rt_memberOf; diff --git a/src/hashmap.c b/src/hashmap.c index 02548af2..0aedd0b3 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -81,6 +81,14 @@ static inline bool N(has) (Map* m, KT k) { N(find)(m, k, h1, h2, &has); return has; } +#ifdef VALS + static inline u64 N(getD) (Map* m, KT k, VT def) { + bool has; + u64 h1 = H1(k); u64 h2 = H2(k, h1); + u64 p = N(find)(m, k, h1, h2, &has); + return has? m->a[p].val : def; + } +#endif static inline void N(qins) (Map* m, u64 h1, HT h2, KT k IFVAL(, VT v)) { // if guaranteed that k doesn't exist in the map yet and there's space for this