/* Last edited on 2023-02-06 13:23:20 by stolfi */ ?? thuf_spread_vals(uint32_t nv, uint64_t vfreqs[]) { uint32_t nz = 10; /* Number of zero-freq extra values. */ uint64_t freqx[nv+nz]; /* Copy of {freq} with inserted zeros. */ uint32_t kv = 0; /* How many datums have been copied. */ uint32_t kz = 0; /* How many zeros have been inserted.*/ uint32_t nx = 0; /* Number of {freqx} slots filled. */ while ((kv < nv) || (kz < nz)) { if (kz*nv <= kv*nz) { freqx[nx] = 0; fprintf(stderr, "inserting zero at %d\n", nx); nx++; kz++; } else { freqx[nx] = vfreqs[kv]; nx++; kv++; } } assert(nx == nv + nz); /* Check consistency of {tick} with {freq}: */ uint64_t tot_weight = 0; uint32_t tot_leaves = 0; for (uint32_t iv = 0; iv < nv; iv++) { if (freq[iv] == 0) { fprintf(stderr, "** tree has leaf with {val} = %u and {freq[val]} = 0\n", iv); nbug++; } else { fprintf(stderr, "** value {val} = %u with {freq[val]} = %lu is not in tree\n", iv, freq[iv]); nbug++; tot_weight += freq[iv]; tot_leaves++; } } if (nbug == 0) { assert(tree_weight == tot_weight); assert(tree_leaves == tot_leaves); } else { demand(FALSE, "bad tree"); } return;