Skip to content

Commit 9960e12

Browse files
committed
review fix and reuse duplicate code
1 parent 51e0998 commit 9960e12

File tree

4 files changed

+35
-42
lines changed

4 files changed

+35
-42
lines changed

lucene/core/src/java/org/apache/lucene/codecs/lucene90/blocktree/Lucene90BlockTreeTermsReader.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,8 @@ public final class Lucene90BlockTreeTermsReader extends FieldsProducer {
8686
*/
8787
public static final int VERSION_MSB_VLONG_OUTPUT = 1;
8888

89-
/** Version that store continuous arcs label as range in FST. */
90-
public static final int VERSION_ARCS_CONTINUOUS = 2;
91-
9289
/** Current terms format. */
93-
public static final int VERSION_CURRENT = VERSION_ARCS_CONTINUOUS;
90+
public static final int VERSION_CURRENT = VERSION_MSB_VLONG_OUTPUT;
9491

9592
/** Extension of terms index file */
9693
static final String TERMS_INDEX_EXTENSION = "tip";

lucene/core/src/java/org/apache/lucene/util/fst/FST.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public enum INPUT_TYPE {
9696
*/
9797
static final byte ARCS_FOR_DIRECT_ADDRESSING = 1 << 6;
9898

99+
/**
100+
* Value of the arc flags to declare a node with continuous arcs designed for pos the arc directly
101+
* with labelToPos - firstLabel. like {@link #ARCS_FOR_BINARY_SEARCH} we use flag combinations
102+
* that will not occur at the same time.
103+
*/
99104
static final byte ARCS_FOR_CONTINUOUS = ARCS_FOR_DIRECT_ADDRESSING + ARCS_FOR_BINARY_SEARCH;
100105

101106
// Increment version to change it
@@ -916,6 +921,7 @@ public Arc<T> readLastArcByDirectAddressing(Arc<T> arc, final BytesReader in) th
916921
return readArcByDirectAddressing(arc, in, arc.numArcs() - 1, presenceIndex);
917922
}
918923

924+
/** Reads the last arc of a continuous node. */
919925
public Arc<T> readLastArcByContinuous(Arc<T> arc, final BytesReader in) throws IOException {
920926
return readArcByContinuous(arc, in, arc.numArcs() - 1);
921927
}

lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ long addNode(FSTCompiler.UnCompiledNode<T> nodeIn) throws IOException {
446446

447447
int labelRange = nodeIn.arcs[nodeIn.numArcs - 1].label - nodeIn.arcs[0].label + 1;
448448
assert labelRange > 0;
449-
boolean continuousLable = labelRange == nodeIn.numArcs;
450-
if (continuousLable) {
449+
boolean continuousLabel = labelRange == nodeIn.numArcs;
450+
if (continuousLabel) {
451451
writeNodeForDirectAddressingOrContinuous(
452452
nodeIn, startAddress, maxBytesPerArcWithoutLabel, labelRange, true);
453453
continuousNodeCount++;

lucene/core/src/java/org/apache/lucene/util/fst/FSTEnum.java

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,8 @@ private FST.Arc<T> doSeekCeilArrayContinuous(
165165
final FST.Arc<T> arc, final int targetLabel, final FST.BytesReader in) throws IOException {
166166
int targetIndex = targetLabel - arc.firstLabel();
167167
if (targetIndex >= arc.numArcs()) {
168-
// Target is beyond the last arc, out of label range.
169-
// Dead end (target is after the last arc);
170-
// rollback to last fork then push
171-
upto--;
172-
while (true) {
173-
if (upto == 0) {
174-
return null;
175-
}
176-
final FST.Arc<T> prevArc = getArc(upto);
177-
// System.out.println(" rollback upto=" + upto + " arc.label=" + prevArc.label + "
178-
// isLast?=" + prevArc.isLast());
179-
if (!prevArc.isLast()) {
180-
fst.readNextArc(prevArc, fstReader);
181-
pushFirst();
182-
return null;
183-
}
184-
upto--;
185-
}
168+
rollbackToLastForkThenPush();
169+
return null;
186170
} else {
187171
if (targetIndex < 0) {
188172
fst.readArcByContinuous(arc, in, 0);
@@ -211,24 +195,8 @@ private FST.Arc<T> doSeekCeilArrayDirectAddressing(
211195

212196
int targetIndex = targetLabel - arc.firstLabel();
213197
if (targetIndex >= arc.numArcs()) {
214-
// Target is beyond the last arc, out of label range.
215-
// Dead end (target is after the last arc);
216-
// rollback to last fork then push
217-
upto--;
218-
while (true) {
219-
if (upto == 0) {
220-
return null;
221-
}
222-
final FST.Arc<T> prevArc = getArc(upto);
223-
// System.out.println(" rollback upto=" + upto + " arc.label=" + prevArc.label + "
224-
// isLast?=" + prevArc.isLast());
225-
if (!prevArc.isLast()) {
226-
fst.readNextArc(prevArc, fstReader);
227-
pushFirst();
228-
return null;
229-
}
230-
upto--;
231-
}
198+
rollbackToLastForkThenPush();
199+
return null;
232200
} else {
233201
if (targetIndex < 0) {
234202
targetIndex = -1;
@@ -458,6 +426,28 @@ private FST.Arc<T> doSeekFloorArrayDirectAddressing(
458426
}
459427
}
460428

429+
/**
430+
* Target is beyond the last arc, out of label range. Dead end (target is after the last arc);
431+
* rollback to last fork then push
432+
*/
433+
private void rollbackToLastForkThenPush() throws IOException {
434+
upto--;
435+
while (true) {
436+
if (upto == 0) {
437+
return;
438+
}
439+
final FST.Arc<T> prevArc = getArc(upto);
440+
// System.out.println(" rollback upto=" + upto + " arc.label=" + prevArc.label + "
441+
// isLast?=" + prevArc.isLast());
442+
if (!prevArc.isLast()) {
443+
fst.readNextArc(prevArc, fstReader);
444+
pushFirst();
445+
return;
446+
}
447+
upto--;
448+
}
449+
}
450+
461451
/**
462452
* Backtracks until it finds a node which first arc is before our target label.` Then on the node,
463453
* finds the arc just before the targetLabel.

0 commit comments

Comments
 (0)