public MatchResult match(MatchResult reuse, byte[] sequence, int start, int length, int node) {
    if (node == 0) {
      reuse.reset(MatchResult.NO_MATCH, start, node);
      return reuse;
    }

    final FST fst = _fst;
    final int end = start + length;
    for (int i = start; i < end; i++) {
      final int arc = fst.getArc(node, sequence[i]);
      if (arc != 0) {
        if (i + 1 == end && fst.isArcFinal(arc)) {
          /* The automaton has an exact match of the input sequence. */
          reuse.reset(MatchResult.EXACT_MATCH, i, node);
          return reuse;
        }

        if (fst.isArcTerminal(arc)) {
          /* The automaton contains a prefix of the input sequence. */
          reuse.reset(MatchResult.AUTOMATON_HAS_PREFIX, i + 1, node);
          return reuse;
        }

        // Make a transition along the arc.
        node = fst.getEndNode(arc);
      } else {
        if (i > start) {
          reuse.reset(MatchResult.AUTOMATON_HAS_PREFIX, i, node);
        } else {
          reuse.reset(MatchResult.NO_MATCH, i, node);
        }
        return reuse;
      }
    }

    /* The sequence is a prefix of at least one sequence in the automaton. */
    reuse.reset(MatchResult.SEQUENCE_IS_A_PREFIX, 0, node);
    return reuse;
  }
@Test
  public void testMatch()
      throws IOException {
    File file = new File("./src/test/resources/data/abc.native.fst");
    FST fst = FST.read(new FileInputStream(file), false, new DirectMemoryManager(FSTTraversalTest.class.getName()));
    FSTTraversal traversalHelper = new FSTTraversal(fst);

    MatchResult m = traversalHelper.match("ax".getBytes());
    assertEquals(m._kind, AUTOMATON_HAS_PREFIX);
    assertEquals(m._index, 1);
    assertEquals(suffixes(fst, m._node), Sets.newHashSet("ba", "c"));

    assertEquals(traversalHelper.match("aba".getBytes())._kind, EXACT_MATCH);

    m = traversalHelper.match("abalonger".getBytes());
    assertEquals(m._kind, AUTOMATON_HAS_PREFIX);
    assertEquals("abalonger".substring(m._index), "longer");

    m = traversalHelper.match("ab".getBytes());
    assertEquals(m._kind, SEQUENCE_IS_A_PREFIX);
    assertEquals(suffixes(fst, m._node), Sets.newHashSet("a"));
  }