This is a simple example implementation of tANS encoding.
- Create a
std::stringwith the data to be encoded. - Create a
std::vector<char>with all unique symbols in the string. - Create a
std::vector<int>with the frequencies of occurences for the symbols, normalized to a power of 2.
- Note: Frequencies cannot be 0. Program may behave unexpectedly then.
- Call
std::vector<DecodeCol> decodeTable = createDecodingTable(symbols, frequencies). - Call
std::vector<EncodeCol> encodeTable = createEncodingTable(decodeTable, symbols). - Do your operations.
EncodedData data = encodeString(stringToEncode, encodeTable)for encoding.std::string decodedString = decodeString(&data, decodeTable, numCharsToDecode)to decodenumCharsToDecodefromdata.