Mercurial > pub > ImplabNet
comparison Implab/Automaton/DFATransitionTable.cs @ 167:96681e9d0cea ref20160224
sync
| author | cin |
|---|---|
| date | Wed, 02 Mar 2016 00:20:48 +0300 |
| parents | e227e78d72e4 |
| children | 8fb9c9507a26 |
comparison
equal
deleted
inserted
replaced
| 166:b84cdbe82e7f | 167:96681e9d0cea |
|---|---|
| 2 using System; | 2 using System; |
| 3 using System.Collections.Generic; | 3 using System.Collections.Generic; |
| 4 using System.Linq; | 4 using System.Linq; |
| 5 | 5 |
| 6 namespace Implab.Automaton { | 6 namespace Implab.Automaton { |
| 7 public class DFATransitionTable<TTag> : IDFATableBuilder { | 7 public class DFATransitionTable : IDFATableBuilder { |
| 8 DFAStateDescriptior[] m_dfaTable; | 8 DFAStateDescriptior[] m_dfaTable; |
| 9 | 9 |
| 10 int m_stateCount; | 10 int m_stateCount; |
| 11 int m_symbolCount; | 11 int m_symbolCount; |
| 12 int m_initialState; | 12 int m_initialState; |
| 13 | 13 |
| 14 readonly Dictionary<int, TTag[]> m_finalStates = new Dictionary<int, TTag[]>(); | 14 readonly HashSet<int> m_finalStates = new HashSet<int>(); |
| 15 readonly HashSet<AutomatonTransition> m_transitions = new HashSet<AutomatonTransition>(); | 15 readonly HashSet<AutomatonTransition> m_transitions = new HashSet<AutomatonTransition>(); |
| 16 | 16 |
| 17 | 17 |
| 18 #region IDFADefinition implementation | 18 #region IDFADefinition implementation |
| 19 | 19 |
| 30 } | 30 } |
| 31 | 31 |
| 32 public bool IsFinalState(int s) { | 32 public bool IsFinalState(int s) { |
| 33 Safe.ArgumentInRange(s, 0, m_stateCount, "s"); | 33 Safe.ArgumentInRange(s, 0, m_stateCount, "s"); |
| 34 | 34 |
| 35 return m_finalStates.ContainsKey(s); | 35 return m_dfaTable != null ? m_dfaTable[s].final : m_finalStates.Contains(s); |
| 36 } | 36 } |
| 37 | 37 |
| 38 public IEnumerable<KeyValuePair<int,TTag[]>> FinalStates { | 38 public IEnumerable<int> FinalStates { |
| 39 get { | 39 get { |
| 40 return m_finalStates; | 40 return m_finalStates; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 53 get { return m_initialState; } | 53 get { return m_initialState; } |
| 54 } | 54 } |
| 55 | 55 |
| 56 #endregion | 56 #endregion |
| 57 | 57 |
| 58 protected virtual DFAStateDescriptior<TTag>[] ConstructTransitionTable() { | 58 protected virtual DFAStateDescriptior[] ConstructTransitionTable() { |
| 59 var dfaTable = new DFAStateDescriptior<TTag>[m_stateCount]; | 59 var dfaTable = new DFAStateDescriptior[m_stateCount]; |
| 60 | 60 |
| 61 foreach (var pair in m_finalStates) { | 61 foreach (var pair in m_finalStates) { |
| 62 var idx = pair.Key; | 62 var idx = pair.Key; |
| 63 | 63 |
| 64 dfaTable[idx].final = true; | 64 dfaTable[idx].final = true; |
