LUCENE-8781: add FST array-with-gap addressing to Util.readCeilArc

This commit is contained in:
Michael Sokolov 2019-06-14 20:47:18 -04:00
parent 0a915c3292
commit badcc4e6c7
1 changed files with 14 additions and 2 deletions

View File

@ -924,7 +924,7 @@ public final class Util {
*/
/**
* Reads the first arc greater or equal that the given label into the provided
* Reads the first arc greater or equal than the given label into the provided
* arc in place and returns it iff found, otherwise return <code>null</code>.
*
* @param label the label to ceil on
@ -958,7 +958,19 @@ public final class Util {
}
fst.readFirstTargetArc(follow, arc, in);
if (arc.bytesPerArc != 0 && arc.label != FST.END_LABEL) {
// Arcs are fixed array -- use binary search to find
if (arc.arcIdx == Integer.MIN_VALUE) {
// Arcs are in an array-with-gaps
int offset = label - arc.label;
if (offset >= arc.numArcs) {
return null;
} else if (offset < 0) {
return arc;
} else {
arc.nextArc = arc.posArcsStart - offset * arc.bytesPerArc;
return fst.readNextRealArc(arc, in);
}
}
// Arcs are packed array -- use binary search to find
// the target.
int low = arc.arcIdx;