public bool Recognizes(string text) { HashSet <int> pc = new HashSet <int>(); DirectedDFS dfs = new DirectedDFS(G, 0); for (int v = 0; v < G.V(); v++) { if (dfs.Reachable(v)) { pc.Add(v); } } for (int i = 0; i < text.Length; i++) { HashSet <int> match = new HashSet <int>(); foreach (int v in pc) { if (v < _re.Length) { if (_re[v] == text[i] || _re[v] == '.') { match.Add(v + 1); } } } pc = new HashSet <int>(); dfs = new DirectedDFS(G, match); for (int v = 0; v < G.V(); v++) { if (dfs.Reachable(v)) { pc.Add(v); } } } foreach (int v in pc) { if (v == _re.Length) { return(true); } } return(false); }
public bool Recognizes(string txt) { var pc = new Bag <int>(); var dfs = new DirectedDFS(_graph, 0); for (var v = 0; v < _graph.GetVertices(); v++) { if (dfs.Marked(v)) { pc.Add(v); } } for (var i = 0; i < txt.Length; i++) { var match = new Bag <int>(); foreach (var v in pc) { if (v < _states) { if (_regx[v] == txt[i] || _regx[v] == '.') { match.Add(v + 1); } } } pc = new Bag <int>(); dfs = new DirectedDFS(_graph, match); for (var v = 0; v < _graph.GetVertices(); v++) { if (dfs.Marked(v)) { pc.Add(v); } } } return(pc.Any(v => v == _states)); }