changeset 167:96681e9d0cea ref20160224

sync
author cin
date Wed, 02 Mar 2016 00:20:48 +0300
parents b84cdbe82e7f
children 8fb9c9507a26
files Implab/Automaton/DFATransitionTable.cs Implab/Automaton/IDFATableBuilder.cs Implab/Automaton/IndexedAlphabetBase.cs
diffstat 3 files changed, 13 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/Implab/Automaton/DFATransitionTable.cs	Mon Feb 29 18:41:01 2016 +0300
+++ b/Implab/Automaton/DFATransitionTable.cs	Wed Mar 02 00:20:48 2016 +0300
@@ -4,14 +4,14 @@
 using System.Linq;
 
 namespace Implab.Automaton {
-    public class DFATransitionTable<TTag> : IDFATableBuilder {
+    public class DFATransitionTable : IDFATableBuilder {
         DFAStateDescriptior[] m_dfaTable;
 
         int m_stateCount;
         int m_symbolCount;
         int m_initialState;
 
-        readonly Dictionary<int, TTag[]> m_finalStates = new Dictionary<int, TTag[]>();
+        readonly HashSet<int> m_finalStates = new HashSet<int>();
         readonly HashSet<AutomatonTransition> m_transitions = new HashSet<AutomatonTransition>();
 
 
@@ -32,10 +32,10 @@
         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<KeyValuePair<int,TTag[]>> FinalStates {
+        public IEnumerable<int> FinalStates {
             get {
                 return m_finalStates;
             }
@@ -55,8 +55,8 @@
 
         #endregion
 
-        protected virtual DFAStateDescriptior<TTag>[] ConstructTransitionTable() {
-            var dfaTable = new DFAStateDescriptior<TTag>[m_stateCount];
+        protected virtual DFAStateDescriptior[] ConstructTransitionTable() {
+            var dfaTable = new DFAStateDescriptior[m_stateCount];
 
             foreach (var pair in m_finalStates) {
                 var idx = pair.Key;
--- a/Implab/Automaton/IDFATableBuilder.cs	Mon Feb 29 18:41:01 2016 +0300
+++ b/Implab/Automaton/IDFATableBuilder.cs	Wed Mar 02 00:20:48 2016 +0300
@@ -1,22 +1,14 @@
 using System;
+using System.Collections.Generic;
 
 namespace Implab.Automaton {
-    public interface IDFATableBuilder : IDFATable {
+    public interface IDFATableBuilder : IDFATable, ICollection<AutomatonTransition> {
         /// <summary>
         /// Marks the state as final.
         /// </summary>
         /// <param name="state">State.</param>
         void MarkFinalState(int state);
 
-        /// <summary>
-        /// Defines the transition from <paramref name="s1"/> to
-        /// <paramref name="s2"/> with input <paramref name="symbol"/>.
-        /// </summary>
-        /// <param name="s1">S1.</param>
-        /// <param name="s2">S2.</param>
-        /// <param name="symbol">Symbol.</param>
-        void DefineTransition(int s1, int s2, int symbol);
-
         void SetInitialState(int s);
 
     }
--- a/Implab/Automaton/IndexedAlphabetBase.cs	Mon Feb 29 18:41:01 2016 +0300
+++ b/Implab/Automaton/IndexedAlphabetBase.cs	Wed Mar 02 00:20:48 2016 +0300
@@ -8,6 +8,11 @@
     /// <summary>
     /// Indexed alphabet is the finite set of symbols where each symbol has a zero-based unique index.
     /// </summary>
+    /// <remarks>
+    /// 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.
+    /// </remarks>
     public abstract class IndexedAlphabetBase<T> : IAlphabetBuilder<T> {
         int m_nextId = 1;
         readonly int[] m_map;