-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRice.h
53 lines (44 loc) · 1.46 KB
/
Rice.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
#ifndef RICE_H
#define RICE_H
#include <vector>
#include <cstddef>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
class Rice {
private:
std::vector <unsigned char> encodedData;
unsigned int prevValue;
int remainderBits;
int offset;
void writeChunkToMem();
void writeQ(const int q);
void writeR(const int r);
inline void writeBit(const bool bit) {
if (bit)
encodedData.back() |= 1 << offset; // turn offset bit on
incOffset();
}
inline void incOffset() {
offset++;
if (offset == 8) {
encodedData.push_back(0);
offset = 0;
}
}
public:
inline int determineM(const float prob) { // will return appropriate rice M - must be power of 2
return(pow(2,int(log2(-1.0/(log2(1.0-prob))))));
}
inline int determineMByProb(const unsigned int *data, const size_t len) { // actually get prob - assumes data is sorted
unsigned int range = data[len-1] - data[0];
float prob = len / float(range);
return determineM(prob);
}
int determineMByMedian(const unsigned int *data, const size_t len);
Rice();
size_t size();
int riceEncode (const unsigned int *data, const size_t len, const int M = -1, const bool findMedianDelta = true);
};
#endif