-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (34 loc) · 1.05 KB
/
main.cpp
File metadata and controls
46 lines (34 loc) · 1.05 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
#include <vector>
#include <unordered_map>
#include <cstdint>
#include <string>
#include "main.hpp"
#include "frequencyOrder.hpp"
#include "Node.hpp"
#include "huffmanCoding.hpp"
#include "output.hpp"
using namespace std;
int byte_compress(uint8_t * data_ptr, int data_size) {
vector<Node> v;
frequencyOrder(v, data_ptr, data_size);
// Build Huffman tree
Node * parent = buildHuffmanTree(v);
// Fill in encodings in tree
parent->encode("0");
unordered_map<uint8_t, string> encodings;
createEncodingTable(parent, encodings);
outputEncodingTable(encodings);
outputOriginal(data_ptr, data_size);
outputEncoded(data_ptr, data_size, encodings);
// Free allocated memory
deallocateNodes(parent);
return 1;
}
int main() {
uint8_t data_ptr[] = { 0x03, 0x74, 0x04, 0x04, 0x04, 0x35, 0x35, 0x64,
0x64, 0x64, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00,
0x56, 0x45, 0x56, 0x56, 0x56, 0x09, 0x09, 0x09};
int data_size = sizeof(data_ptr)/sizeof(*data_ptr);
int new_size = byte_compress(data_ptr, data_size);
return 0;
}