jibsen / brieflz

Small fast Lempel-Ziv compression library
zlib License
101 stars 18 forks source link

16-bit tags/flags #10

Closed odzhan closed 4 years ago

odzhan commented 4 years ago

Hello,

This compressor is awesome, so thanks for sharing your code. :)

Apologies in advance if this is not the right place to ask.

Is there any reason why you use 2 bytes for tags instead of 1? I implemented the depacker in 96 bytes, but was thinking it could be smaller (not much of course) if smaller tags used.

jibsen commented 4 years ago

Thanks, happy to hear you like it!

I guess at the time because I used 8-bit tags in aPLib, and some of the other compression libraries at the time were moving to 32-bit tags to improve speed. I wanted something that could still be implemented in little code on 16-bit x86, so 16-bit tags were the compromise.

One nice thing about using 16 rather than 8 bits is that because the literal bytes are interleaved with the tag bits, it is not possible to "peek" many bits ahead, but having up to 16 bits allowed sometimes using the lookup table in the decoder for speed.