annotate Implab/Parsing/EDFADefinition.cs @ 89:ce0171cacec4 v2

improved performance of a chained map operation
author cin
date Wed, 08 Oct 2014 02:19:45 +0400
parents c0bf853aa04f
children 97fbbf816844
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
1 using Implab;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
2 using System;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
3 using System.Collections.Generic;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
4 using System.Linq;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
5 using System.Text;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
6 using System.Threading.Tasks;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
7
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
8 namespace Implab.Parsing {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
9 public class EDFADefinition<T> : DFADefinitionBase where T : struct, IConvertible {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
10 EnumAlphabet<T> m_alphabet;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
11
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
12 public EnumAlphabet<T> Alphabet {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
13 get { return m_alphabet; }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
14 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
15
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
16 public EDFADefinition(EnumAlphabet<T> alphabet)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
17 : base() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
18 Safe.ArgumentNotNull(alphabet, "alphabet");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
19 m_alphabet = alphabet;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
20 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
21
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
22 public override int AlphabetSize {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
23 get { return m_alphabet.Count; }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
24 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
25
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
26 public EDFADefinition<T> Optimize() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
27 var optimized = new EDFADefinition<T>(new EnumAlphabet<T>());
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
28 Optimize(optimized, m_alphabet, optimized.Alphabet);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
29
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
30 return optimized;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
31 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
32
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
33 public void PrintDFA() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
34 PrintDFA(m_alphabet);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
35 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
36 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
37 }