LZW compression/decompression under low memory conditions

前端 未结 8 1221
Happy的楠姐
Happy的楠姐 2020-12-14 05:13

Can anybody give pointers how I can implement lzw compression/decompression in low memory conditions (< 2k). is that possible?

8条回答
  •  无人及你
    2020-12-14 05:40

    The lowest dictionary for lzw is trie on linked list. See original implementation in LZW AB. I've rewrited it in fork LZWS. Fork is compatible with compress. Detailed documentation here.

    n bit dictionary requires (2 ** n) * sizeof(code) + ((2 ** n) - 257) * sizeof(code) + (2 ** n) - 257.

    So:

    1. 9 bit code - 1789 bytes.
    2. 12 bit code - 19709 bytes.
    3. 16 bit code - 326909 bytes.

    Please be aware that it is a requirements for dictionary. You need to have about 100-150 bytes for state or variables in stack.

    Decompressor will use less memory than compressor.

    So I think that you can try to compress your data with 9 bit version. But it won't provide good compression ratio. More bits you have - ratio is better.

提交回复
热议问题