public IState Transition(IState state, Symbol symbol) { if (!this.allEdges.Contains(symbol)) { return(null); } var states = (state as ListState <IState>).Value; var result = new ListState <IState>(states.Select(x => null as IState).ToList()); for (int i = 0; i < states.Count(); i++) { if (states[i] == null) { continue; } var newStates = this.dfas[i].Item2.Transitions(states[i]); if (newStates.TryGetValue(symbol, out var out_state)) { (result as ListState <IState>).Value[i] = out_state; } } return(result); }
IReadOnlyDictionary <Symbol, IState> IDfa <TLabel, Symbol> .Transitions(IState state) { var states = (state as ListState <IState>).Value; var result = new Dictionary <Symbol, IState>(); foreach (var edge in this.allEdges) { result[edge] = new ListState <IState>(states.Select(x => null as IState).ToList()); } for (int i = 0; i < states.Count(); i++) { if (states[i] == null) { continue; } var newStates = this.dfas[i].Item2.Transitions(states[i]); foreach (KeyValuePair <Symbol, IState> p in newStates) { IState newState = p.Value; Symbol edge = p.Key; if (!result.ContainsKey(edge)) { // create empty state (only nulls) - null acts as an implicit fail state result[edge] = new ListState <IState>(states.Select(x => null as IState).ToList()); } (result[edge] as ListState <IState>).Value[i] = newState; } } return(result); }