# LZH Compression

This topic is 5479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've just finished up a huffman compression file packer and am rather disappointed with the level of compression when dealing with binary data. LZH seems like the next logical step as it would offer better compression and uses a familar technique (the h stands for huffman.) I can't seem to find any good articles on how this compression works and would appreciate it if I could get pointed in the right direction.

This might help.

##### Share on other sites
Yes I've looked there already :/

The problem with those links is that none offer an explanation of what the algorithm is. I'd rather have an explanation than a code example. That said, I can deal with a code example if it is commented (I'd rather understand that just perform a copy paste.) Some of those links have code examples but none are commented and are also in pascal. I don't understand a alot of the syntax that I see there.

So what I'm looking for is a link to an explanation, a code example in C++, or an explanation from one of the forums members if they would be so gracious :D

##### Share on other sites
Well it's been a while since I've looked at it so I can't really give you an in depth explanation, but IIRC the basic idea behind LZH is that it uses dynamic huffman codes instead of the static ones you'd be using currently. Think of it this way, as you move through a block of data the probability of any one symbol appearing isn't constant. For example, the number 10 might occur regularly in the first half of a file but not at all in the second half.

To do this you use what is called a sliding window. For any symbol, the hoffman code for that symbol is determined only from the probabilities in the current window, not from the entire file. Here, take a look at some dodgy ASCII art.....
                               currently encoding                                          |data:   0 1 2 3 1 2 3 1 2 3 0 0 0 1 0 0 2 0                    |<----window----->|

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46