-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcoder.h
51 lines (48 loc) · 1.01 KB
/
hcoder.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
/*
* hcoder.h
*
* Created on: 20.06.2015
* Author: roman
*/
#ifndef BAR_H_
#define BAR_H_
#include <map>
#include "pdistrib.h"
#include "bitarr.h"
class hcoder {
public:
hcoder();
virtual ~hcoder();
// pd must be sorted
int setPDistrib(PDistrib *pd, bool _optimist = false);
void reset();
bitarr encode(long val);
bitarr encodeTbl(long val);
int decode(bitarr *arr, int pos, long *value);
void dump(int priority);
void bench();
void test();
protected:
class Vertex {
public:
Vertex(vector<Vertex *> *tree) :p(0),s0(0),s1(0) { tree->push_back(this); }
int countN() { int n=0; if (p) n++; if(s0) n++; if (s1) n++; return n; }
unsigned int depth;
bitarr nominal;
bool busy;
long value;
Vertex *p, *s0, *s1;
};
Vertex *findLocalRoot(unsigned int depth);
int raiseBTree(Vertex *v, int diff);
int adjustBTree();
int genBTree();
void clearBTree();
int genCodes();
private:
PDistrib *pd;
bool optimist;
vector<Vertex *> btree;
std::map<long, bitarr> codes;
};
#endif /* BAR_H_ */