Skip to content

LZW rework

Sven M. Hallberg requested to merge lzw into master

A comprehensive polish, refactoring, rework pass over lzw.c.

Major changes:

  • Rather than defering code creation to the next cycle (when the following byte of input is known), new codes are created in sync with the encoder and only the addition of the last byte is defered. This makes the code much less complicated.
  • The table representation is changed from an array of pointers to HBytes to an "internally linked" fixed-size array of (conceptually) code-byte pairs. The string represented by a given code is found by traversing the resulting linked list of suffix bytes. Combined with other refactorings, this eliminates the extra uses of malloc().
  • (added 2022-12-20) Choosing the code word parser of the appropriate bit length is done using h_bind() rather than trying and failing a validation until the right size is found. This saves code and should run in less time and memory.

Includes some smaller bugfixes and a lot of style/comment tweaks.

Edited by Sven M. Hallberg

Merge request reports