Mercurial > pub > ImplabNet
comparison Implab/Automaton/DummyAlphabet.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 |
---|---|
1 using System; | 1 using System; |
2 using System.Collections.Generic; | 2 using System.Collections.Generic; |
3 using System.Linq; | 3 using System.Linq; |
4 | 4 |
5 namespace Implab.Automaton { | 5 namespace Implab.Automaton { |
6 /// <summary> | |
7 /// Dummy alphabet consists of integer numbers which are identical to their classes. | |
8 /// </summary> | |
6 public class DummyAlphabet : IAlphabet<int> { | 9 public class DummyAlphabet : IAlphabet<int> { |
7 readonly int m_size; | 10 readonly int m_size; |
11 | |
12 /// <summary> | |
13 /// Creates a new dummy alphabet with given size. | |
14 /// </summary> | |
15 /// <param name="size">The size of the alphabet, must be greater then zero.</param> | |
8 public DummyAlphabet(int size) { | 16 public DummyAlphabet(int size) { |
9 Safe.ArgumentAssert(size > 0); | 17 Safe.ArgumentAssert(size > 0); |
10 m_size = 0; | 18 m_size = 0; |
11 } | 19 } |
12 | 20 |
19 public int[] Reclassify(IAlphabetBuilder<int> newAlphabet, IEnumerable<IEnumerable<int>> classes) { | 27 public int[] Reclassify(IAlphabetBuilder<int> newAlphabet, IEnumerable<IEnumerable<int>> classes) { |
20 Safe.ArgumentNotNull(newAlphabet, "newAlphabet"); | 28 Safe.ArgumentNotNull(newAlphabet, "newAlphabet"); |
21 Safe.ArgumentNotNull(classes, "classes"); | 29 Safe.ArgumentNotNull(classes, "classes"); |
22 var map = new int[m_size]; | 30 var map = new int[m_size]; |
23 foreach (var cls in classes) { | 31 foreach (var cls in classes) { |
32 if (cls.Contains(DFAConst.UNCLASSIFIED_INPUT)) | |
33 continue; | |
24 var newid = newAlphabet.DefineClass(cls); | 34 var newid = newAlphabet.DefineClass(cls); |
25 foreach (var id in cls) | 35 foreach (var id in cls) |
26 map[id] = newid; | 36 map[id] = newid; |
27 } | 37 } |
28 | 38 |