-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
50 lines (43 loc) · 1.55 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
#include <unordered_map>
#include <fstream>
#include <time.h>
#include "MinHeapNode.h"
#include "huffman.cpp"
#include "freqTable.cpp"
using namespace std;
//extern unordered_map<char,string> codeMap;//codeMap created in MinHeap and used in huffman
int filesize(const char* filename)
{
ifstream in_file(filename, ios::binary);
in_file.seekg(0, ios::end);
int file_size = in_file.tellg();
return file_size;
}
int main(){
unordered_map<char, int> frequencyMap;
string Mode;
cout<<"Enter working mode: ";
cin >> Mode;
if(Mode == "compress")
{
clock_t tStart = clock();
frequencyMap = frequencyTable("FileToRead.txt");
createcodeMap(frequencyMap);
compressTofile("input.txt","compressed.txt");
cout <<"Time taken: "<<(1.0*(clock() - tStart)/CLOCKS_PER_SEC)<<"sec"<<endl;
cout << "Input File Size : "<<filesize("FileToRead.txt")<<" bytes."<<endl;
cout<< "Compressed File Size : "<<filesize("compressed.txt")<<" bytes."<<endl;
cout<< "Compression Ratio : "<<(1.0*filesize("compressed.txt")/filesize("FileToRead.txt"))<<endl;
}
else if(Mode == "decompress")
{
clock_t tStart = clock();
Decipher("compressed.txt","decompressed.txt");
cout <<"Time taken: "<<(1.0*(clock() - tStart)/CLOCKS_PER_SEC)<<"sec"<<endl;
cout << "Input File (Compressed) Size : "<<filesize("compressed.txt")<<" bytes."<<endl;
cout<< "DeCompressed File Size : "<<filesize("decompressed.txt")<<" bytes."<<endl;
}
return 0;
}