blob: 2403709954624367606d2e2092361b011556dfbf (
plain) (
blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#pragma once
#ifndef MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_
#define MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_
#include "../../base.h"
namespace marisa {
namespace grimoire {
namespace vector {
class RankIndex {
public:
RankIndex() : abs_(0), rel_lo_(0), rel_hi_(0) {}
void set_abs(std::size_t value) {
MARISA_DEBUG_IF(value > MARISA_UINT32_MAX, MARISA_SIZE_ERROR);
abs_ = (UInt32)value;
}
void set_rel1(std::size_t value) {
MARISA_DEBUG_IF(value > 64, MARISA_RANGE_ERROR);
rel_lo_ = (UInt32)((rel_lo_ & ~0x7FU) | (value & 0x7FU));
}
void set_rel2(std::size_t value) {
MARISA_DEBUG_IF(value > 128, MARISA_RANGE_ERROR);
rel_lo_ = (UInt32)((rel_lo_ & ~(0xFFU << 7)) | ((value & 0xFFU) << 7));
}
void set_rel3(std::size_t value) {
MARISA_DEBUG_IF(value > 192, MARISA_RANGE_ERROR);
rel_lo_ = (UInt32)((rel_lo_ & ~(0xFFU << 15)) | ((value & 0xFFU) << 15));
}
void set_rel4(std::size_t value) {
MARISA_DEBUG_IF(value > 256, MARISA_RANGE_ERROR);
rel_lo_ = (UInt32)((rel_lo_ & ~(0x1FFU << 23)) | ((value & 0x1FFU) << 23));
}
void set_rel5(std::size_t value) {
MARISA_DEBUG_IF(value > 320, MARISA_RANGE_ERROR);
rel_hi_ = (UInt32)((rel_hi_ & ~0x1FFU) | (value & 0x1FFU));
}
void set_rel6(std::size_t value) {
MARISA_DEBUG_IF(value > 384, MARISA_RANGE_ERROR);
rel_hi_ = (UInt32)((rel_hi_ & ~(0x1FFU << 9)) | ((value & 0x1FFU) << 9));
}
void set_rel7(std::size_t value) {
MARISA_DEBUG_IF(value > 448, MARISA_RANGE_ERROR);
rel_hi_ = (UInt32)((rel_hi_ & ~(0x1FFU << 18)) | ((value & 0x1FFU) << 18));
}
std::size_t abs() const {
return abs_;
}
std::size_t rel1() const {
return rel_lo_ & 0x7FU;
}
std::size_t rel2() const {
return (rel_lo_ >> 7) & 0xFFU;
}
std::size_t rel3() const {
return (rel_lo_ >> 15) & 0xFFU;
}
std::size_t rel4() const {
return (rel_lo_ >> 23) & 0x1FFU;
}
std::size_t rel5() const {
return rel_hi_ & 0x1FFU;
}
std::size_t rel6() const {
return (rel_hi_ >> 9) & 0x1FFU;
}
std::size_t rel7() const {
return (rel_hi_ >> 18) & 0x1FFU;
}
private:
UInt32 abs_;
UInt32 rel_lo_;
UInt32 rel_hi_;
};
} // namespace vector
} // namespace grimoire
} // namespace marisa
#endif // MARISA_GRIMOIRE_VECTOR_RANK_INDEX_H_
|