-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffman_tree.h
52 lines (34 loc) · 1.14 KB
/
huffman_tree.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
#include "huffman_node.h"
#include <unordered_map>
#include <memory>
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#ifndef HUFFMAN_TREE_H
#define HUFFMAN_TREE_H
struct compare_huffman_node{
bool operator()(const huffman_node& lhs, const huffman_node& rhs)
{
return lhs.getFrequency() > rhs.getFrequency();
}
};
class huffman_tree{
public:
std::shared_ptr<huffman_node> root;
std::unordered_map<char, int> huffman_node_map;
std::priority_queue<huffman_node, std::vector<huffman_node>, compare_huffman_node> huffman_node_queue;
std::unordered_map<char, std::string> code_table;
public:
huffman_tree();
~huffman_tree();
void make_huffman_node_map(std::string input_file) throw();
void make_huffman_node_queue();
void visit(std::shared_ptr<huffman_node> node, std::string binary_code);
void in_order(std::shared_ptr<huffman_node> node, std::string binary_code);
void compress(std::string input_file, std::string output_file);
void convert(std::string input_file, std::string output_file);
int packed_size(std::string buffer) const;
std::string make_buffer(std::string input_file) const;
};
#endif