Class FSATraversal


  • public final class FSATraversal
    extends Object
    This class implements some common matching and scanning operations on a generic FSA.
    • Constructor Detail

      • FSATraversal

        public FSATraversal​(FSA fsa)
        Traversals of the given FSA.
        Parameters:
        fsa - The target automaton for traversals.
    • Method Detail

      • perfectHash

        public int perfectHash​(byte[] sequence,
                               int start,
                               int length,
                               int node)
        Calculate perfect hash for a given input sequence of bytes. The perfect hash requires that FSA is built with FSAFlags.NUMBERS and corresponds to the sequential order of input sequences used at automaton construction time.
        Parameters:
        sequence - The byte sequence to calculate perfect hash for.
        start - Start index in the sequence array.
        length - Length of the byte sequence, must be at least 1.
        node - The node to start traversal from, typically the root node.
        Returns:
        Returns a unique integer assigned to the input sequence in the automaton (reflecting the number of that sequence in the input used to build the automaton). Returns a negative integer if the input sequence was not part of the input from which the automaton was created. The type of mismatch is a constant defined in MatchResult.
      • perfectHash

        public int perfectHash​(byte[] sequence)
        Parameters:
        sequence - The byte sequence to calculate perfect hash for.
        Returns:
        Returns a unique integer assigned to the input sequence in the automaton (reflecting the number of that sequence in the input used to build the automaton). Returns a negative integer if the input sequence was not part of the input from which the automaton was created. The type of mismatch is a constant defined in MatchResult.
        See Also:
        perfectHash(byte[], int, int, int)
      • match

        public MatchResult match​(MatchResult reuse,
                                 byte[] sequence,
                                 int start,
                                 int length,
                                 int node)
        Same as match(byte[], int, int, int), but allows passing a reusable MatchResult object so that no intermediate garbage is produced.
        Parameters:
        reuse - The MatchResult to reuse.
        sequence - Input sequence to look for in the automaton.
        start - Start index in the sequence array.
        length - Length of the byte sequence, must be at least 1.
        node - The node to start traversal from, typically the root node.
        Returns:
        The same object as reuse, but with updated match MatchResult.kind and other relevant fields.
      • match

        public MatchResult match​(byte[] sequence,
                                 int start,
                                 int length,
                                 int node)
        Finds a matching path in the dictionary for a given sequence of labels from sequence and starting at node node.
        Parameters:
        sequence - Input sequence to look for in the automaton.
        start - Start index in the sequence array.
        length - Length of the byte sequence, must be at least 1.
        node - The node to start traversal from, typically the root node.
        Returns:
        MatchResult with updated match MatchResult.kind.
        See Also:
        match(byte [], int)