@@ -43,10 +43,15 @@ class TrieBuilder {
43
43
static final long NON_LEAF_NODE_HAS_TERMS = 1L << 1 ;
44
44
static final long NON_LEAF_NODE_HAS_FLOOR = 1L << 0 ;
45
45
46
- // describes the on-disk terms block which a trie node points to.
47
- // floorData is non-null when a large block of terms sharing a single trie prefix is split into
48
- // multiple on-disk blocks.
49
- // hasTerms is false if this on-disk block consists entirely of pointers to child blocks.
46
+ /**
47
+ * The output describing the term block the prefix point to.
48
+ *
49
+ * @param fp describes the on-disk terms block which a trie node points to.
50
+ * @param hasTerms A boolean which will be false if this on-disk block consists entirely of
51
+ * pointers to child blocks.
52
+ * @param floorData A {@link BytesRef} which will be non-null when a large block of terms sharing
53
+ * a single trie prefix is split into multiple on-disk blocks.
54
+ */
50
55
record Output (long fp , boolean hasTerms , BytesRef floorData ) {}
51
56
52
57
private enum Status {
@@ -56,16 +61,18 @@ private enum Status {
56
61
}
57
62
58
63
private static class Node {
59
- // the utf8 digit that leads to this Node, and 0 for root node
64
+ // The utf8 digit that leads to this Node, 0 for root node
60
65
private final int label ;
61
- // children listed in order by their utf8 label
66
+ // The children listed in order by their utf8 label
62
67
private final LinkedList <Node > children ;
68
+ // The output of this node.
63
69
private Output output ;
64
70
65
71
// Vars used during saving:
66
72
67
- // -1 means the node has not been saved.
73
+ // The file pointer point to where the node saved. -1 means the node has not been saved.
68
74
private long fp = -1 ;
75
+ // The iterator whose next() point to the first child has not been saved.
69
76
private Iterator <Node > childrenIterator ;
70
77
71
78
Node (int label , Output output , LinkedList <Node > children ) {
@@ -145,7 +152,9 @@ Output getEmptyOutput() {
145
152
return root .output ;
146
153
}
147
154
155
+ /** Used for tests only. */
148
156
void visit (BiConsumer <BytesRef , Output > consumer ) {
157
+ assert status == Status .BUILDING ;
149
158
if (root .output != null ) {
150
159
consumer .accept (new BytesRef (), root .output );
151
160
}
@@ -252,7 +261,6 @@ void saveNodes(IndexOutput index) throws IOException {
252
261
if (node .output != null ) {
253
262
Output output = node .output ;
254
263
long encodedFp = encodeFP (output );
255
- ;
256
264
writeLongNBytes (encodedFp , encodedOutputFpBytes , index );
257
265
if (output .floorData != null ) {
258
266
index .writeBytes (
0 commit comments