Thursday, May 31, 2007

Huffman Compression

Well, as mentioned above, I spend more time with coding in the last few weeks. I tried myself with my own implementation of Huffman Compression. (see Huffman Compression for more information).
While doing the huffman compression for a sentence with pen&paper is really easy and intuitive, writing a C programm is quite difficult: it took my really some time to build the huffman tree. Ok, I made two stupid typo-errors and linked the child leafes wrong... this resulted in time-consuming debugging. Well, sometimes I'm an idiot ;-)
But the compression itself was really hard! First I printed the huffman codes out as strings to be sure it works... not that big thing. But really save the codes as bits was pretty difficult and time-consuming and needed some fancy 'bit action'. Again, I made a stupid mistake by saving the codes in wrong direction in the compressed file, so decompressing failed for sure.
Finally, it works... but: it's really really slow and the compressed file is bigger than the original file cause of the overhead I save (the huffman tree). This must definitely optimized. But what sucks most is that my little programm hangs if compressing files larger than about 5MB. I fuckin' don't know why! So it will take some time till I will release the source on my site.
Have a nice weekend!

1 comment:

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!