> So, assuming long enough stationary data, unary coding with an
> independent linear counter per flag should achieve the same
> compression ratio as bytewise coding with linear counting?
Yes, with dynamic ranking and counter update parameters tuned for each rank
its quite likely - in fact it should be better for binary data,
because updating multiple counters per symbol provides faster adaptation.
But its impractical.
Dynamic ranking is a must, because otherwise you'd have to encode 254 bits
for each 0xFF byte.
And dynamic ranking means that we'd have to recompute the probabilities:
so we have to store probabilities as doubles for good precision,
rank1p=p1; // symbol!='a' flag
rank2p=p2; // symbol!='b' flag
// ranks of 'a' and 'b' are swapped:
rank1p=p2*(1-p1); // symbol!='b' flag
rank2p=p1/(1-p2*(1-p1)); // symbol!='a' flag
or we lose compression if precision is bad,
and either way multiple extra divisions and multiplications per symbol are bad.