-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecompressor.hpp
More file actions
55 lines (46 loc) · 851 Bytes
/
decompressor.hpp
File metadata and controls
55 lines (46 loc) · 851 Bytes
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
#pragma once
#include "utils.hpp"
class haffman_decompressor
{
public:
haffman_decompressor(byte_freq &bm)
{
root = get_hff_tree(bm);
}
void decompress(bits_vector &bits)
{
int64_t index = -1;
while (index < (int64_t)bits.get_bit_count() - 2)
{
decode(root, index, bits);
}
}
vector<uint8_t> *get_data()
{
return &data;
}
void clear_data()
{
data.clear();
}
void decode(shared_ptr<node> root, int64_t &index, bits_vector &bits)
{
if (nullptr == root)
{
return;
}
if (!root->left && !root->right)
{
data.push_back(root->byte);
return;
}
index++;
if (bits.bit_check(index) == 0)
decode(root->left, index, bits);
else
decode(root->right, index, bits);
}
private:
shared_ptr<node> root;
vector<uint8_t> data;
};