diff --git a/Implab/Automaton/DFATransitionTable.cs b/Implab/Automaton/DFATransitionTable.cs --- a/Implab/Automaton/DFATransitionTable.cs +++ b/Implab/Automaton/DFATransitionTable.cs @@ -4,14 +4,14 @@ using System.Collections.Generic; using System.Linq; namespace Implab.Automaton { - public class DFATransitionTable : IDFATableBuilder { + public class DFATransitionTable : IDFATableBuilder { DFAStateDescriptior[] m_dfaTable; int m_stateCount; int m_symbolCount; int m_initialState; - readonly Dictionary m_finalStates = new Dictionary(); + readonly HashSet m_finalStates = new HashSet(); readonly HashSet m_transitions = new HashSet(); @@ -32,10 +32,10 @@ namespace Implab.Automaton { public bool IsFinalState(int s) { Safe.ArgumentInRange(s, 0, m_stateCount, "s"); - return m_finalStates.ContainsKey(s); + return m_dfaTable != null ? m_dfaTable[s].final : m_finalStates.Contains(s); } - public IEnumerable> FinalStates { + public IEnumerable FinalStates { get { return m_finalStates; } @@ -55,8 +55,8 @@ namespace Implab.Automaton { #endregion - protected virtual DFAStateDescriptior[] ConstructTransitionTable() { - var dfaTable = new DFAStateDescriptior[m_stateCount]; + protected virtual DFAStateDescriptior[] ConstructTransitionTable() { + var dfaTable = new DFAStateDescriptior[m_stateCount]; foreach (var pair in m_finalStates) { var idx = pair.Key; diff --git a/Implab/Automaton/IDFATableBuilder.cs b/Implab/Automaton/IDFATableBuilder.cs --- a/Implab/Automaton/IDFATableBuilder.cs +++ b/Implab/Automaton/IDFATableBuilder.cs @@ -1,22 +1,14 @@ using System; +using System.Collections.Generic; namespace Implab.Automaton { - public interface IDFATableBuilder : IDFATable { + public interface IDFATableBuilder : IDFATable, ICollection { /// /// Marks the state as final. /// /// State. void MarkFinalState(int state); - /// - /// Defines the transition from to - /// with input . - /// - /// S1. - /// S2. - /// Symbol. - void DefineTransition(int s1, int s2, int symbol); - void SetInitialState(int s); } diff --git a/Implab/Automaton/IndexedAlphabetBase.cs b/Implab/Automaton/IndexedAlphabetBase.cs --- a/Implab/Automaton/IndexedAlphabetBase.cs +++ b/Implab/Automaton/IndexedAlphabetBase.cs @@ -8,6 +8,11 @@ namespace Implab.Automaton { /// /// Indexed alphabet is the finite set of symbols where each symbol has a zero-based unique index. /// + /// + /// Indexed alphabets are usefull in bulting efficient translations from source alphabet + /// to the input alphabet of the automaton. It's assumed that the index to the symbol match + /// is well known and documented. + /// public abstract class IndexedAlphabetBase : IAlphabetBuilder { int m_nextId = 1; readonly int[] m_map;