##// END OF EJS Templates
code cleanup and refactoring
code cleanup and refactoring

File last commit:

r180:c32688129f14 ref20160224
r281:e0916ddc9950 v3
Show More
IndexedAlphabetBase.cs
50 lines | 1.8 KiB | text/x-csharp | CSharpLexer
/ Implab / Automaton / IndexedAlphabetBase.cs
cin
DFA refactoring
r162 using Implab;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Implab.Automaton {
/// <summary>
/// Indexed alphabet is the finite set of symbols where each symbol has a zero-based unique index.
/// </summary>
cin
sync
r167 /// <remarks>
/// Indexed alphabets are usefull in bulting efficient translations from source alphabet
/// to the input alphabet of the automaton. It's assumed that the index to the symbol match
/// is well known and documented.
/// </remarks>
cin
rewritten the text scanner
r176 public abstract class IndexedAlphabetBase<T> : MapAlphabet<T> {
cin
Working on regular DFA
r171
cin
rewritten the text scanner
r176 protected IndexedAlphabetBase() :base(true, null) {
cin
Working on text scanner
r172 }
cin
DFA refactoring
r162 public abstract int GetSymbolIndex(T symbol);
/// <summary>
/// Gets the translation map from the index of the symbol to it's class this is usefull for the optimized input symbols transtaion.
/// </summary>
cin
rewritten the text scanner
r176 /// <remarks>
/// The map is continous and start from the symbol with zero code. The last symbol
/// in the map is the last classified symbol in the alphabet, i.e. the map can be
/// shorter then the whole alphabet.
/// </remarks>
cin
DFA refactoring
r162 /// <returns>The translation map.</returns>
public int[] GetTranslationMap() {
cin
refactoring complete, JSONParser rewritten
r180 var map = new Dictionary<int, int>();
cin
rewritten the text scanner
r176
cin
refactoring complete, JSONParser rewritten
r180 int max = 0;
cin
rewritten the text scanner
r176 foreach (var p in Mappings) {
var index = GetSymbolIndex(p.Key);
max = Math.Max(max, index);
map[index] = p.Value;
}
var result = new int[max + 1];
for (int i = 0; i < result.Length; i++)
map.TryGetValue(i, out result[i]);
return result;
cin
DFA refactoring
r162 }
}
}