void Repeats::decode()

in lattices/lattice_utils.cpp [205:238]


void Repeats::decode(uint64_t code, float *c) const
{
    if (dim < 64) {
        repeats_decode_64 (repeats, dim, code, c);
        return;
    }

    std::vector<bool> decoded(dim, false);
    int nfree = dim;
    for (auto r = repeats.begin(); r != repeats.end(); ++r) {
        uint64_t max_comb = comb(nfree, r->n);
        uint64_t code_comb = code % max_comb;
        code /= max_comb;

        int occ = 0;
        int rank = nfree;
        int next_rank = decode_comb_1 (&code_comb, r->n, rank);
        for (int i = dim - 1; i >= 0; i--) {
            if (!decoded[i]) {
                rank--;
                if (rank == next_rank) {
                    decoded[i] = true;
                    c[i] = r->val;
                    occ++;
                    if (occ == r->n) break;
                    next_rank = decode_comb_1 (
                         &code_comb, r->n - occ, next_rank);
                }
            }
        }
        nfree -= r->n;
    }

}