Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 private WordCharMap(WordList list, ImmutableDictionary <WordChar, ImmutableHashSet <string> > map)
 {
     List = list;
     Map  = map;
 }
Ejemplo n.º 3
0
 public static void Save(
     string path,
     WordList wordList)
 {
     Save(path, wordList.Values, wordList.Comparer);
 }