-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (34 loc) · 1.13 KB
/
Copy pathmain.cpp
File metadata and controls
49 lines (34 loc) · 1.13 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
#include <cstdint>
#include <iostream>
#include <cassert>
#include <HuffmanTree.hpp>
#include <Histogram.hpp>
#include <ShannonHistogram.hpp>
#include <SymbolTable.hpp>
#include <bitarray/BitArray.hpp>
#include <hafe_file_format/Hafe.hpp>
#include <encoder/Encoder.hpp>
#include <decoder/Decoder.hpp>
using namespace std;
int main(int argc, [[maybe_unused]] char *argv[]) {
enum {
COMPRESS = 1,
DECOMPRESS
};
auto mode = argc > 1 ? DECOMPRESS : COMPRESS;
if (mode == COMPRESS) { // compress a binary file
auto str = stream_content(cin);
Encoder encoder{str};
// const auto &freq = encoder.shannon_histogram();
//auto symbol_table = encoder.symbol_table();
//assert(symbol_table.longest().bit_length() < HuffmanCode::MAX_LENGTH);
Hafe hafe = encoder.hafe();
hafe.write(cout);
return 0;
}
Hafe hafe{cin};
Decoder decoder{hafe};
//const auto &symbol_table = decoder.symbol_table();
//assert(symbol_table.longest().bit_length() < HuffmanCode::MAX_LENGTH);
cout.write((char *)decoder.str().data(), decoder.str().length());
}