MTF + Zero-Run RLE
MTF + Zero-Run RLE Pipeline
Implement Move-to-Front (MTF) encoding/decoding and a zero-run RLE stage.
Functions
func MTFEncode(data []byte) []int
func MTFDecode(indices []int) []byte
func RLEZeroEncode(values []int) []int
func RLEZeroDecode(values []int) []int
func PipelineEncode(data []byte) []int
func PipelineDecode(values []int) []byte
MTF rules
- Maintain an ordered list of symbols 0..255.
- For each byte, output its index and move that symbol to the front.
- Decoding mirrors this process.
Zero-run RLE rules
- Input values are non-negative integers (MTF output).
- Replace any run of
k >= 1zeros with a single negative value-k. - Non-zero values are emitted unchanged.
- Decoding expands negative values back into that many zeros.
Pipeline
PipelineEncode=MTFEncodethenRLEZeroEncode.PipelineDecode=RLEZeroDecodethenMTFDecode.
Run tests to see results
No issues detected