From badcc4e6c723678cda9c7990a8d2c4bf1e556f42 Mon Sep 17 00:00:00 2001 From: Michael Sokolov Date: Fri, 14 Jun 2019 20:47:18 -0400 Subject: [PATCH] LUCENE-8781: add FST array-with-gap addressing to Util.readCeilArc --- .../java/org/apache/lucene/util/fst/Util.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/Util.java b/lucene/core/src/java/org/apache/lucene/util/fst/Util.java index 04cd18270cf..f8dd6fd029d 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/Util.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/Util.java @@ -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 null. * * @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;