-
Notifications
You must be signed in to change notification settings - Fork 0
/
LZ77.h
58 lines (47 loc) · 1.26 KB
/
LZ77.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
58
//
// Created by Fedor on 31.03.2020.
//
#include <vector>
#include <ios>
#include <algorithm>
#ifndef ZIPPER_LZ77_H
#define ZIPPER_LZ77_H
typedef unsigned char byte;
using std::vector;
using std::string;
using std::min;
class LZ77
{
public:
vector<byte> Encode(vector<byte> input, int VOCAB_BUFFER_SIZE, int PREVIEW_BUFFER_SIZE);
vector<byte> Decode(vector<byte> input);
static const int KB_1 = 1 * 1024;
static const int KB_2 = 2 * 1024;
static const int KB_4 = 4 * 1024;
static const int KB_8 = 8 * 1024;
static const int KB_16 = 16 * 1024;
private:
struct Node
{
unsigned short position, length;
byte symbol;
Node(unsigned short position, unsigned short length, byte symbol)
{
this->position = position;
this->length = length;
this->symbol = symbol;
}
};
/**
* A method for finding a match between substrings of the preview buffer and a dictionary
*/
Node* findMatching(const string& vocab_buffer, int vocab_buffer_end, string preview_buffer,
int preview_buffer_end);
static const int SYMBOL_DATA_SIZE = 5;
};
union LongShortByteUnion
{
unsigned short uShort;
byte uBytes[8];
};
#endif //ZIPPER_LZ77_H