public static int Search(string pattern, string source, int startIndex) { char[] x = pattern.ToCharArray(), y = source.ToCharArray(startIndex, source.Length - startIndex); int j, state, m = x.Length, n = y.Length; Graph aut; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); /* Preprocessing */ aut = Automata.NewAutomaton(m + 1, (m + 1) * 65536); PreAut(x, aut); stopwatch.Stop(); preProcessTime = stopwatch.Elapsed.TotalMilliseconds; stopwatch.Restart(); /* Searching */ for (state = Automata.GetInitial(aut), j = 0; j < n; ++j) { state = Automata.GetTarget(aut, state, y[j]); if (Automata.IsTerminal(aut, state)) { stopwatch.Stop(); searchTime = stopwatch.Elapsed.TotalMilliseconds; return(j - m + 1 + startIndex); } } stopwatch.Stop(); searchTime = stopwatch.Elapsed.TotalMilliseconds; return(-1); }