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 TypeMethodDescriptionvoid
Iterate to the next transition after the provided oneint
getNumTransitions
(int state) How many transitions this state has.int
getSize()
Returns number of states this automaton has, note this may not be an accurate number in case of NFAvoid
getTransition
(int state, int index, Transition t) Fill the providedTransition
with the index'th transition leaving the specified state.int
initTransition
(int state, Transition t) Initialize the provided Transition to iterate through all transitions leaving the specified state.boolean
isAccept
(int state) Returns acceptance status for given state.long
Return the memory usage of this object in bytes.int
step
(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, wait
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
Methods 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 useRunAutomaton
for 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:
step
in 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
MISSING
if the transition doesn't exist
-
isAccept
public boolean isAccept(int state) Description copied from interface:ByteRunnable
Returns acceptance status for given state.- Specified by:
isAccept
in interfaceByteRunnable
- Parameters:
state
- the state- Returns:
- whether the state is accepted
-
getSize
public int getSize()Description copied from interface:ByteRunnable
Returns number of states this automaton has, note this may not be an accurate number in case of NFA- Specified by:
getSize
in interfaceByteRunnable
- Returns:
- number of states
-
initTransition
Description copied from interface:TransitionAccessor
Initialize 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:
initTransition
in interfaceTransitionAccessor
-
getNextTransition
Description copied from interface:TransitionAccessor
Iterate to the next transition after the provided one- Specified by:
getNextTransition
in interfaceTransitionAccessor
-
getNumTransitions
public int getNumTransitions(int state) Description copied from interface:TransitionAccessor
How many transitions this state has.- Specified by:
getNumTransitions
in interfaceTransitionAccessor
-
getTransition
Description copied from interface:TransitionAccessor
Fill the providedTransition
with the index'th transition leaving the specified state.- Specified by:
getTransition
in interfaceTransitionAccessor
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:Accountable
Return the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsed
in interfaceAccountable
-