-
Notifications
You must be signed in to change notification settings - Fork 2
/
huffman_test.cpp
149 lines (108 loc) · 5.78 KB
/
huffman_test.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "helpers/huffmanish.hh"
int main(int argc, char* argv[]){
Huffman huffmanclass(argv[1]); //initialize
huffmanclass.assign_values();
huffmanclass.produce_lookups();
huffmanclass.serialize_maps("/tmp/maps/");
util::FilePiece filein(argv[1]);
line_text firstline = splitLine(filein.ReadLine());
line_text line2 = splitLine(filein.ReadLine());
line_text line3 = splitLine(filein.ReadLine());
line_text line4 = splitLine(filein.ReadLine());
line_text line5 = splitLine(filein.ReadLine());
line_text line6 = splitLine(filein.ReadLine());
line_text line7 = splitLine(filein.ReadLine());
line_text line8 = splitLine(filein.ReadLine());
line_text line9 = splitLine(filein.ReadLine());
line_text line10 = splitLine(filein.ReadLine());
std::cout << "BEGIN! Encode 10 lines!" << std::endl;
std::vector<unsigned char> encoding = huffmanclass.full_encode_line(firstline);
std::vector<unsigned char> encoding2 = huffmanclass.full_encode_line(line2);
std::vector<unsigned char> encoding3 = huffmanclass.full_encode_line(line3);
std::vector<unsigned char> encoding4 = huffmanclass.full_encode_line(line4);
std::vector<unsigned char> encoding5 = huffmanclass.full_encode_line(line5);
std::vector<unsigned char> encoding6 = huffmanclass.full_encode_line(line6);
std::vector<unsigned char> encoding7 = huffmanclass.full_encode_line(line7);
std::vector<unsigned char> encoding8 = huffmanclass.full_encode_line(line8);
std::vector<unsigned char> encoding9 = huffmanclass.full_encode_line(line9);
std::vector<unsigned char> encoding10 = huffmanclass.full_encode_line(line10);
std::cout << "END! Encoded 10 lines!" << std::endl;
/*
for (std::vector<unsigned char>::iterator it = encoding.begin(); it != encoding.end(); it++){
std::cout << (int)*it << " ";
}
std::cout << std::endl;
*/
std::cout <<"BEGIN! Initialize decoder" <<std::endl;
std::map<unsigned int, std::string> lookup_target_phrase = huffmanclass.get_target_lookup_map();
std::map<unsigned int, std::vector<unsigned char> > lookup_word_all1 = huffmanclass.get_word_all1_lookup_map();
std::map<unsigned int, std::vector<unsigned char> > lookup_word_all2 = huffmanclass.get_word_all2_lookup_map();
HuffmanDecoder decoder(&lookup_target_phrase, &lookup_word_all1, &lookup_word_all2);
std::cout <<"END! Initialized decoder" <<std::endl;
target_text tmp = (decoder.full_decode_line(encoding))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding2))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding3))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding4))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding5))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding6))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding7))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding8))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding9))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
tmp = (decoder.full_decode_line(encoding10))[0];
std::cout << decoder.getTargetWordsFromIDs(tmp.target_phrase) << " ";
for (std::vector<float>::iterator it = tmp.prob.begin(); it != tmp.prob.end(); it++){
std::cout << *it << " ";
}
std::cout << (int)tmp.word_all1[0] << " " << (int)tmp.word_all2[0] << std::endl;
std::vector<unsigned int> test = {1};
std::cout << "Size is! " << (vbyte_encode_line(test)).size() << std::endl;
std::vector<unsigned int> test2 = {1,2};
std::cout << "Size is! " << (vbyte_encode_line(test2)).size() << std::endl;
std::vector<unsigned int> test3 = {250430};
std::cout << "Size is! " << (vbyte_encode_line(test3)).size() << std::endl;
}