-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuffmanCode.h
60 lines (52 loc) · 1.39 KB
/
HuffmanCode.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef HUFFMANCODE_H
#define HUFFMANCODE_H
using namespace std;
#include <string>
#include<map>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include "HuffmanNode.h"
using std::string;
using std::map;
class HuffmanCode{
private:
map<char, int> charFrequency;
map<char, string> huffmanMap;
//The Compare struct
//Used to compare 2 differnt nodes together by their count
struct compareStruct {
public:
bool operator()(const HuffmanNode* one, const HuffmanNode* two){
return one->getCount() > two->getCount();
}
};
//Declaring priority queue
priority_queue<HuffmanNode*, vector<HuffmanNode*>, compareStruct> huffmanQueue;
string poem;
string zerosAndOnes;
HuffmanNode *root;
int extraZeros = 0;
public:
HuffmanCode();
~HuffmanCode();
void readData();
void displayData();
void createQueue();
void createTable();
void display();
void encodeHuffmanTable(HuffmanNode *, string);
void encodeString();
void decodeString(string);
void setRoot(HuffmanNode *a) {root = a;};
HuffmanNode* getRoot() { return root;};
string getChar() {return poem;};
string getEncodedString() {return zerosAndOnes;};
void displayTable();
void displayHuffmanTable();
void decodeFile();
void compressFile();
void decompressFile();
};
#endif