FAQ of Project 2


Questions about Map

  1. How to traverse the map?
    Say i is a iterator. You can use the following way to traverse the map.
    for( i = _charmap.begin();i != _charmap.end(); ++i )
    { ... }
    Use (*i).second to access the huffnode pointer.

  2. I was wondering how to access the huffnodes after you place it in the map. How do you increment the count?
    Use _charmap.find(key) first. It will return an iterator. If this iterator is not equal to _charmap.end(), it means the key is in the map. Then you can use (*iterator).second to access the huffnode pointer. In the class huffnode, there is a data member named _count. You have to increment this variable to count how many times the charater has appeared.

Questions related to huffnode.h

  1. What should we do about the file huffnode.h?
    The class "huffnode" is not completely defined. You have to add member functions to access or change the protected data members of the class, such as _bits, _count, etc. You also have to finish constructor
    huffnode( huffnode* l, huffnode* r ) : _type(internal), _char(0), _bits() { .... }

Questions related to hufftree.h

  1. How to set _bits to correct values?
    You can do it in two ways.

  2. What's the format of the encoded file?
    The format is :
            Header           //The string "HuffEnCoded"
            CharCount        //Number of distinct characters in the file.
            Character Table  //A CharCount number of entries, each of the form 
                             //"UCHAR Count", where UCHAR is an unsigned char and
                             //Count is the number of its occurrence in the 
                             //Huffman encoded data.
            Huffman Data     //A stream of binary Huffman-codes of variable length.
       
    What I have to emphasize is CharCount and Count should be in binary form. For example, say CharCount is 123. We know that 0x31 is the ASCII code for character "1", 0x32 is that of "2", 0x33 is that of "3". So if you save CharCount as ASCII form ( when using << operator ), it will be "0x31","0x32","0x33". But if you save it as binary form ( when using ostream::write() ) it will be "0x00","0x00","0x00","0x7b", since in our system, type int is 32 bits long. You may ask why should we adopt binary form? What the advantage? When using ASCII, four bytes can only express value between 0 and 9999. But when using binary form, the value can be up to 4 billion ( 2 to the power 32 ).
    See some refence book about C++, the answer lies in the member function write() and read() of the class istream and ostream.

Other Questions

  1. Could you clarify how you give points for "comments and style"?
    I have add these additional information in the "Grading Scheme" of project two's home page.

  2. Which files are we to submit?
    huffnode.h, hufftree.h, encode.C, decode.C. If you have written some other files, submit them.

Comments or Questions

Back to Project 2