-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuffmantree.h
57 lines (43 loc) · 1.53 KB
/
huffmantree.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
/*
* HuffmanTree.h
*
* Created on: May 2, 2018
* Author: Yuun
*/
#ifndef SRC_HUFFMANTREE_H_
#define SRC_HUFFMANTREE_H_
#include <string>
#include "Node.h"
#include "Heap.h"
#include <limits.h>
#include <bitset>
#include "BitReaderStream.h"
#include <iostream>
#include <fstream>
using namespace std;
class HuffmanTree {
public:
HuffmanTree();
HuffmanTree(unsigned int table[]);
HuffmanTree(BitReaderStream& reader);
virtual ~HuffmanTree();
void Build_table(unsigned long long* code_table, int* codes_length);
void decode_message(BitReaderStream& reader, string puffFile, unsigned int num_of_chars);
void verify(unsigned long long* code_table, int* codes_length);
private:
Heap<Node<unsigned int, unsigned char>*,
CompareNode<unsigned int, unsigned char> > priority_queue;
Node<unsigned int, unsigned char>* root_;
void Build_tableHelper(unsigned long long* code_table, int* codes_length,
Node<unsigned int, unsigned char>* current,
int depth, unsigned int binary_code);
Node<unsigned int, unsigned char>* build_Tree(Node<unsigned int, unsigned char>* current,
unsigned char ch, int binary_length, unsigned long long binary_code);
void decode_helper(std::ofstream& output, BitReaderStream& reader,
Node<unsigned int, unsigned char>* current);
void dump(Node<unsigned int, unsigned char>* current, int level);
void verify_helper(Node<unsigned int, unsigned char>* current,
unsigned long long* code_table, int* codes_length,
unsigned long long code_from_tree, int depth);
};
#endif /* SRC_HUFFMANTREE_H_ */