165
+ − 1 using System.Collections.Generic;
164
+ − 2 using System.Linq;
165
+ − 3 using Implab.Automaton;
228
+ − 4 using System;
164
+ − 5
165
+ − 6 namespace Implab.Formats {
236
+ − 7 public class CharAlphabet : IndexedAlphabetBase<char> {
164
+ − 8
+ − 9 public override int GetSymbolIndex(char symbol) {
+ − 10 return symbol;
+ − 11 }
+ − 12
176
+ − 13 public IEnumerable<char> InputSymbols {
164
+ − 14 get { return Enumerable.Range(char.MinValue, char.MaxValue).Cast<char>(); }
+ − 15 }
228
+ − 16
+ − 17 public CharMap CreateCharMap() {
+ − 18 var map = new Dictionary<int, int>();
+ − 19
+ − 20 int max = 0, min = char.MaxValue;
+ − 21 foreach (var p in Mappings) {
+ − 22 var index = GetSymbolIndex(p.Key);
+ − 23 max = Math.Max(max, index);
+ − 24 min = Math.Min(min, index);
+ − 25 map[index] = p.Value;
+ − 26 }
+ − 27
+ − 28 var result = new int[max - min + 1];
+ − 29
+ − 30 for (int i = 0; i < result.Length; i++)
+ − 31 map.TryGetValue(min + i, out result[i]);
+ − 32
+ − 33 return new CharMap((char)min, result);
+ − 34 }
164
+ − 35 }
+ − 36 }