Package org.apache.lucene.util.automaton
Class NFARunAutomaton
java.lang.Object
org.apache.lucene.util.automaton.NFARunAutomaton
- All Implemented Interfaces:
Accountable,ByteRunnable,TransitionAccessor
public class NFARunAutomaton
extends Object
implements ByteRunnable, TransitionAccessor, Accountable
A RunAutomaton that does not require DFA. It will lazily determinize on-demand, memorizing the
generated DFA states that has been explored. Note: the current implementation is NOT thread-safe
implemented based on: https://swtch.com/~rsc/regexp/regexp1.html
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
ConstructorsConstructorDescriptionNFARunAutomaton(Automaton automaton) Constructor, assuming alphabet size is the whole Unicode code point spaceNFARunAutomaton(Automaton automaton, int alphabetSize) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidIterate to the next transition after the provided oneintgetNumTransitions(int state) How many transitions this state has.intgetSize()Returns number of states this automaton has, note this may not be an accurate number in case of NFAvoidgetTransition(int state, int index, Transition t) Fill the providedTransitionwith the index'th transition leaving the specified state.intinitTransition(int state, Transition t) Initialize the provided Transition to iterate through all transitions leaving the specified state.booleanisAccept(int state) Returns acceptance status for given state.longReturn the memory usage of this object in bytes.intstep(int state, int c) For a given state and an incoming character (codepoint), return the next stateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResourcesMethods inherited from interface org.apache.lucene.util.automaton.ByteRunnable
run
-
Constructor Details
-
NFARunAutomaton
Constructor, assuming alphabet size is the whole Unicode code point space- Parameters:
automaton- incoming automaton, should be NFA, for DFA please useRunAutomatonfor better efficiency
-
NFARunAutomaton
Constructor- Parameters:
automaton- incoming automaton, should be NFA, for DFA please useRunAutomaton* for better efficiencyalphabetSize- alphabet size
-
-
Method Details
-
step
public int step(int state, int c) For a given state and an incoming character (codepoint), return the next state- Specified by:
stepin interfaceByteRunnable- Parameters:
state- incoming state, should either be 0 or some state that is returned previously by this functionc- codepoint- Returns:
- the next state or
MISSINGif the transition doesn't exist
-
isAccept
public boolean isAccept(int state) Description copied from interface:ByteRunnableReturns acceptance status for given state.- Specified by:
isAcceptin interfaceByteRunnable- Parameters:
state- the state- Returns:
- whether the state is accepted
-
getSize
public int getSize()Description copied from interface:ByteRunnableReturns number of states this automaton has, note this may not be an accurate number in case of NFA- Specified by:
getSizein interfaceByteRunnable- Returns:
- number of states
-
initTransition
Description copied from interface:TransitionAccessorInitialize the provided Transition to iterate through all transitions leaving the specified state. You must callTransitionAccessor.getNextTransition(org.apache.lucene.util.automaton.Transition)to get each transition. Returns the number of transitions leaving this state.- Specified by:
initTransitionin interfaceTransitionAccessor
-
getNextTransition
Description copied from interface:TransitionAccessorIterate to the next transition after the provided one- Specified by:
getNextTransitionin interfaceTransitionAccessor
-
getNumTransitions
public int getNumTransitions(int state) Description copied from interface:TransitionAccessorHow many transitions this state has.- Specified by:
getNumTransitionsin interfaceTransitionAccessor
-
getTransition
Description copied from interface:TransitionAccessorFill the providedTransitionwith the index'th transition leaving the specified state.- Specified by:
getTransitionin interfaceTransitionAccessor
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-