Package morfologik.fsa
Class ByteSequenceIterator
java.lang.Object
morfologik.fsa.ByteSequenceIterator
- All Implemented Interfaces:
Iterator<ByteBuffer>
An iterator that traverses the right language of a given node (all sequences
reachable from a given node).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int[]
An arc stack for DFS when processing the automaton.private byte[]
A buffer for the current sequence of bytes from the current node to the root.private ByteBuffer
Reusable byte buffer wrapper aroundbuffer
.private static final int
Default expected depth of the recursion stack (estimated longest sequence in the automaton).private final FSA
The FSA to which this iterator belongs.private ByteBuffer
An internal cache for the next element in the FSAprivate int
Current processing depth inarcs
. -
Constructor Summary
ConstructorsConstructorDescriptionByteSequenceIterator
(FSA fsa) Create an instance of the iterator iterating over all automaton sequences.ByteSequenceIterator
(FSA fsa, int node) Create an instance of the iterator for a given node. -
Method Summary
Modifier and TypeMethodDescriptionprivate final ByteBuffer
advance()
Advances to the next available final state.boolean
hasNext()
Returnstrue
if there are still elements in this iterator.next()
private void
pushNode
(int node) Descends to a given node, adds its arcs to the stack to be traversed.void
remove()
Not implemented in this iterator.restartFrom
(int node) Restart walking fromnode
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
EXPECTED_MAX_STATES
private static final int EXPECTED_MAX_STATESDefault expected depth of the recursion stack (estimated longest sequence in the automaton). Buffers expand by the same value if exceeded.- See Also:
-
fsa
The FSA to which this iterator belongs. -
nextElement
An internal cache for the next element in the FSA -
buffer
private byte[] bufferA buffer for the current sequence of bytes from the current node to the root. -
bufferWrapper
Reusable byte buffer wrapper aroundbuffer
. -
arcs
private int[] arcsAn arc stack for DFS when processing the automaton. -
position
private int positionCurrent processing depth inarcs
.
-
-
Constructor Details
-
ByteSequenceIterator
Create an instance of the iterator iterating over all automaton sequences.- Parameters:
fsa
- The automaton to iterate over.
-
ByteSequenceIterator
Create an instance of the iterator for a given node.- Parameters:
fsa
- The automaton to iterate over.node
- The starting node's identifier (can be theFSA.getRootNode()
).
-
-
Method Details
-
restartFrom
Restart walking fromnode
. Allows iterator reuse.- Parameters:
node
- Restart the iterator fromnode
.- Returns:
- Returns
this
for call chaining.
-
hasNext
public boolean hasNext()Returnstrue
if there are still elements in this iterator.- Specified by:
hasNext
in interfaceIterator<ByteBuffer>
-
next
- Specified by:
next
in interfaceIterator<ByteBuffer>
- Returns:
- Returns a
ByteBuffer
with the sequence corresponding to the next final state in the automaton.
-
advance
Advances to the next available final state. -
remove
public void remove()Not implemented in this iterator.- Specified by:
remove
in interfaceIterator<ByteBuffer>
-
pushNode
private void pushNode(int node) Descends to a given node, adds its arcs to the stack to be traversed.
-