Static Arithmetic Coding
Static Arithmetic (Range) Coding
Implement a static arithmetic coder using fixed frequencies.
Functions
func BuildFrequencies(data []byte) []int
func ArithmeticEncode(data []byte, freqs []int) []byte
func ArithmeticDecode(encoded []byte, freqs []int) []byte
Behavior
freqshas length 257 (symbols 0..255 plus EOF at index 256).BuildFrequenciescounts bytes indataand setsfreqs[256] = 1.ArithmeticEncodeencodesdatafollowed by an explicit EOF symbol.ArithmeticDecodedecodes until EOF is seen.
Constraints
- Total frequency sum must fit within 20 bits (sum <= 1<<20).
- Input length <= 4096 (to keep arithmetic ranges safe).
Notes
- Use a fixed-precision arithmetic coder with renormalization and underflow handling.
- Bitstream is MSB-first; trailing zero padding is allowed.
Run tests to see results
No issues detected