Objets/Documentation
motif_address.py
Address prépare des compteurs de complétions par fibre. unrank(k) reconstruit un départ en ordre interne. sorted_small() reconstruit puis trie les événements quand leur nombre reste sous le plafond.
Télécharger ↓"""Direct rank/unrank of coverage-constrained motifs in an internal CRT order.
Uses a shared canonical DP; optional localized count by branch bounds.
"""
from collections import Counter
from functools import lru_cache
from math import gcd,prod
from bisect import bisect_left
from motifs import primes,tail
class CoverFiber:
def __init__(self,ps,hs,g):
self.ps=tuple(ps);self.hs=tuple(hs);self.full=(1<<len(hs))-1
self.opts=[];self.agg=[];self.sizes=[];self.bad=[];self.multi=[]
for p in ps:
op=[(a,sum(1<<j for j,h in enumerate(hs) if (a+h)%p==0)) for a in range(p) if a and (a+g)%p]
cnt=Counter(b for a,b in op);self.opts.append(op);self.agg.append(tuple(cnt.items()));self.sizes.append(len(op))