1

How does LZW decompress data with dictionary clearing/flushing? I understand that a space is reserved in the dictionary that represents a clear code (usually 256), but how is this code actually used when compressing and decompressing data? My thoughts for compression are that it checks the table size, and if the table size has reached the maximum size it appends the flush character to the output before resetting the dictionary. I'm not sure what it does for decompression though.

hakmad
  • 11
  • 1

2 Answers2

2

When the compressor clears the dictionary, it emits the clear code. This enables the decompressor to stay in sync: when it sees the clear code, the decompressor clears its own dictionary. In this way, the decompressor can reconstruct/infer the state of the encoder's dictionary at each step.

Wikipedia says:

Smart encoders can monitor the compression efficiency and clear the table whenever the existing table no longer matches the input well.

D.W.
  • 167,959
  • 22
  • 232
  • 500
0

Anybody who has worked on BOTH parts of LZW, that is, Compression and Decompression, knows they operate identically, building the same translation table from the stream. There is no need to send a flag code. They would both decide to reset the table at the same point.