test-me: text compression

This is a discussion on test-me: text compression within the C++ Programming forums, part of the General Programming Boards category; this program compresses text files using the huffman algorithm. please tell me what you think of it, and any critisism ...

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493

    test-me: text compression

    this program compresses text files using the huffman algorithm. please tell me what you think of it, and any critisism or compliments too.

    a couple of things to note:
    to run: huff-enc < file_to_compress
    this outputs out.ygc, the compressed file, and out.ygt, the lookup table.
    then run: huff-dec
    this inputs out.ygc and out.ygt and outputs out.ygf, the newly uncompressed file. note: be sure that all 3 output files are deleted before encoding a new file.

    because of the size restrictions of this board i haven't included executables with these programs. if you want the executables, see below

    huff3.cpp is included into each of the other files. eventually i will link it like a normal program. to compile, just compile huff-enc and huff-dec seperately. remember to keep the huff3.cpp file in the same directory.

    don't forget to tell me what you think (if you see bugs, report that too.)

    anyone who wants the binaries as well (windows 98 se) can download here:
    http://www.flashdaddee.com/forums/sh...&threadid=1990

    i've tested it on gcc 2.95.3 on redhat 7.2 linux (successfully), the borland free command line compiler under windows 98 se (successfully), and dev c++ 4 (successfully). borland gives me a fair share of warnings about unsigned to signed conversions, but that's not important.
    Attached Files Attached Files
    Last edited by ygfperson; 04-26-2002 at 05:51 PM.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    also, a question:
    this program is supposed to be able to compress anything in bytes (ie, binaries, too). but for some reason, after decompression of a binary file like an image or program, the file's much smaller, and corrupt. any idea on why this is happening?

  3. #3
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    howdy,
    i tryed it on RH 7.2 kernel 2.4.7-10 using gcc 2.96.
    it worked just fine, i had a file that started at 2247 before copression and after compression it was 1512 not counting the look up table. when i decompressed it it came just like the original.
    now i will disect your source code and steal any knowledge from it that i can.
    very very cool thanks for sharing your stuff

    M.R.

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    the file you compressed, was it a text file or a binary file?

    go ahead, steal. it's a huffman algorithm. in the future i'm going to change the table so it will compress smaller.
    a little help:

    class huffman_tree // a class with a vector array of nodes, and member functions to sort, search, organize into a huffman tree, etc

    class huff_table // a lookup table, basically a vector array for the letters, a vector<bool> for each binary, and member functions to encode and decode a string to it

    struct node // a node. it has a value (the letter), an amount (the frequency of the letter) and a pointer going up, and two going down the tree.
    if you are going to mess around with it please send me any changes, so i can make this better.

  5. #5
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    howdy,
    the file i compressed was a file of random words and text i created while i was talking on the phone.
    i created it in emacs and saved it with .txt extension. i'm not perfectly sure but i believe emacs saves this type of file as ascii text.

    M.R.

  6. #6
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    i'm not perfectly sure but i believe emacs saves this type of file as ascii text.
    yeah, i think so too. as stated before, binaries should but don't work. maybe it's the number of different ascii chars.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. test to binary & binary to text
    By wolfindark in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 05:29 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  4. mygets
    By Dave_Sinkula in forum C Programming
    Replies: 6
    Last Post: 03-23-2003, 06:23 PM
  5. Accessing a Specific Text Line Inside CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2002, 08:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21