Sparse Indices prototype

This commit is contained in:
Marshall Lochbaum 2022-09-16 20:02:21 -04:00
parent 26c3dbfeea
commit fb1230bcc2
2 changed files with 20 additions and 17 deletions

View File

@ -35,16 +35,13 @@
TALLOC(usz, c0, C); usz *c0o=c0+C/2; \
for (usz j=0; j<C; j++) c0[j]=0; \
for (usz i=0; i<n; i++) c0o[xp[i]]++; \
if (n <= C*8) { /* Sum-based */ \
for (usz i=1; i<n; i++) rp[i]=0; \
GRADE_UD( \
rp[0]=-C/2; usz e=C-1; while (c0[e]==0) e--; \
for (usz j=0 , i=0; j<e; j++) { i+=c0[j]; rp[i]++; } \
, \
rp[0]=C/2-1; usz e=0; while (c0[e]==0) e++; \
for (usz j=C-1, i=0; j>e; j--) { i+=c0[j]; rp[i]--; } \
) \
for (usz i=1; i<n; i++) rp[i]+=rp[i-1]; \
if (n/16 <= C) { /* Sum-based */ \
for (usz i=0; i<n; i++) rp[i]=0; \
usz j=GRADE_UD(0,C-1), i; \
while ((i=c0[j])==0) GRADE_UD(j++,j--); \
usz js = j - C/2; \
while (i<n) { rp[i]++; i+=c0[GRADE_UD(++j,--j)]; } \
for (usz i=0; i<n; i++) js=rp[i]+=js; \
} else { /* Branchy */ \
FOR(j,C) for (usz c=c0[j]; c--; ) *rp++ = j-C/2; \
} \

View File

@ -374,13 +374,19 @@ B slash_c1(B t, B x) {
i32* rp; r = m_i32arrv(&rp, s);
if (xe==el_i8) {
i8* xp = i8any_ptr(x);
while (xia>0 && !xp[xia-1]) xia--;
for (u64 i = 0; i < xia; i++) {
i32 c = xp[i];
if (LIKELY(c==0 || c==1)) {
*rp = i;
rp+= c;
} else {
if (s/16 <= xia) {
usz b = 1<<10;
for (usz k=0, j=0, js=0, ij=xp[0]; ; ) {
usz e = b<s-k? k+b : s;
for (usz i=k; i<e; i++) rp[i]=0;
while (ij<e) { rp[ij]++; ij+=xp[++j]; }
for (usz i=k; i<e; i++) js=rp[i]+=js;
if (e==s) break; k=e;
}
} else {
while (xia>0 && !xp[xia-1]) xia--;
for (u64 i = 0; i < xia; i++) {
i32 c = xp[i];
for (i32 j = 0; j < c; j++) *rp++ = i;
}
}