Пример #1
0
        // creates all combinations of symbols up to length given by lookaheadWidth
        // example: A, B, C, up to 2
        // will give: (empty), A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC
        public static SymbolChunkSet <SYMBOL_ENUM> MultiplyUpTo <SYMBOL_ENUM>(IEnumerable <SYMBOL_ENUM> symbols,
                                                                              int lookaheadWidth)
            where SYMBOL_ENUM : struct
        {
            var seed = SymbolChunkSet.Create(symbols.Select(it => SymbolChunk.Create(it)));

            var working = new SymbolChunkSet <SYMBOL_ENUM>();
            var result  = new SymbolChunkSet <SYMBOL_ENUM>();

            result.Add(SymbolChunk.Create <SYMBOL_ENUM>()); // empty entry

            foreach (var _ in Enumerable.Repeat(0, lookaheadWidth))
            {
                working = MultiConcat(new[] { working, seed }, lookaheadWidth);
                result.Add(working);
            }

            return(result);
        }
Пример #2
0
 public static IEnumerable <SymbolChunk <SYMBOL_ENUM> > MultiConcat <SYMBOL_ENUM>(SymbolChunk <SYMBOL_ENUM> chunk,
                                                                                  SymbolChunkSet <SYMBOL_ENUM> tailSet,
                                                                                  int limitLength)
     where SYMBOL_ENUM : struct
 {
     if (chunk.Count >= limitLength)
     {
         yield return(chunk.GetFirst(limitLength));
     }
     else
     {
         foreach (SymbolChunk <SYMBOL_ENUM> tail_chunk in tailSet.Chunks)
         {
             yield return(chunk.Concat(tail_chunk, limitLength));
         }
     }
 }