public final class CFSA2Serializer extends java.lang.Object implements FSASerializer
FSA graphs to CFSA2.
It is possible to serialize the automaton with numbers required for perfect
hashing. See withNumbers() method.
CFSA2| Modifier and Type | Field and Description |
|---|---|
private static java.util.EnumSet<FSAFlags> |
flags
Supported flags.
|
private byte[] |
labelsIndex
The most frequent labels for integrating with the flags field.
|
private int[] |
labelsInvIndex
Inverted index of labels to be integrated with flags field.
|
private java.util.logging.Logger |
logger |
private static int |
NO_STATE
No-state id.
|
private com.carrotsearch.hppc.IntIntHashMap |
numbers
A hash map of [state, right-language-count] pairs.
|
private com.carrotsearch.hppc.IntIntHashMap |
offsets
A hash map of [state, offset] pairs.
|
private byte[] |
scratch
Scratch array for serializing vints.
|
private boolean |
withNumbers
true if we should serialize with numbers. |
| Constructor and Description |
|---|
CFSA2Serializer() |
| Modifier and Type | Method and Description |
|---|---|
private java.util.ArrayDeque<java.lang.Integer> |
computeFirstStates(com.carrotsearch.hppc.IntIntHashMap inlinkCount,
int maxStates,
int minInlinkCount)
Compute the set of states that should be linearized first to minimize other
states goto length.
|
private com.carrotsearch.hppc.IntIntHashMap |
computeInlinkCount(FSA fsa)
Compute in-link count for each state.
|
private void |
computeLabelsIndex(FSA fsa)
Compute a set of labels to be integrated with the flags field.
|
private int |
emitArc(java.io.OutputStream os,
int flags,
byte label,
int targetOffset) |
private int |
emitNodeArcs(FSA fsa,
java.io.OutputStream os,
int state,
int nextState)
Emit all arcs of a single node.
|
private int |
emitNodeData(java.io.OutputStream os,
int number) |
private int |
emitNodes(FSA fsa,
java.io.OutputStream os,
com.carrotsearch.hppc.IntArrayList linearized)
Update arc offsets assuming the given goto length.
|
java.util.Set<FSAFlags> |
getFlags()
Return supported flags.
|
private com.carrotsearch.hppc.IntArrayList |
linearize(FSA fsa)
Linearization of states.
|
private int |
linearizeAndCalculateOffsets(FSA fsa,
com.carrotsearch.hppc.IntArrayList states,
com.carrotsearch.hppc.IntArrayList linearized,
com.carrotsearch.hppc.IntIntHashMap offsets)
Linearize all states, putting
states in front of the automaton
and calculating stable state offsets. |
private void |
linearizeState(FSA fsa,
com.carrotsearch.hppc.IntStack nodes,
com.carrotsearch.hppc.IntArrayList linearized,
com.carrotsearch.hppc.BitSet visited,
int node)
Add a state to linearized list.
|
private void |
log(java.util.logging.Level level,
java.lang.String msg,
java.lang.Object... args) |
<T extends java.io.OutputStream> |
serialize(FSA fsa,
T os)
|
CFSA2Serializer |
withAnnotationSeparator(byte annotationSeparator)
Sets the annotation separator (only if
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS). |
CFSA2Serializer |
withFiller(byte filler)
Sets the filler separator (only if
FSASerializer.getFlags() returns
FSAFlags.SEPARATORS). |
CFSA2Serializer |
withNumbers()
Serialize the automaton with the number of right-language sequences in each
node.
|
(package private) static int |
writeVInt(byte[] array,
int offset,
int value)
Write a v-int to a byte array.
|
private final java.util.logging.Logger logger
private static final java.util.EnumSet<FSAFlags> flags
private static final int NO_STATE
private boolean withNumbers
true if we should serialize with numbers.withNumbers()private com.carrotsearch.hppc.IntIntHashMap offsets
private com.carrotsearch.hppc.IntIntHashMap numbers
private final byte[] scratch
private byte[] labelsIndex
private int[] labelsInvIndex
i has the index or zero (no integration).public CFSA2Serializer withNumbers()
withNumbers in interface FSASerializerpublic <T extends java.io.OutputStream> T serialize(FSA fsa, T os) throws java.io.IOException
serialize in interface FSASerializerT - A subclass of OutputStream, returned for chaining.fsa - The automaton to serialize.os - The output stream to serialize to.os for chaining.java.io.IOException - Rethrown if an I/O error occurs.withNumbers()private void computeLabelsIndex(FSA fsa)
public java.util.Set<FSAFlags> getFlags()
getFlags in interface FSASerializerprivate com.carrotsearch.hppc.IntArrayList linearize(FSA fsa) throws java.io.IOException
java.io.IOExceptionprivate void log(java.util.logging.Level level,
java.lang.String msg,
java.lang.Object... args)
private int linearizeAndCalculateOffsets(FSA fsa, com.carrotsearch.hppc.IntArrayList states, com.carrotsearch.hppc.IntArrayList linearized, com.carrotsearch.hppc.IntIntHashMap offsets) throws java.io.IOException
states in front of the automaton
and calculating stable state offsets.java.io.IOExceptionprivate void linearizeState(FSA fsa, com.carrotsearch.hppc.IntStack nodes, com.carrotsearch.hppc.IntArrayList linearized, com.carrotsearch.hppc.BitSet visited, int node)
private java.util.ArrayDeque<java.lang.Integer> computeFirstStates(com.carrotsearch.hppc.IntIntHashMap inlinkCount,
int maxStates,
int minInlinkCount)
private com.carrotsearch.hppc.IntIntHashMap computeInlinkCount(FSA fsa)
private int emitNodes(FSA fsa, java.io.OutputStream os, com.carrotsearch.hppc.IntArrayList linearized) throws java.io.IOException
java.io.IOExceptionprivate int emitNodeArcs(FSA fsa, java.io.OutputStream os, int state, int nextState) throws java.io.IOException
java.io.IOExceptionprivate int emitArc(java.io.OutputStream os,
int flags,
byte label,
int targetOffset)
throws java.io.IOException
java.io.IOExceptionprivate int emitNodeData(java.io.OutputStream os,
int number)
throws java.io.IOException
java.io.IOExceptionpublic CFSA2Serializer withFiller(byte filler)
FSASerializerFSASerializer.getFlags() returns
FSAFlags.SEPARATORS).withFiller in interface FSASerializerfiller - The filler separator byte.this for call chaining.public CFSA2Serializer withAnnotationSeparator(byte annotationSeparator)
FSASerializerFSASerializer.getFlags() returns
FSAFlags.SEPARATORS).withAnnotationSeparator in interface FSASerializerannotationSeparator - The filler separator byte.this for call chaining.static int writeVInt(byte[] array,
int offset,
int value)