// Does not set any of the mapping information. Use the CreateBasicMap() // factory method if you want the mapping dictionary filled in for symbols // that match in both the alphabet and the encoding. internal EncodingMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { this.alphabet = alphabet; this.encoding = encoding; this.direction = direction; }
// Does a direct symbol comparison to create the dictionary used in the mapping // This is a useful starting point for any map. The dictionary can then be customized // by adding or removing entries. internal static EncodingMap CreateBasicMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { EncodingMap result = new EncodingMap(alphabet, encoding, direction); if (direction == EncodingMapDirection.AlphabetToEncoding) { foreach (ISequenceItem sourceItem in alphabet) { try { ISequenceItem resultItem = encoding.LookupBySymbol(sourceItem.Symbol); result.map[sourceItem] = resultItem; } catch (Exception) { // Ignore the exception and just continue filling the dictionary } } } else if (direction == EncodingMapDirection.EncodingToAlphabet) { foreach (ISequenceItem sourceItem in encoding) { try { ISequenceItem resultItem = alphabet.LookupBySymbol(sourceItem.Symbol); result.map[sourceItem] = resultItem; } catch (Exception) { // Ignore the exception and just continue filling the dictionary } } } return(result); }
// Does a direct symbol comparison to create the dictionary used in the mapping // This is a useful starting point for any map. The dictionary can then be customized // by adding or removing entries. internal static EncodingMap CreateBasicMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { EncodingMap result = new EncodingMap(alphabet, encoding, direction); if (direction == EncodingMapDirection.AlphabetToEncoding) { result.map = GetMap( alphabet, item => encoding.LookupBySymbol(item.Symbol)); } else if (direction == EncodingMapDirection.EncodingToAlphabet) { result.map = GetMap( encoding, item => alphabet.LookupBySymbol(item.Symbol)); } return(result); }