comparison Implab/Automaton/DFATable.cs @ 180:c32688129f14 ref20160224

refactoring complete, JSONParser rewritten
author cin
date Thu, 24 Mar 2016 02:30:46 +0300
parents d5c5db0335ee
children b2b6a6640aa3
comparison
equal deleted inserted replaced
179:478ef706906a 180:c32688129f14
75 public void CopyTo(AutomatonTransition[] array, int arrayIndex) { 75 public void CopyTo(AutomatonTransition[] array, int arrayIndex) {
76 m_transitions.CopyTo(array, arrayIndex); 76 m_transitions.CopyTo(array, arrayIndex);
77 } 77 }
78 78
79 public bool Remove(AutomatonTransition item) { 79 public bool Remove(AutomatonTransition item) {
80 m_transitions.Remove(item); 80 return m_transitions.Remove(item);
81 } 81 }
82 82
83 public int Count { 83 public int Count {
84 get { 84 get {
85 return m_transitions.Count; 85 return m_transitions.Count;
166 optimalStates.Add(state); 166 optimalStates.Add(state);
167 queue.Add(state); 167 queue.Add(state);
168 168
169 var rmap = m_transitions 169 var rmap = m_transitions
170 .GroupBy(t => t.s2) 170 .GroupBy(t => t.s2)
171 .ToLookup( 171 .ToDictionary(
172 g => g.Key, // s2 172 g => g.Key, // s2
173 g => g.ToLookup(t => t.edge, t => t.s1) 173 g => g.GroupBy(t => t.edge, t => t.s1).ToDictionary(p => p.Key)
174 ); 174 );
175 175
176 while (queue.Count > 0) { 176 while (queue.Count > 0) {
177 var stateA = queue.First(); 177 var stateA = queue.First();
178 queue.Remove(stateA); 178 queue.Remove(stateA);
179 179
180 for (int c = 0; c < m_symbolCount; c++) { 180 for (int c = 0; c < m_symbolCount; c++) {
181 var stateX = new HashSet<int>(); 181 var stateX = new HashSet<int>();
182 foreach(var a in stateA) 182 foreach(var a in stateA)
183 stateX.UnionWith(rmap[a][c]); // all states from wich 'c' leads to 'a' 183 stateX.UnionWith(rmap[a][c]); // all states from wich the symbol 'c' leads to the state 'a'
184 184
185 foreach (var stateY in optimalStates.ToArray()) { 185 foreach (var stateY in optimalStates.ToArray()) {
186 if (stateX.Overlaps(stateY) && !stateY.IsSubsetOf(stateX)) { 186 if (stateX.Overlaps(stateY) && !stateY.IsSubsetOf(stateX)) {
187 var stateR1 = new HashSet<int>(stateY); 187 var stateR1 = new HashSet<int>(stateY);
188 var stateR2 = new HashSet<int>(stateY); 188 var stateR2 = new HashSet<int>(stateY);