def huff.counts
import gralha-bytes@0.1.0.1/bytes.bend as Bytesimport Base
import gralha-text-scan@0.1.0.1/scan.bend as U
160def huff.counts(n: Nat, +lengths: Bytes, +index: U32, +counts: Bytes) -> Bytes:
161 match n:
162 case 0n: counts
163 case 1n+d:
164 +len = bytes.get(lengths, index)
165 huff.counts(d, lengths, U32.inc(index), U.choose(Bytes, U32.is_gt(len, 0) && U32.is_le(len, 15), bytes.set(counts, len, U32.inc(bytes.get(counts, len))), counts))