static IEnumerable <int> ChangeBaseInternal(IEnumerable <char> src, ICharLookup inMap, ICharLookup outMap) { //the charOut/charsIn calculation is a bit magical // i'm not exactly sure why this works out but it does int charsOut = inMap.BytesIn * outMap.CharsOut; int charsIn = inMap.CharsOut * outMap.BytesIn; var unInMap = new GlifMap(inMap); int[] inArr = new int[charsIn]; int[] outArr = new int[charsOut]; int inBase = inMap.Base(); int outBase = outMap.Base(); var iter = src.GetEnumerator(); bool done = false; while (!done) { Array.Clear(inArr, 0, charsIn); Array.Clear(outArr, 0, charsOut); int inCount = 0; while (inCount < charsIn) { if (iter.MoveNext()) { int digit = unInMap.Map(iter.Current); //reverse incoming bigendgian order int iIndex = charsIn - inCount - 1; inArr[iIndex] = digit; } else { done = true; break; } inCount++; } //base calculation is done in little endian ChangeBase(inBase, outBase, inArr, ref outArr); //reverse again to restore big endianess for (int o = charsOut - 1; o >= 0; o--) { yield return(outArr[o]); } } }
void Init(ICharLookup map) { int @base = map.Base(); lookup = new Dictionary <char, int>(@base); for (int b = 0; b < @base; b++) { lookup.Add(map.Map(b), b); } if (map.IncludePadding) { Padding = map.Padding; } }