For my personal project, I am writing a small class to compress and decompress from a rather obscure format. I have a full specification, but that is not a problem.
First, this “format” uses a set of 6 different types of compression, as well as uncompressed blocks of byte data. Formats: RLE, RLE branch, where the number increases byte each (for example, 3, 4, 5, ...), 16-bit RLE, LZ-Copy, LZ reverse copy, and LZ-Copy Xor'd from 255. This not the cleanest of the specs, but I didn't design it either.
It is assumed that my compression procedure will take an array from 1 to 65535 bytes and (hopefully) compress it as much as possible. My previous attempt at this is simply calculated, starting from any index in an uncompressed stream, which of the above compression methods will provide the best compression, and then compresses the total number of bytes that this method compresses to an array of compressed bytes, before repeating from a new "uncompressed" index, eg:
{0,0,0,1,2,3,4}
At first, the algorithm had to read that at the beginning there were three zeros, and then output the RLE encoding for them, which was used by spec, and then, starting from the fourth element, read that the RLE increment would cover '1,2, 3,4' enough and squeeze that before returning.
, , , (20-30) . - , , - , , ?