当前位置: 首页>>代码示例>>C#>>正文


C# BitSet.Contains方法代码示例

本文整理汇总了C#中BitSet.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# BitSet.Contains方法的具体用法?C# BitSet.Contains怎么用?C# BitSet.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BitSet的用法示例。


在下文中一共展示了BitSet.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connected

        // Uses depth-first search to check if the graph induced by the subgraph given as a parameter is connected
        // In other words, we retreive all edges from the original graph and check the subgraph for connectedness
        public static bool Connected(Datastructures.Graph graph, BitSet subgraph)
        {
            // Vertices that are visited
            Set<int> visited = new Set<int>();

            // Stack of vertices yet to visit
            Stack<int> stack = new Stack<int>();

            // Initial vertex
            int s = subgraph.First();
            stack.Push(s);

            // Continue while there are vertices on the stack
            while (stack.Count > 0)
            {
                int v = stack.Pop();

                // If we have not encountered this vertex before, then we check for all neighbors if they are part of the subgraph
                // If a neighbor is part of the subgraph it means that we have to push it on the stack to explore it at a later stage
                if (!visited.Contains(v))
                {
                    visited.Add(v);

                    foreach (int w in graph.OpenNeighborhood(v))
                        if (subgraph.Contains(w))
                            stack.Push(w);
                }
            }

            // If we visited an equal number of vertices as there are vertices in the subgraph then the subgraph is connected
            return visited.Count == subgraph.Count;
        }
开发者ID:Miloan,项目名称:BooleanWidth,代码行数:34,代码来源:DepthFirstSearch.cs

示例2: ConnectedComponents

        // Returns all connected components in a certain subgraph, where we define a subgraph by the vertices that are contained in it
        // We apply multiple dfs searches to find all connected parts of the graph
        public static List<BitSet> ConnectedComponents(Datastructures.Graph graph, BitSet subgraph)
        {
            // Each connected component is defined as a bitset, thus the result is a list of these bitsets
            List<BitSet> result = new List<BitSet>();

            // Working stack for the dfs algorithm
            Stack<int> stack = new Stack<int>();

            // Each vertex of the subgraph will either be explored, or it will be the starting point of a new dfs search
            BitSet todo = subgraph;

            while (!todo.IsEmpty)
            {
                int s = todo.First();
                stack.Push(s);

                // Start tracking the new component
                BitSet component = new BitSet(0, graph.Size);

                // Default dfs exploring part of the graph
                while (stack.Count > 0)
                {
                    int v = stack.Pop();

                    // If we have not encountered this vertex before (meaning it isn't in this component), then we check for all neighbors if they are part of the subgraph
                    // If a neighbor is part of the subgraph it means that we have to push it on the stack to explore it at a later stage for this component
                    if (!component.Contains(v))
                    {
                        component += v;

                        // Remove this vertex from the 'todo' list, since it can never be the starting point of a new component
                        todo -= v;

                        foreach (int w in graph.OpenNeighborhood(v))
                            if (subgraph.Contains(w))
                                stack.Push(w);
                    }
                }
                // The whole connected component has been found, so we can add it to the list of results
                result.Add(component);
            }
            return result;
        }
开发者ID:Miloan,项目名称:BooleanWidth,代码行数:45,代码来源:DepthFirstSearch.cs

示例3: FindFirstTypeOutsideRewrite

        protected virtual GrammarAST FindFirstTypeOutsideRewrite(GrammarAST block, BitSet types)
        {
            List<GrammarAST> worklist = new List<GrammarAST>();
            worklist.Add(block);
            while (worklist.Count > 0)
            {
                GrammarAST current = worklist[worklist.Count - 1];
                worklist.RemoveAt(worklist.Count - 1);
                if (current.Type == ANTLRParser.REWRITE)
                    continue;

                if (current.Type >= 0 && types.Contains(current.Type))
                    return current;

                worklist.AddRange(current.GetChildrenAsArray());
            }

            return null;
        }
开发者ID:jamilgeor,项目名称:antlrcs,代码行数:19,代码来源:Grammar.cs


注:本文中的BitSet.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。