public static WordCharMap CreateCharIndexMap(WordList wordList, bool reverse = false) { ImmutableDictionary <WordChar, ImmutableHashSet <string> > map = wordList.Values .Select(s => { return( value: s, chars: ((reverse) ? s.Reverse() : s).Select((ch, i) => (ch, i))); }) .SelectMany(f => f.chars.Select(g => { return( f.value, g.ch, g.i, key: new WordChar(g.ch, g.i)); })) .GroupBy(f => f.key) .ToImmutableDictionary( f => f.Key, f => f.Select(f => f.value).ToImmutableHashSet(wordList.Comparer)); return(new WordCharMap(wordList, map)); }
public static void Save( string path, WordList wordList) { Save(path, wordList.Values, wordList.Comparer); }
private WordCharMap(WordList list, ImmutableDictionary <WordChar, ImmutableHashSet <string> > map) { List = list; Map = map; }