in lattices/lattice_utils.cpp [95:124]
static long repeats_encode_64 (
const std::vector<Repeat> & repeats,
int dim, const float *c)
{
uint64_t coded = 0;
int nfree = dim;
uint64_t code = 0, shift = 1;
for (auto r = repeats.begin(); r != repeats.end(); ++r) {
int rank = 0, occ = 0;
uint64_t code_comb = 0;
uint64_t tosee = ~coded;
for(;;) {
// directly jump to next available slot.
int i = __builtin_ctzl(tosee);
tosee &= ~(1UL << i) ;
if (c[i] == r->val) {
code_comb += comb(rank, occ + 1);
occ++;
coded |= 1UL << i;
if (occ == r->n) break;
}
rank++;
}
uint64_t max_comb = comb(nfree, r->n);
code += shift * code_comb;
shift *= max_comb;
nfree -= r->n;
}
return code;
}