IFiniteAutomaton <char> IFiniteAutomatonBuilder <char> .Build() { if (pattern.Length == 0) { return(new EmptyPatternFiniteAutomaton()); } StringMatchAutomatonState[] states = new StringMatchAutomatonState[pattern.Length + 1]; StringBuilder text = new StringBuilder(pattern.Length); for (int n = 0; n < states.Length; n++) { StringMatchAutomatonState state = states[n] ?? (states[n] = new StringMatchAutomatonState(n)); text.Append(0); char symbol = char.MaxValue; do { symbol++; text[n] = symbol; int value = CalculateSuffixFunction(text.ToString(), pattern); if (value != 0) { if (states[value] == null) { states[value] = new StringMatchAutomatonState(value); } state.SetTransition(symbol, states[value]); } }while(symbol != char.MaxValue); if (n != pattern.Length) { text[n] = pattern[n]; } } return(new StringMatchFiniteAutomaton(states.First(), states.Last())); }
public StringMatchAutomatonStateDebugView(StringMatchAutomatonState owner) { Guard.IsNotNull(owner, nameof(owner)); this.owner = owner; this.hashMap = owner.HashMap; }
public StringMatchFiniteAutomaton(StringMatchAutomatonState startState, StringMatchAutomatonState acceptingState) { this.startState = startState; this.currentState = startState; this.acceptingState = acceptingState; }
internal void SetTransition(char symbol, StringMatchAutomatonState state) { hashMap[symbol] = state; }