Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If I had to guess, it’s a matter of setting up the Huffman tables such that every code ends up with a length of four bits, and then prepending that precomputed Huffman table onto the “compressed” stream. Then you can abuse the zlib library as a decompressor mapping the 4-bit “Huffman” codes to regular bytes.

Of course, this won’t be anywhere near as efficient as just implementing the decoder in C, as Huffman decoding needs to be much more general than just unpacking fixed-width chunks. But it will definitely be an improvement over naive loops.

I wonder whether .hex() could be pressed into service as a very scuffed 4-bit unpacker? Maybe something like .hex().encode().translate() to get an arbitrary palette mapping?



Yup, that's pretty much exactly it.

.hex() is a good idea, and probably has a decent chance of beating gzip, assuming .translate() is fast enough.

The fastest approach for the bitsliced AES impl ended up being pretty cursed: https://github.com/DavidBuchanan314/python-bitsliced-aes/blo...


> Of course, this won’t be anywhere near as efficient as just implementing the decoder in C

> It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can’t be done directly in Python: they can implement new built-in object types, and they can call C library functions and system calls.

Then why are you talking about this instead of extension modules?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: