Arithmetic Encoding vs Adaptive Arithmetic Encoding
The pseudocode looks good to me, except of course that in static arithmetic coding, you need to transmit the model before the decoder can use it.
Exactly how to do that in a space-efficient way is not obvious. One of the advantages of adaptive coding is that it gives you that for free: the loss of compression while the model is &quot;learning&quot; should be (if you did it correctly) exactly the minimal cost of transmitting the model.
But, of course, it's not free because updating an adaptive model isn't free. You pay for it in the CPU and memory efficiency of the encoder and decoder.