diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 4cacac98164..cf42511b01a 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -327,6 +327,9 @@ Optimizations Always use MethodHandles to create AttributeImpl classes. (Uwe Schindler) +* LUCENE-5960: Use a more efficient bitset, not a Set, to + track visited states. (Markus Heiden via Mike McCandless) + Bug Fixes * LUCENE-5796: Fixes the Scorer.getChildren() method for two combinations diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java index 58d9e78e5ed..98c1113a914 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.BitSet; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; @@ -42,26 +43,24 @@ import org.apache.lucene.util.Accountables; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IntsRef; import org.apache.lucene.util.IntsRefBuilder; import org.apache.lucene.util.OfflineSorter; -import org.apache.lucene.util.UnicodeUtil; -import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.Automaton; +import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.Transition; import org.apache.lucene.util.fst.Builder; import org.apache.lucene.util.fst.ByteSequenceOutputs; -import org.apache.lucene.util.fst.FST.BytesReader; import org.apache.lucene.util.fst.FST; -import org.apache.lucene.util.fst.PairOutputs.Pair; +import org.apache.lucene.util.fst.FST.BytesReader; import org.apache.lucene.util.fst.PairOutputs; +import org.apache.lucene.util.fst.PairOutputs.Pair; import org.apache.lucene.util.fst.PositiveIntOutputs; +import org.apache.lucene.util.fst.Util; import org.apache.lucene.util.fst.Util.Result; import org.apache.lucene.util.fst.Util.TopResults; -import org.apache.lucene.util.fst.Util; /** * Suggester that first analyzes the surface form, adds the @@ -270,11 +269,12 @@ public class AnalyzingSuggester extends Lookup { } private int[] topoSortStates(Automaton a) { - int[] states = new int[a.getNumStates()]; - final Set visited = new HashSet<>(); + int numStates = a.getNumStates(); + int[] states = new int[numStates]; + final BitSet visited = new BitSet(numStates); final LinkedList worklist = new LinkedList<>(); worklist.add(0); - visited.add(0); + visited.set(0); int upto = 0; states[upto] = 0; upto++; @@ -284,8 +284,8 @@ public class AnalyzingSuggester extends Lookup { int count = a.initTransition(s, t); for (int i=0;i