forked from pjmikkol/bwtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuffmanUtil.hpp
84 lines (68 loc) · 2.27 KB
/
HuffmanUtil.hpp
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
/**
* @file HuffmanUtilCoders.hpp
* @author Dominik Kempa <[email protected]>
* @author Pekka Mikkola <[email protected]>
* @author Jussi Kokkala <[email protected]>
* @section LICENSE
*
* This file is part of bwtc.
*
* bwtc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* bwtc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bwtc. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
* Header for simple HuffmanUtil coder.
*
*/
#ifndef BWTC_HUFFMANUTIL_HPP_
#define BWTC_HUFFMANUTIL_HPP_
#include "EntropyCoders.hpp"
#include "globaldefs.hpp"
#include "BitCoders.hpp"
#include "Streams.hpp"
#include <iostream>
#include <string>
#include <vector>
namespace bwtc {
class HuffmanUtilEncoder {
public:
HuffmanUtilEncoder();
~HuffmanUtilEncoder();
size_t encode(byte* data, uint64 size, OutStream* out);
void encodeData(const byte* data, const std::vector<uint32>& stats,
uint32 blockSize, OutStream* out);
void writeBlockHeader(std::vector<uint32>& stats, OutStream* out);
void writePackedInteger(uint64 packed_integer, OutStream* out);
void finishBlock(OutStream* out);
private:
long int m_headerPosition;
uint64 m_compressedBlockLength;
void serializeShape(uint32 *clen, std::vector<bool> &vec);
HuffmanUtilEncoder(const HuffmanUtilEncoder&);
HuffmanUtilEncoder& operator=(const HuffmanUtilEncoder&);
};
class HuffmanUtilDecoder {
public:
HuffmanUtilDecoder();
~HuffmanUtilDecoder();
uint64 readPackedInteger(InStream* in);
void decodeBlock(std::vector<byte>& data,InStream* in);
uint64 readBlockHeader(std::vector<uint64>* stats, InStream* in);
private:
size_t deserializeShape(InStream &input, uint32 *clen);
HuffmanUtilDecoder(const HuffmanUtilDecoder&);
HuffmanUtilDecoder& operator=(const HuffmanUtilDecoder&);
};
} // namespace bwtc
#endif