public final class CFSA2 extends FSA
BIT_TARGET_NEXT applicable on all arcs, not necessarily the last one.The encoding of automaton body is as follows.
---- CFSA header
Byte Description
+-+-+-+-+-+-+-+-+\
0 | | | | | | | | | +------ '\'
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
1 | | | | | | | | | +------ 'f'
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
2 | | | | | | | | | +------ 's'
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
3 | | | | | | | | | +------ 'a'
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
4 | | | | | | | | | +------ version (fixed 0xc6)
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
5 | | | | | | | | | +----\
+-+-+-+-+-+-+-+-+/ \ flags [MSB first]
+-+-+-+-+-+-+-+-+\ /
6 | | | | | | | | | +----/
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
7 | | | | | | | | | +------ label lookup table size
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
8-32 | | | | | | | | | +------ label value lookup table
: : : : : : : : : |
+-+-+-+-+-+-+-+-+/
---- Start of a node; only if automaton was compiled with NUMBERS option.
Byte
+-+-+-+-+-+-+-+-+\
0 | | | | | | | | | \
+-+-+-+-+-+-+-+-+ +
1 | | | | | | | | | | number of strings recognized
+-+-+-+-+-+-+-+-+ +----- by the automaton starting
: : : : : : : : : | from this node. v-coding
+-+-+-+-+-+-+-+-+ +
| | | | | | | | | /
+-+-+-+-+-+-+-+-+/
---- A vector of this node's arcs. An arc's layout depends on the combination of flags.
1) NEXT bit set, mapped arc label.
+----------------------- node pointed to is next
| +--------------------- the last arc of the node
| | +------------------- this arc leads to a final state (acceptor)
| | | _______+--------- arc's label; indexed if M > 0, otherwise explicit label follows
| | | / | | | |
+-+-+-+-+-+-+-+-+\
0 |N|L|F|M|M|M|M|M| +------ flags + (M) index of the mapped label.
+-+-+-+-+-+-+-+-+/
+-+-+-+-+-+-+-+-+\
1 | | | | | | | | | +------ optional label if M == 0
+-+-+-+-+-+-+-+-+/
: : : : : : : : :
+-+-+-+-+-+-+-+-+\
|A|A|A|A|A|A|A|A| +------ v-coded goto address
+-+-+-+-+-+-+-+-+/
| Modifier and Type | Field and Description |
|---|---|
byte[] |
arcs
An array of bytes with the internal representation of the automaton.
|
static int |
BIT_FINAL_ARC
The arc corresponds to the last character of a sequence
available when building the automaton (acceptor transition).
|
static int |
BIT_LAST_ARC
The arc is the last one from the current node's arcs list.
|
static int |
BIT_TARGET_NEXT
The target node of this arc follows the last arc of the current state
(no goto field).
|
private int |
epsilon
Epsilon node's offset.
|
private java.util.EnumSet<FSAFlags> |
flags
Flags for this automaton version.
|
private boolean |
hasNumbers
If
true states are prepended with numbers. |
(package private) static int |
LABEL_INDEX_BITS
The count of bits assigned to storing an indexed label.
|
(package private) static int |
LABEL_INDEX_MASK
Masks only the M bits of a flag byte.
|
static int |
LABEL_INDEX_SIZE
Maximum size of the labels index.
|
byte[] |
labelMapping
Label mapping for M-indexed labels.
|
static byte |
VERSION
Automaton header version value.
|
| Constructor and Description |
|---|
CFSA2(java.io.InputStream stream)
Reads an automaton from a byte stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getArc(int node,
byte label) |
byte |
getArcLabel(int arc) |
(package private) int |
getDestinationNodeOffset(int arc)
Returns the address of the node pointed to by this arc.
|
int |
getEndNode(int arc) |
int |
getFirstArc(int node) |
java.util.Set<FSAFlags> |
getFlags() |
int |
getNextArc(int arc) |
int |
getRightLanguageCount(int node) |
int |
getRootNode() |
boolean |
isArcFinal(int arc) |
boolean |
isArcLast(int arc)
Returns
true if this arc has NEXT bit set. |
boolean |
isArcTerminal(int arc) |
boolean |
isNextSet(int arc) |
(package private) static int |
readVInt(byte[] array,
int offset)
Read a v-int.
|
private int |
skipArc(int offset)
Read the arc's layout and skip as many bytes, as needed, to skip it.
|
private int |
skipVInt(int offset)
Skip a v-int.
|
(package private) static int |
vIntLength(int value)
Return the byte-length of a v-coded int.
|
getArcCount, getSequences, getSequences, iterator, read, read, readRemaining, visitAllStates, visitInPostOrder, visitInPostOrder, visitInPreOrder, visitInPreOrderpublic static final byte VERSION
public static final int BIT_TARGET_NEXT
public static final int BIT_LAST_ARC
public static final int BIT_FINAL_ARC
static final int LABEL_INDEX_BITS
static final int LABEL_INDEX_MASK
public static final int LABEL_INDEX_SIZE
public byte[] arcs
private final java.util.EnumSet<FSAFlags> flags
public final byte[] labelMapping
private final boolean hasNumbers
true states are prepended with numbers.private final int epsilon
CFSA2(java.io.InputStream stream) throws java.io.IOException
java.io.IOExceptionpublic int getRootNode()
getRootNode in class FSApublic final int getFirstArc(int node)
getFirstArc in class FSAnode - Identifier of the node.node
or 0 if the node has no outgoing arcs.public final int getNextArc(int arc)
getNextArc in class FSAarc - The arc's identifier.arc and
leaving node. Zero is returned if no more arcs are
available for the node.public int getArc(int node,
byte label)
public int getEndNode(int arc)
getEndNode in class FSAarc - The arc's identifier.arc.
Terminal arcs (those that point to a terminal state) have no end
node representation and throw a runtime exception.public byte getArcLabel(int arc)
getArcLabel in class FSAarc - The arc's identifier.arc.public int getRightLanguageCount(int node)
getRightLanguageCount in class FSAnode - Identifier of the node.FSAFlags.NUMBERS. The size
of the right language of the state, in other words.public boolean isArcFinal(int arc)
isArcFinal in class FSAarc - The arc's identifier.true if the destination node at the end of
this arc corresponds to an input sequence created when
building this automaton.public boolean isArcTerminal(int arc)
isArcTerminal in class FSAarc - The arc's identifier.true if this arc does not have a
terminating node (@link FSA.getEndNode(int) will throw an
exception). Implies FSA.isArcFinal(int).public boolean isArcLast(int arc)
true if this arc has NEXT bit set.arc - The node's arc identifier.BIT_LAST_ARCpublic boolean isNextSet(int arc)
arc - The node's arc identifier.BIT_TARGET_NEXT is set for this arc.BIT_TARGET_NEXTpublic java.util.Set<FSAFlags> getFlags()
final int getDestinationNodeOffset(int arc)
private int skipArc(int offset)
static int readVInt(byte[] array,
int offset)
static int vIntLength(int value)
private int skipVInt(int offset)