Skip to content
Permalink
Browse files

automaton initial state is always 0

  • Loading branch information...
mikemccand committed Oct 10, 2016
1 parent 257ea34 commit 4fe3110e494a7c090d5d72d93dddcb4772c3904b
@@ -474,7 +474,7 @@ private CharsRef newStem(char buffer[], int length, IntsRef forms, int formID) {
private boolean checkCondition(int condition, char c1[], int c1off, int c1len, char c2[], int c2off, int c2len) {
if (condition != 0) {
CharacterRunAutomaton pattern = dictionary.patterns.get(condition);
int state = pattern.getInitialState();
int state = 0;
for (int i = c1off; i < c1off + c1len; i++) {
state = pattern.step(state, c1[i]);
if (state == -1) {
@@ -92,7 +92,7 @@ public OrdsIntersectTermsEnum(OrdsFieldReader fr, CompiledAutomaton compiled, By
final OrdsIntersectTermsEnumFrame f = stack[0];
f.fp = f.fpOrig = fr.rootBlockFP;
f.prefix = 0;
f.setState(runAutomaton.getInitialState());
f.setState(0);
f.arc = arc;
f.outputPrefix = arc.output;
f.load(fr.rootCode);
@@ -969,7 +969,7 @@ public DirectIntersectTermsEnum(CompiledAutomaton compiled, BytesRef startTerm)
states = new State[1];
states[0] = new State();
states[0].changeOrd = terms.length;
states[0].state = runAutomaton.getInitialState();
states[0].state = 0;
states[0].transitionCount = compiledAutomaton.automaton.getNumTransitions(states[0].state);
compiledAutomaton.automaton.initTransition(states[0].state, states[0].transition);
states[0].transitionUpto = -1;
@@ -705,7 +705,7 @@ Frame loadVirtualFrame(Frame frame) throws IOException {
/** Load frame for start arc(node) on fst */
Frame loadFirstFrame(Frame frame) throws IOException {
frame.arc = fst.getFirstArc(frame.arc);
frame.state = fsa.getInitialState();
frame.state = 0;
return frame;
}

@@ -602,7 +602,7 @@ Frame loadVirtualFrame(Frame frame) throws IOException {
/** Load frame for start arc(node) on fst */
Frame loadFirstFrame(Frame frame) throws IOException {
frame.fstArc = fst.getFirstArc(frame.fstArc);
frame.fsaState = fsa.getInitialState();
frame.fsaState = 0;
return frame;
}

@@ -124,7 +124,7 @@ public IntersectTermsEnum(FieldReader fr, Automaton automaton, RunAutomaton runA
final IntersectTermsEnumFrame f = stack[0];
f.fp = f.fpOrig = fr.rootBlockFP;
f.prefix = 0;
f.setState(runAutomaton.getInitialState());
f.setState(0);
f.arc = arc;
f.outputPrefix = arc.output;
f.load(fr.rootCode);
@@ -110,7 +110,7 @@ protected BytesRef nextSeekTerm(final BytesRef term) throws IOException {
if (term == null) {
assert seekBytesRef.length() == 0;
// return the empty term, as it's valid
if (runAutomaton.isAccept(runAutomaton.getInitialState())) {
if (runAutomaton.isAccept(0)) {
return seekBytesRef.get();
}
} else {
@@ -135,7 +135,7 @@ protected BytesRef nextSeekTerm(final BytesRef term) throws IOException {
private void setLinear(int position) {
assert linear == false;

int state = runAutomaton.getInitialState();
int state = 0;
assert state == 0;
int maxInterval = 0xff;
//System.out.println("setLinear pos=" + position + " seekbytesRef=" + seekBytesRef);
@@ -182,7 +182,7 @@ private boolean nextString() {
int state;
int pos = 0;
savedStates.grow(seekBytesRef.length()+1);
savedStates.setIntAt(0, runAutomaton.getInitialState());
savedStates.setIntAt(0, 0);

while (true) {
curGen++;
@@ -36,7 +36,7 @@ public ByteRunAutomaton(Automaton a, boolean isBinary, int maxDeterminizedStates
* Returns true if the given byte array is accepted by this automaton
*/
public boolean run(byte[] s, int offset, int length) {
int p = initial;
int p = 0;
int l = offset + length;
for (int i = offset; i < l; i++) {
p = step(p, s[i] & 0xFF);
@@ -43,7 +43,7 @@ public CharacterRunAutomaton(Automaton a, int maxDeterminizedStates) {
* Returns true if the given string is accepted by this automaton.
*/
public boolean run(String s) {
int p = initial;
int p = 0;
int l = s.length();
for (int i = 0, cp = 0; i < l; i += Character.charCount(cp)) {
p = step(p, cp = s.codePointAt(i));
@@ -56,7 +56,7 @@ public boolean run(String s) {
* Returns true if the given string is accepted by this automaton
*/
public boolean run(char[] s, int offset, int length) {
int p = initial;
int p = 0;
int l = offset + length;
for (int i = offset, cp = 0; i < l; i += Character.charCount(cp)) {
p = step(p, cp = Character.codePointAt(s, i, l));
@@ -351,7 +351,7 @@ public BytesRef floor(BytesRef input, BytesRefBuilder output) {

//if (DEBUG) System.out.println("CA.floor input=" + input.utf8ToString());

int state = runAutomaton.getInitialState();
int state = 0;

// Special case empty string:
if (input.length == 0) {
@@ -32,7 +32,7 @@
import java.util.Arrays;

/**
* Finite-state automaton with fast run operation.
* Finite-state automaton with fast run operation. The initial state is always 0.
*
* @lucene.experimental
*/
@@ -41,7 +41,6 @@
final int maxInterval;
final int size;
final boolean[] accept;
final int initial;
final int[] transitions; // delta(state,c) = transitions[state*points.length +
// getCharClass(c)]
final int[] points; // char interval start points
@@ -53,7 +52,7 @@
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("initial state: ").append(initial).append("\n");
b.append("initial state: 0\n");
for (int i = 0; i < size; i++) {
b.append("state " + i);
if (accept[i]) b.append(" [accept]:\n");
@@ -92,13 +91,6 @@ public final boolean isAccept(int state) {
return accept[state];
}

/**
* Returns initial state.
*/
public final int getInitialState() {
return initial;
}

/**
* Returns array of codepoint class interval start points. The array should
* not be modified by the caller.
@@ -138,7 +130,6 @@ public RunAutomaton(Automaton a, int maxInterval, boolean tableize,
a = Operations.determinize(a, maxDeterminizedStates);
this.automaton = a;
points = a.getStartPoints();
initial = 0;
size = Math.max(1,a.getNumStates());
accept = new boolean[size];
transitions = new int[size * points.length];
@@ -188,7 +179,6 @@ public final int step(int state, int c) {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + initial;
result = prime * result + maxInterval;
result = prime * result + points.length;
result = prime * result + size;
@@ -201,7 +191,6 @@ public boolean equals(Object obj) {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
RunAutomaton other = (RunAutomaton) obj;
if (initial != other.initial) return false;
if (maxInterval != other.maxInterval) return false;
if (size != other.size) return false;
if (!Arrays.equals(points, other.points)) return false;
@@ -170,7 +170,7 @@ private void addDoc(RandomIndexWriter w, Collection<String> terms, Map<BytesRef,
}

private boolean accepts(CompiledAutomaton c, BytesRef b) {
int state = c.runAutomaton.getInitialState();
int state = 0;
for(int idx=0;idx<b.length;idx++) {
assertTrue(state != -1);
state = c.runAutomaton.step(state, b.bytes[b.offset+idx] & 0xff);
@@ -291,7 +291,7 @@ public void testIntersectRandom() throws IOException {
System.out.println("\nTEST: iter2=" + iter2 + " startTerm=" + (startTerm == null ? "<null>" : startTerm.utf8ToString()));

if (startTerm != null) {
int state = c.runAutomaton.getInitialState();
int state = 0;
for(int idx=0;idx<startTerm.length;idx++) {
final int label = startTerm.bytes[startTerm.offset+idx] & 0xff;
System.out.println(" state=" + state + " label=" + label);
@@ -166,12 +166,12 @@ public void testSpecialCase() {
CharacterRunAutomaton cra = new CharacterRunAutomaton(automaton);
ByteRunAutomaton bra = new ByteRunAutomaton(automaton);
// make sure character dfa accepts empty string
assertTrue(cra.isAccept(cra.getInitialState()));
assertTrue(cra.isAccept(0));
assertTrue(cra.run(""));
assertTrue(cra.run(new char[0], 0, 0));

// make sure byte dfa accepts empty string
assertTrue(bra.isAccept(bra.getInitialState()));
assertTrue(bra.isAccept(0));
assertTrue(bra.run(new byte[0], 0, 0));
}

@@ -92,7 +92,7 @@ public MockTokenizer(AttributeFactory factory, CharacterRunAutomaton runAutomato
super(factory);
this.runAutomaton = runAutomaton;
this.lowerCase = lowerCase;
this.state = runAutomaton.getInitialState();
this.state = 0;
this.maxTokenLength = maxTokenLength;
}

@@ -252,7 +252,7 @@ protected int readChar() throws IOException {

protected boolean isTokenChar(int c) {
if (state < 0) {
state = runAutomaton.getInitialState();
state = 0;
}
state = runAutomaton.step(state, c);
if (state < 0) {
@@ -270,7 +270,7 @@ protected int normalize(int c) {
public void reset() throws IOException {
try {
super.reset();
state = runAutomaton.getInitialState();
state = 0;
lastOffset = off = 0;
bufferedCodePoint = -1;
if (streamState == State.RESET) {

0 comments on commit 4fe3110

Please sign in to comment.
You can’t perform that action at this time.