Mercurial > pub > ImplabNet
comparison Implab/Automaton/RegularExpressions/RegularDFADefinition.cs @ 164:ec35731ae299 ref20160224
Almost complete DFA refactoring
author | cin |
---|---|
date | Thu, 25 Feb 2016 02:11:13 +0300 |
parents | |
children | e227e78d72e4 |
comparison
equal
deleted
inserted
replaced
163:419aa51b04fd | 164:ec35731ae299 |
---|---|
1 using System; | |
2 | |
3 namespace Implab.Automaton.RegularExpressions { | |
4 public class RegularDFADefinition<TInput, TTag> : DFATransitionTable<TTag>, IDFATransitionTable<TTag> { | |
5 | |
6 readonly IAlphabet<TInput> m_alphabet; | |
7 readonly int m_initialState; | |
8 | |
9 public RegularDFADefinition(IAlphabet<TInput> alphabet, int initialState) { | |
10 Safe.ArgumentNotNull(alphabet, "aplhabet"); | |
11 | |
12 m_alphabet = alphabet; | |
13 m_initialState = initialState; | |
14 } | |
15 | |
16 | |
17 public IAlphabet<TInput> InputAlphabet { | |
18 get { | |
19 return m_alphabet; | |
20 } | |
21 } | |
22 | |
23 protected override DFAStateDescriptior<TTag>[] ConstructTransitionTable() { | |
24 if (InputAlphabet.Count != m_alphabet.Count) | |
25 throw new InvalidOperationException("The alphabet doesn't match the transition table"); | |
26 | |
27 return base.ConstructTransitionTable(); | |
28 } | |
29 | |
30 /// <summary> | |
31 /// Optimize the specified alphabet. | |
32 /// </summary> | |
33 /// <param name="alphabet">Пустой алфавит, который будет зполнен в процессе оптимизации.</param> | |
34 public RegularDFADefinition<TInput, TTag> Optimize(IAlphabetBuilder<TInput> alphabet) { | |
35 Safe.ArgumentNotNull(alphabet, "alphabet"); | |
36 | |
37 var optimalDFA = new RegularDFADefinition<TInput,TTag>(alphabet, m_initialState); | |
38 | |
39 Optimize(optimalDFA, InputAlphabet, alphabet, new DummyAlphabet(StateCount), new MapAlphabet<int>()); | |
40 | |
41 } | |
42 | |
43 | |
44 } | |
45 } | |
46 |