Help with Huffman Compression

Discussion in 'C Programming' started by lukabratzi, Jul 18, 2010.

  1. lukabratzi

    lukabratzi

    Joined:
    Jul 18, 2010
    Messages:
    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.
    Code:
    pastebin.ca/1903023
    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
     
    lukabratzi, Jul 18, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NOBODY
    Replies:
    2
    Views:
    817
    Thomas Weidenfeller
    Oct 17, 2003
  2. niko
    Replies:
    3
    Views:
    3,799
  3. dot

    Python Huffman encoding

    dot, Nov 25, 2004, in forum: Python
    Replies:
    3
    Views:
    1,796
    Guyon Morée
    Nov 30, 2004
  4. dirgesh@gmail.com

    Using Huffman Compression

    dirgesh@gmail.com, Oct 12, 2005, in forum: C Programming
    Replies:
    8
    Views:
    542
    Mabden
    Oct 28, 2005
  5. Josef 'Jupp' SCHUGT

    Compression (besides Huffman) and Ruby

    Josef 'Jupp' SCHUGT, Jan 7, 2004, in forum: Ruby
    Replies:
    10
    Views:
    266
    Joel VanderWerf
    Jan 8, 2004
Loading...

Share This Page