-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.hpp
65 lines (56 loc) · 1.79 KB
/
model.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
/*********************************************
* Statistical model
* This file contains two model classes: one fast adapting and one slow adapting.
* The fast model relies on probabilities getting updated at adapting rates. (CDF transformation based)
* The slow model is more traditional, it starts with initial distribution every now and then updates the table to the real probability. (Quasi-static)
**********************************************/
#ifndef MODEL_H
#define MODEL_H
#include "format.hpp"
/**
* Fast adaptive model performs alphabet-wise rescaling very frequently, normally this is done with OoOE or SSE so it's quite efficient.
*/
class AdaptiveModel
{
public:
AdaptiveModel(int Alpha);
~AdaptiveModel();
int *AlphabetSize;
static const unsigned int ProbBits = 16;
static const unsigned int ProbScale = 1 << ProbBits;
void Update(int symbol);
void Reset();
unsigned int SymToLow(unsigned short sym);
unsigned int SymToFreq(unsigned short sym);
unsigned short RangeToSym(unsigned int range);
private:
inline int* Ptr1Dto2D(int *ptr, int x, int xMax);
int Rate = 5;
int *Mix;
int *CumFreqs;
};
/**
* Quasi-static model performs alphabet-wise rescaling once per n-symbols
*/
class QuasiModel
{
private:
int *AlphabetSize;
static const int UPDATE_RATE = 64 << 10;
int SEEN = 0;
int EXP = 8;
public:
QuasiModel(int Alpha);
~QuasiModel();
static const unsigned int ProbBits = 16;
static const unsigned int ProbScale = 1 << ProbBits;
int *Freqs;
int *CumFreqs;
unsigned short RangeToSymbol[ProbScale] = {0};
void Update(int symbol);
void Reset();
unsigned int SymToLow(unsigned short sym);
unsigned int SymToFreq(unsigned short sym);
unsigned short RangeToSym(unsigned int range);
};
#endif // MODEL_H