/****************************************************************************************************/ /* This class Written by Sourena Maroofi maroofi[at]Gmail.com */ /* simple and easy to use class implementing huffman algorithm to En/Decode file... */ /* use it like this: */ /* */ /* int main() */ /* { */ /* make a class instance.get file1 as input and write output to file2 */ /* huffman instance1("file1","file2"); */ /* instance1.encode(); */ /* get file2 as a compress file and decompress and save it to file1 */ /* huffman instance2("file2","file1"); */ /* instance2.decode(); */ /* return 0; */ /* } */ /* */ /* USE IT AT YOUR OWN RISK,I'M NOT RESPONSIBLE FOR ANY DAMAGE OR LOSS OF DATA */ /* CAUSED BY THIS CLASS.......... */ /* */ /* */ /* */ /* */ /* */ /****************************************************************************************************/ #include "stdafx.h" #include //for cout and cin #include //manipulating input output using hex and dec #include //using string variable #include "bitio.h" //input output bitoperation using this class in current directory #include //working with input and output file #include //using vector template #ifndef huffman_h #include "huffman.h" #endif using namespace std; /**************************************************************************************/ huffman::huffman(char const * inputFileName,char const * outputFileName) { vec.resize(VEC_SIZE); errorMessage="No Error Yet!!!"; print_detail=false; error_occured=false; this->inputFileName=inputFileName; this->outputFileName=outputFileName; for (int i=0;i "< "< "< probilities -> code -> code length : "< 1 ) { //cout< maxCodeLen) { maxCodeLen=vec[i].len; } } } if (print_detail==true) { cout<32) { cout<<"can not encode with length greater than 32...maybe next version"<> 1; } } } } huffOut.flushBuffer(); return; } /********************************************************************************************/ void huffman::generateHuffmanCode(unsigned char * nrcode,unsigned char * values,int maxCodeLen) { int minCodeLen; unsigned long int codeLen,temp; minCodeLen=maxCodeLen; for (int i=0;i