Mercurial > pub > ImplabNet
comparison Implab/Automaton/MapAlphabet.cs @ 164:ec35731ae299 ref20160224
Almost complete DFA refactoring
| author | cin | 
|---|---|
| date | Thu, 25 Feb 2016 02:11:13 +0300 | 
| parents | 419aa51b04fd | 
| children | 0f70905b4652 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 163:419aa51b04fd | 164:ec35731ae299 | 
|---|---|
| 3 using System.Linq; | 3 using System.Linq; | 
| 4 | 4 | 
| 5 namespace Implab.Automaton { | 5 namespace Implab.Automaton { | 
| 6 public class MapAlphabet<T> : IAlphabetBuilder<T> { | 6 public class MapAlphabet<T> : IAlphabetBuilder<T> { | 
| 7 readonly Dictionary<T,int> m_map; | 7 readonly Dictionary<T,int> m_map; | 
| 8 int m_nextCls; | 8 int m_nextCls = 1; | 
| 9 | |
| 10 public MapAlphabet() { | |
| 11 m_map = new Dictionary<T, int>(); | |
| 12 } | |
| 9 | 13 | 
| 10 public MapAlphabet(IEqualityComparer<T> comparer) { | 14 public MapAlphabet(IEqualityComparer<T> comparer) { | 
| 11 m_map = new Dictionary<T, int>(comparer); | 15 m_map = new Dictionary<T, int>(comparer); | 
| 12 m_nextCls = 1; | |
| 13 } | 16 } | 
| 14 | 17 | 
| 15 #region IAlphabetBuilder implementation | 18 #region IAlphabetBuilder implementation | 
| 16 | 19 | 
| 17 public int DefineSymbol(T symbol) { | 20 public int DefineSymbol(T symbol) { | 
| 69 | 72 | 
| 70 var rmap = CreateReverseMap(); | 73 var rmap = CreateReverseMap(); | 
| 71 var map = new int[rmap.Length]; | 74 var map = new int[rmap.Length]; | 
| 72 | 75 | 
| 73 foreach (var cls in classes) { | 76 foreach (var cls in classes) { | 
| 77 if (cls.Contains(DFAConst.UNCLASSIFIED_INPUT)) | |
| 78 continue; | |
| 79 | |
| 74 var symbols = new List<T>(); | 80 var symbols = new List<T>(); | 
| 75 foreach (var id in cls) { | 81 foreach (var id in cls) { | 
| 76 if (id < 0 || id >= rmap.Length) | 82 if (id < 0 || id >= rmap.Length) | 
| 77 throw new ArgumentOutOfRangeException(String.Format("Class {0} is not valid for the current alphabet", id)); | 83 throw new ArgumentOutOfRangeException(String.Format("Class {0} is not valid for the current alphabet", id)); | 
| 78 if (rmap[id] != null) | 84 if (rmap[id] != null) | 
