annotate Implab/Automaton/DummyAlphabet.cs @ 163:419aa51b04fd ref20160224

JSON moved to Formats namespace Working in RegularDFA
author cin
date Wed, 24 Feb 2016 20:12:52 +0300
parents
children ec35731ae299
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
163
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
1 using System;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
2 using System.Collections.Generic;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
3 using System.Linq;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
4
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
5 namespace Implab.Automaton {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
6 public class DummyAlphabet : IAlphabet<int> {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
7 readonly int m_size;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
8 public DummyAlphabet(int size) {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
9 Safe.ArgumentAssert(size > 0);
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
10 m_size = 0;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
11 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
12
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
13 #region IAlphabet implementation
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
14
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
15 public List<int>[] CreateReverseMap() {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
16 Enumerable.Range(0, m_size).ToArray();
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
17 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
18
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
19 public int[] Reclassify(IAlphabetBuilder<int> newAlphabet, IEnumerable<IEnumerable<int>> classes) {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
20 Safe.ArgumentNotNull(newAlphabet, "newAlphabet");
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
21 Safe.ArgumentNotNull(classes, "classes");
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
22 var map = new int[m_size];
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
23 foreach (var cls in classes) {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
24 var newid = newAlphabet.DefineClass(cls);
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
25 foreach (var id in cls)
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
26 map[id] = newid;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
27 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
28
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
29 return map;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
30 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
31
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
32 public int Translate(int symobl) {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
33 Safe.ArgumentInRange(symobl, 0, m_size, "symbol");
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
34 return symobl;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
35 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
36
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
37 public int Count {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
38 get {
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
39 return m_size;
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
40 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
41 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
42
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
43 #endregion
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
44 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
45 }
419aa51b04fd JSON moved to Formats namespace
cin
parents:
diff changeset
46