forked from hxim/paq8px
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLargeIndirectContext.hpp
41 lines (34 loc) · 986 Bytes
/
LargeIndirectContext.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
#pragma once
#include "Array.hpp"
#include "Bucket16.hpp"
#include "Hash.hpp"
#include <cassert>
#include <cstdint>
template<typename T>
class LargeIndirectContext {
private:
Array<Bucket16<T, 7>> data;
const uint32_t hashBits, inputBits;
public:
LargeIndirectContext(const int hashBits, const int inputBits) :
data(UINT64_C(1) << hashBits),
hashBits(hashBits),
inputBits(inputBits)
{
assert(hashBits > 0 && hashBits <= 24);
assert(inputBits > 0 && inputBits <= 8);
}
void reset() {
for (uint64_t i = 0; i < data.size(); ++i) {
data[i].reset();
}
}
void set(const uint64_t contextHash, const uint8_t c) {
assert(c < (1 << inputBits));
T* ptr = data[finalize64(contextHash, hashBits)].find(checksum16(contextHash, hashBits), nullptr);
*ptr = (*ptr) << inputBits | c;
};
T get(const uint64_t contextHash) {
return *data[finalize64(contextHash, hashBits)].find(checksum16(contextHash, hashBits), nullptr);
};
};