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


C# Set.GetEnumerator方法代码示例

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


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

示例1: ShouldThrowIfSameThreadModifiesCollectionWhileEnumerating

        public void ShouldThrowIfSameThreadModifiesCollectionWhileEnumerating()
        {
            var collection = new Set<string>();
            collection.Add("1");
            collection.Add("2");
            var enumerator = collection.GetEnumerator();
            enumerator.MoveNext();
            collection.Add("3");
            Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext());

            enumerator.Dispose();
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:12,代码来源:SetTests.cs

示例2: checkIsDAGAndCollectVariablesInTopologicalOrder

        // END-BayesianNetwork
        //

        //
        // PRIVATE METHODS
        //
        private void checkIsDAGAndCollectVariablesInTopologicalOrder()
        {

            // Topological sort based on logic described at:
            // http://en.wikipedia.org/wiki/Topoligical_sorting
            Set<Node> seenAlready = new Set<Node>();
            Map<Node, List<Node>> incomingEdges = new Map<Node, List<Node>>();
            Set<Node> s = new Set<Node>();
            foreach (Node n in this.rootNodes)
            {
                walkNode(n, seenAlready, incomingEdges, s);
            }
            while (!(s.Count == 0))
            {
                HashSet<Node>.Enumerator enumerator = s.GetEnumerator();
                enumerator.MoveNext();
                Node n = enumerator.Current;
                s.remove(n);
                variables.Add(n.getRandomVariable());
                varToNodeMap.put(n.getRandomVariable(), n);
                foreach (Node m in n.getChildren())
                {
                    List<Node> edges = incomingEdges.get(m);
                    edges.Remove(n);
                    if (edges.Count == 0)
                    {
                        s.add(m);
                    }
                }
            }

            foreach (List<Node> edges in incomingEdges.values())
            {
                if (!(edges.Count == 0))
                {
                    throw new IllegalArgumentException(
                        "Network contains at least one cycle in it, must be a DAG.");
                }
            }
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:46,代码来源:BayesNet.cs

示例3: ComputeIsomorphism

            internal Map<Node, Node> ComputeIsomorphism()
            {
                // We start with a functional pass.
                ControlState c = ControlState.InitialFunctionalPass;
                while (true)
                {

                    switch (c)
                    {
                        # region Find all reachable functional matches of current active nodes x and y.
                        case ControlState.InitialFunctionalPass:
                            c = ExtendForOnlyFunctionalEdges(x, y);

                            break;
                        # endregion

                        #region Find all relational matches after one or more functional pass.
                        case ControlState.RelationalPass:
                            if (xPartitions.Count > 0)
                                goto case ControlState.NextPartition;
                            if (relationalPassIndex >= index)
                            {
                                if (relationalPassIndex == numberOfNodes)
                                    c = ControlState.Done;
                                else
                                    goto case ControlState.Fail; // c = ControlState.Fail;
                                break;

                            }
                            x = bijection[relationalPassIndex,X];
                            y = bijection[relationalPassIndex,Y];
                            xData = g1.vertexRecords[x];
                            yData = g2.vertexRecords[y];
                            if (relationalEdgeEnumerator == default(IEnumerator<CompoundTerm>))
                            {

                                relationalEdgeLabels = Set<CompoundTerm>.EmptySet;
                                foreach (Pair<CompoundTerm, Set<Node>> pair in xData.unorderedOutgoingEdges) {
                                    relationalEdgeLabels = relationalEdgeLabels.Add(pair.First);
                                }
                                relationalEdgeEnumerator = relationalEdgeLabels.GetEnumerator();
                            }
                            if (relationalEdgeEnumerator.MoveNext())
                            {
                                xEdgeLabel = relationalEdgeEnumerator.Current;
                                //xtoNodes = xData.unorderedOutgoingEdges[xEdgeLabel];
                                if (yData.unorderedOutgoingEdges.ContainsKey(xEdgeLabel)) // Perhaps this check can be assumed true for all graphs?
                                {
                                    //ytoNodes = yData.unorderedOutgoingEdges[xEdgeLabel];
                                    xPartitions = GetPartitions(g1, x, xEdgeLabel);
                                    yPartitions = GetPartitions(g2, y, xEdgeLabel);

                                    //Console.WriteLine("Partitions: " + x + " has " + xPartitions.Count + "elements.");
                                    if (PartitionsAreConsistent(xPartitions,yPartitions))
                                        goto case ControlState.NextPartition;
                                    else
                                        goto case ControlState.Fail;
                                    ////c = ControlState.NextRelationalEdge;
                                    //goto case ControlState.NextRelationalEdge;
                                }
                                else
                                    goto case ControlState.Fail; // c = ControlState.Fail;

                            }
                            else
                            {
                                relationalPassIndex++;
                                relationalEdgeEnumerator = default(IEnumerator<CompoundTerm>);
                                relationalEdgeLabels = default(Set<CompoundTerm>);
                                if (relationalPassIndex == numberOfNodes)
                                    c = ControlState.Done;
                            }
                            break;

                        case ControlState.NextPartition:
                            if (xPartitions.Count > 0) // the other constraints have been implied by PartitionsAreConsistent
                            {
                                Pair<IComparable, bool> label = xPartitions.Keys.Choose(0);
                                xtoNodes = xPartitions[label];
                                xPartitions = xPartitions.RemoveKey(label);
                                ytoNodes = yPartitions[label];
                                yPartitions = yPartitions.RemoveKey(label);
                                goto case ControlState.ProcessPartition;
                            }
                            else
                                c = ControlState.RelationalPass;
                            break;
                        // It is possible that we have multiple sets of relational edges from a node. The following is done for each set.
                        case ControlState.ProcessPartition:

                                // xEdgeLabel has been set
                                // xtoNodes has been set;
                                // ytoNodes has been set;
                                Node x1, y1;
                                // remove all nodes that have already been matched. (previously implemented as PruneCandidates)
                                Set<Node> xtoNodesTmp = xtoNodes;
                                int count = xtoNodesTmp.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    x1 = xtoNodesTmp.Choose(i);
//.........这里部分代码省略.........
开发者ID:juhan,项目名称:NModel,代码行数:101,代码来源:GraphIsomorphism.cs

示例4: ShouldLockThreadsFromEditingCollectionWhenEnumerating

        public void ShouldLockThreadsFromEditingCollectionWhenEnumerating()
        {
            var collection = new Set<string>();
            collection.Add("1");
            collection.Add("2");
            var enumerator = collection.GetEnumerator();
            Assert.IsTrue(enumerator.MoveNext());
            
            ThreadPool.QueueUserWorkItem(
                delegate
                {
                    collection.Add("3");
                });

            Assert.IsTrue(enumerator.MoveNext());
            Thread.Sleep(100); // Give the thread about enough time to become locked
            Assert.IsFalse(enumerator.MoveNext());
            Assert.AreEqual(2, collection.Count);

            enumerator.Dispose();
            Thread.Sleep(100); // Give the thread about enough time to become unlocked
            Assert.AreEqual(3, collection.Count);
        }
开发者ID:p69,项目名称:magellan-framework,代码行数:23,代码来源:SetTests.cs


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