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
This commit is contained in:
Michael McCandless 2014-06-18 16:44:28 +00:00
parent 8f0c046ef6
commit a0904dc28b
2 changed files with 7 additions and 18 deletions

View File

@ -20,11 +20,11 @@ package org.apache.lucene.util.automaton;
//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 @@ public class Automaton {
/** 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 @@ public class Automaton {
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 @@ public class Automaton {
}
/** 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 @@ public class Automaton {
}
}
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);

View File

@ -42,7 +42,6 @@ import java.util.Set;
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 @@ final public class Operations {
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 @@ final public class Operations {
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 @@ final public class Operations {
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) {