Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help with Huffman Compression

Thread Tools

Help with Huffman Compression

lukabratzi lukabratzi is offline
Junior Member
Join Date: Jul 2010
Posts: 1
Hello everyone,

I've programmed my own implementation of Huffman Compression and Decompression, but am having trouble writing out my huffman tree to the compressed file's header. Everything works, and I can compress/decompress a number of files with no change in output, but many of my "compressed" files end up larger than the input files were.

The reason for this has to do with how I am writing out my huffman tree to the header. Right now, I am writing byte values of 0 to represent parent nodes, 1 to represent leaf nodes, and a 2 to represent my pseudo eof node. After each 1 I also write the character value associated with each node. Below is a link to my code for this method. I also included the method I use to rebuild the tree for decompression. It won't let me link to it so you'll have to copy paste it.
I think that I can fix this problem by writing 1 and 0 bits to represent my nodes and then following all 1 bits with the 8 bit value associated with each node. So I would end up with something like 001(8 bit value)00001(8 bit value).... My question is, how would I store my pseudo eof node?

Right now I have an array of 257 values so that I can store the frequencies of characters 0-255 and a pseudo eof ('char' 256). My issue is that I don't know how to write a char value of 256 to a file. If anyone has any insight or advice for me, it would be appreciated. This is the last bit of code I have to write before this project is done, but I'm having a hard time figuring it out.

I can upload more code if requested.

Thank you
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Huffman Compression C Programming 8 10-28-2005 05:48 AM
javax.imageio.IIOException: Missing Huffman code niko Java 3 02-12-2005 08:37 PM
Python Huffman encoding dot Python 3 11-30-2004 12:18 PM
Compression (besides Huffman) and Ruby Josef 'Jupp' SCHUGT Ruby 10 01-08-2004 01:23 AM
deflater/inflater and dictionnary for huffman NOBODY Java 2 10-17-2003 08:56 AM