-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuffman.h
More file actions
49 lines (39 loc) · 1.65 KB
/
Huffman.h
File metadata and controls
49 lines (39 loc) · 1.65 KB
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
#pragma once
#include "File.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <queue>
typedef struct HuffNode {
char key;
unsigned int frequency;
HuffNode* left;
HuffNode* right;
HuffNode(char _key, unsigned int _frequency, HuffNode* _left, HuffNode* _right)
: key(_key), frequency(_frequency), left(_left), right(_right) {}
bool operator<(const HuffNode& rhs) const
{
return frequency > rhs.frequency;
}
} HuffNode;
typedef struct SymbolCodePair {
char key;
std::string code;
SymbolCodePair(char _key, std::string _code)
: key(_key), code(_code) {}
} SymbolCodePair;
typedef struct HuffNodeComparator {
bool operator()(HuffNode* lhs, HuffNode* rhs) { return lhs->frequency > rhs->frequency; }
} HuffNodeComparator;
void PrintInorderTraversal(HuffNode* root);
void PrintDFS(HuffNode* root);
HuffNode* CreateMinHeap(const std::string& message);
bool isLeafNode(HuffNode* node);
void FindSymbolTable(HuffNode* root, std::string prevCode,std::vector<SymbolCodePair>& symbolTable);
std::string EncodeMessage(const std::string& message, const std::vector<SymbolCodePair>& symbolTable);
void SaveHuffmanData(const std::string& filepath, const std::vector<SymbolCodePair>& symbolTable, std::string& encodedMessage);
void HuffmanCompression(const std::string& inputFilepath, const std::string& outputFilepath);
void LoadHuffmanData(const std::string& filepath, std::vector<SymbolCodePair>& symbolTable, int& encodedMessageLength,std::string& encodedMessage);
void HuffmanDecompression(const std::string& inputFilepath, const std::string& outputFilepath);