Пример #1
0
            private void addToken(int tokenLen, TokenType type)
            {
                if (type == TokenType.Comment)
                {
                    return;
                }
                //Console.WriteLine("idx[" + currentIdx_ + "]  ch[" + "] tok len[" + tokenLen + "]" );
                var token = CodeToken.Build(type, SourceCode.Substring(currentIdx_ - tokenLen + 1, tokenLen));

                token.LineNumber   = lineCount_;
                token.ColumeNumber = tokenLeft_ - currentLineIdx_;

                TokenList.Add(token);

                if (TokenMatrix.Count == 0 || TokenMatrix.ElementAt(TokenMatrix.Count - 1).LineNum != lineCount_)
                {
                    var lastLine = new CodeLine(lineCount_);
                    lastLine.Add(token);
                    TokenMatrix.Add(lastLine);
                    // Console.WriteLine("NEW " + lastLine.ToString());
                }
                else
                {
                    TokenMatrix.ElementAt(TokenMatrix.Count - 1).Add(token);
                    // Console.WriteLine(tokenFile_.ElementAt(tokenFile_.Count - 1).ToString());
                }
                this.TokenCount++;
            }
Пример #2
0
        public static void Main(string[] args)
        {
            var degree    = new TokenMatrix(6);
            var adjacency = new SparseMatrix(6);

            degree [0, 0, "A"] = 2.0d;
            degree [1, 1, "B"] = 3.0d;
            degree [2, 2, "C"] = 2.0d;
            degree [3, 3, "D"] = 3.0d;
            degree [4, 4, "E"] = 3.0d;
            degree [5, 5, "F"] = 1.0d;

            adjacency [0, 1] = 1.0d;
            adjacency [0, 4] = 1.0d;

            adjacency [1, 0] = 1.0d;
            adjacency [1, 2] = 1.0d;
            adjacency [1, 4] = 1.0d;

            adjacency [2, 1] = 1.0d;
            adjacency [2, 3] = 1.0d;

            adjacency [3, 2] = 1.0d;
            adjacency [3, 4] = 1.0d;
            adjacency [3, 5] = 1.0d;

            adjacency [4, 0] = 1.0d;
            adjacency [4, 1] = 1.0d;
            adjacency [4, 3] = 1.0d;

            adjacency [5, 3] = 1.0d;


            var componentFinder = new SimpleComponentFinder(degree, adjacency, degree.Map, 3);

            var L = new LaplacianMatrix(6);

            L ["A"] = "B";
            L ["A"] = "E";

            L ["B"] = "A";
            L ["B"] = "C";
            L ["B"] = "E";

            L ["C"] = "B";
            L ["C"] = "D";

            L ["D"] = "C";
            L ["D"] = "E";
            L ["D"] = "F";

            L ["E"] = "A";
            L ["E"] = "B";
            L ["E"] = "D";

            L ["F"] = "E";

            var streamlined = new SimpleComponentFinder(L, 3);

            streamlined.CalculateComponents();

            foreach (var component in streamlined.Components)
            {
                Console.WriteLine("-------Component---------");
                Console.WriteLine("Contained Nodes: " + string.Join(", ", component.Nodes));
                Console.WriteLine();
            }
        }