mirror of https://github.com/apache/lucene.git
LUCENE-5960: Use a more efficient bitset, not a Set<Integer>, to track visited states
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1625965 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
442f787693
commit
6e6aa0b2ac
|
@ -327,6 +327,9 @@ Optimizations
|
||||||
Always use MethodHandles to create AttributeImpl classes.
|
Always use MethodHandles to create AttributeImpl classes.
|
||||||
(Uwe Schindler)
|
(Uwe Schindler)
|
||||||
|
|
||||||
|
* LUCENE-5960: Use a more efficient bitset, not a Set<Integer>, to
|
||||||
|
track visited states. (Markus Heiden via Mike McCandless)
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
|
|
||||||
* LUCENE-5796: Fixes the Scorer.getChildren() method for two combinations
|
* LUCENE-5796: Fixes the Scorer.getChildren() method for two combinations
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
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.ArrayUtil;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.BytesRefBuilder;
|
import org.apache.lucene.util.BytesRefBuilder;
|
||||||
import org.apache.lucene.util.CharsRef;
|
|
||||||
import org.apache.lucene.util.CharsRefBuilder;
|
import org.apache.lucene.util.CharsRefBuilder;
|
||||||
import org.apache.lucene.util.IOUtils;
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.apache.lucene.util.IntsRef;
|
import org.apache.lucene.util.IntsRef;
|
||||||
import org.apache.lucene.util.IntsRefBuilder;
|
import org.apache.lucene.util.IntsRefBuilder;
|
||||||
import org.apache.lucene.util.OfflineSorter;
|
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.Automaton;
|
||||||
|
import org.apache.lucene.util.automaton.Operations;
|
||||||
import org.apache.lucene.util.automaton.Transition;
|
import org.apache.lucene.util.automaton.Transition;
|
||||||
import org.apache.lucene.util.fst.Builder;
|
import org.apache.lucene.util.fst.Builder;
|
||||||
import org.apache.lucene.util.fst.ByteSequenceOutputs;
|
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.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;
|
||||||
|
import org.apache.lucene.util.fst.PairOutputs.Pair;
|
||||||
import org.apache.lucene.util.fst.PositiveIntOutputs;
|
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.Result;
|
||||||
import org.apache.lucene.util.fst.Util.TopResults;
|
import org.apache.lucene.util.fst.Util.TopResults;
|
||||||
import org.apache.lucene.util.fst.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggester that first analyzes the surface form, adds the
|
* Suggester that first analyzes the surface form, adds the
|
||||||
|
@ -270,11 +269,12 @@ public class AnalyzingSuggester extends Lookup {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] topoSortStates(Automaton a) {
|
private int[] topoSortStates(Automaton a) {
|
||||||
int[] states = new int[a.getNumStates()];
|
int numStates = a.getNumStates();
|
||||||
final Set<Integer> visited = new HashSet<>();
|
int[] states = new int[numStates];
|
||||||
|
final BitSet visited = new BitSet(numStates);
|
||||||
final LinkedList<Integer> worklist = new LinkedList<>();
|
final LinkedList<Integer> worklist = new LinkedList<>();
|
||||||
worklist.add(0);
|
worklist.add(0);
|
||||||
visited.add(0);
|
visited.set(0);
|
||||||
int upto = 0;
|
int upto = 0;
|
||||||
states[upto] = 0;
|
states[upto] = 0;
|
||||||
upto++;
|
upto++;
|
||||||
|
@ -284,8 +284,8 @@ public class AnalyzingSuggester extends Lookup {
|
||||||
int count = a.initTransition(s, t);
|
int count = a.initTransition(s, t);
|
||||||
for (int i=0;i<count;i++) {
|
for (int i=0;i<count;i++) {
|
||||||
a.getNextTransition(t);
|
a.getNextTransition(t);
|
||||||
if (!visited.contains(t.dest)) {
|
if (!visited.get(t.dest)) {
|
||||||
visited.add(t.dest);
|
visited.set(t.dest);
|
||||||
worklist.add(t.dest);
|
worklist.add(t.dest);
|
||||||
states[upto++] = t.dest;
|
states[upto++] = t.dest;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue