LUCENE-5752: use BitSet for accept states
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5752@1603516 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java b/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
index 3603aba..78e096b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Automaton.java
@@ -20,11 +20,11 @@
//import java.io.IOException;
//import java.io.PrintWriter;
import java.util.Arrays;
+import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.util.ArrayUtil;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.lucene.util.Sorter;
@@ -72,7 +72,7 @@
/** Holds toState, min, max for each transition. */
private int[] transitions = new int[6];
- private FixedBitSet isAccept = new FixedBitSet(4);
+ private final BitSet isAccept = new BitSet(4);
/** True if no state has two transitions leaving with the same label. */
private boolean deterministic = true;
@@ -87,11 +87,6 @@
int state = nextState/2;
states[nextState] = -1;
nextState += 2;
- if (state >= isAccept.length()) {
- FixedBitSet newBits = new FixedBitSet(ArrayUtil.oversize(state+1, 1));
- newBits.or(isAccept);
- isAccept = newBits;
- }
return state;
}
@@ -126,7 +121,7 @@
}
/** Returns accept states. If the bit is set then that state is an accept state. */
- FixedBitSet getAcceptStates() {
+ BitSet getAcceptStates() {
return isAccept;
}
@@ -203,13 +198,8 @@
}
}
nextState += other.nextState;
- if (isAccept.length() < nextState/2) {
- FixedBitSet newBits = new FixedBitSet(ArrayUtil.oversize(nextState/2, 1));
- newBits.or(isAccept);
- isAccept = newBits;
- }
int otherNumStates = other.getNumStates();
- FixedBitSet otherAcceptStates = other.getAcceptStates();
+ BitSet otherAcceptStates = other.getAcceptStates();
int state = 0;
while (state < otherNumStates && (state = otherAcceptStates.nextSetBit(state)) != -1) {
setAccept(stateOffset + state, true);
diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
index 6d2ecac..24f85f8 100644
--- a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
+++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
@@ -42,7 +42,6 @@
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.RamUsageEstimator;
@@ -258,7 +257,7 @@
private static Set<Integer> toSet(Automaton a, int offset) {
int numStates = a.getNumStates();
- FixedBitSet isAccept = a.getAcceptStates();
+ BitSet isAccept = a.getAcceptStates();
Set<Integer> result = new HashSet<Integer>();
int upto = 0;
while (upto < numStates && (upto = isAccept.nextSetBit(upto)) != -1) {
@@ -924,7 +923,7 @@
LinkedList<Integer> workList = new LinkedList<>();
BitSet live = new BitSet(numStates);
- FixedBitSet acceptBits = a.getAcceptStates();
+ BitSet acceptBits = a.getAcceptStates();
int s = 0;
while (s < numStates && (s = acceptBits.nextSetBit(s)) != -1) {
live.set(s);
@@ -1161,7 +1160,7 @@
Automaton result = builder.finish();
int s = 0;
- FixedBitSet acceptStates = a.getAcceptStates();
+ BitSet acceptStates = a.getAcceptStates();
while (s < numStates && (s = acceptStates.nextSetBit(s)) != -1) {
result.addEpsilon(0, s+1);
if (initialStates != null) {