blob: d6f4317db09085c63faa8d6e4ea5c1c54ac21a15 (
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
|
#pragma once
#include <cstddef>
namespace NCompactTrie {
class ILeafSkipper;
enum TDirection {
D_LEFT,
D_FINAL,
D_NEXT,
D_RIGHT,
D_MAX
};
inline TDirection& operator++(TDirection& direction) {
direction = static_cast<TDirection>(direction + 1);
return direction;
}
inline TDirection& operator--(TDirection& direction) {
direction = static_cast<TDirection>(direction - 1);
return direction;
}
class TNode {
public:
TNode();
// Processes epsilon links and sets ForwardOffset to correct value. Assumes an epsilon link doesn't point to an epsilon link.
TNode(const char* data, size_t offset, const ILeafSkipper& skipFunction);
size_t GetOffset() const {
return Offset;
}
size_t GetLeafOffset() const {
return Offsets[D_FINAL];
}
size_t GetLeafLength() const {
return LeafLength;
}
size_t GetCoreLength() const {
return CoreLength;
}
size_t GetOffsetByDirection(TDirection direction) const {
return Offsets[direction];
}
size_t GetForwardOffset() const {
return Offsets[D_NEXT];
}
size_t GetLeftOffset() const {
return Offsets[D_LEFT];
}
size_t GetRightOffset() const {
return Offsets[D_RIGHT];
}
char GetLabel() const {
return Label;
}
bool IsFinal() const {
return GetLeafOffset() != 0;
}
bool HasEpsilonLinkForward() const {
return GetForwardOffset() > Offset + CoreLength;
}
private:
size_t Offsets[D_MAX];
size_t Offset;
size_t LeafLength;
size_t CoreLength;
char Label;
};
}
|