I have a code which implements Huffman coding to encode texts.
Given the following text
abbccc
My program generates the following table
a -> 00
b -> 01
c -> 1
So the encoded text (bit array) is
000101111
The problem is: I need to encode the table together with the text and I do not know what is the recommended approach for this.
What I have thought so far:
- First byte is the number N of key-value pairs in table
- Following N*2 bytes are the key-value pairs themselves (one byte for key, one byte for value)
- Remaining bits are the encoded text itself
Could you suggest me some more flexible yet inexpensive (low memory usage) approach for this?