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


C# Queue.GetEnumerator方法代码示例

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


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

示例1: GetElements

        ///////////////////////////////////////////////////////////////////////////
        // IDataStore implementation
        public void GetElements(String aContainerID, out IEnumerator aElements)
        {
            XmlElement container = GetElementById(aContainerID);
              if (container == null)
            container = mBookmarksDocument.DocumentElement.FirstChild as XmlElement;
              int itemCount = container.ChildNodes.Count;
              Queue items = new Queue();
              for (int i = 0; i < itemCount; ++i)
              {
            XmlElement currElt = container.ChildNodes[i] as XmlElement;
            // If the bookmark does not have an ID, generate one and set it.
            if (!currElt.HasAttribute("id") || currElt.GetAttribute("id") == "")
              currElt.SetAttribute("id", Bookmarks.GenerateID());

            CommandTarget target = new CommandTarget();
            target.Label = currElt.GetAttribute("label");
            target.AccessKey = currElt.GetAttribute("accesskey");
            target.Data = currElt.GetAttribute("id");
            target.IsContainer = currElt.HasChildNodes;
            target.IconURL = currElt.GetAttribute("icon");
            target.IsOpen = currElt.GetAttribute("open") == "true";

            items.Enqueue(target);
              }
              aElements = items.GetEnumerator();
        }
开发者ID:nfan,项目名称:Jaxer,代码行数:28,代码来源:bookmarks.cs

示例2: MatchIdenticalSubtrees

    // Finds identical subtrees in both trees and skrinks them into XmlDiffShrankNode instances
    private void MatchIdenticalSubtrees()
    {
        Hashtable sourceUnmatchedNodes = new Hashtable( 16 );
        Hashtable targetUnmatchedNodes = new Hashtable( 16 );

        Queue sourceNodesToExpand = new Queue( 16 );
        Queue targetNodesToExpand = new Queue( 16 );

        sourceNodesToExpand.Enqueue( _sourceDoc );
        targetNodesToExpand.Enqueue( _targetDoc );

        AddNodeToHashTable( sourceUnmatchedNodes, _sourceDoc );
        AddNodeToHashTable( targetUnmatchedNodes, _targetDoc );

        while ( sourceNodesToExpand.Count > 0  ||
                targetNodesToExpand.Count > 0 )
        {
            // Expand next level of source nodes and add them to the sourceUnmatchedNodes hashtable.
            // Leave the parents of expanded nodes in the sourceNodesToExpand queue for later use.
            {
                IEnumerator en = sourceNodesToExpand.GetEnumerator();
                while ( en.MoveNext() )
                {
                    XmlDiffParentNode sourceParentNode = (XmlDiffParentNode) en.Current;
                    Debug.Assert( !sourceParentNode._bExpanded );

                    sourceParentNode._bExpanded = true;
                    
                    if ( !sourceParentNode.HasChildNodes )
                        continue;

                    XmlDiffNode curSourceNode = sourceParentNode._firstChildNode;
                    while ( curSourceNode != null )
                    {
                        AddNodeToHashTable( sourceUnmatchedNodes, curSourceNode );
                        curSourceNode = curSourceNode._nextSibling;
                    }
                }
            }

            // Expand next level of target nodes and try to match them against the sourceUnmatchedNodes hashtable.
            // to find matching node. 
            int count = targetNodesToExpand.Count;
            for ( int i = 0; i < count; i++ )
            {
                XmlDiffParentNode targetParentNode = (XmlDiffParentNode) targetNodesToExpand.Dequeue();
                Debug.Assert( !targetParentNode._bExpanded );

                if ( !NodeInHashTable( targetUnmatchedNodes, targetParentNode ) ) {
                    continue;
                }

                targetParentNode._bExpanded = true;
                
                if ( !targetParentNode.HasChildNodes )
                    continue;

                XmlDiffNode curTargetNode = targetParentNode._firstChildNode;
                while ( curTargetNode != null )
                {
                    Debug.Assert( !( curTargetNode is XmlDiffAttributeOrNamespace ) );

                    // try to match
                    XmlDiffNode firstSourceNode = null;
                    XmlDiffNodeListHead matchingSourceNodes = (XmlDiffNodeListHead) sourceUnmatchedNodes[ curTargetNode.HashValue ];

                    if ( matchingSourceNodes != null  ) {
                        // find matching node and remove it from the hashtable
                        firstSourceNode = HTFindAndRemoveMatchingNode( sourceUnmatchedNodes, matchingSourceNodes, curTargetNode );
                    }
                    
                    // no match
                    if ( firstSourceNode == null || 
                         // do not shrink xml declarations and DTD
                         (int)curTargetNode.NodeType < 0 )
                    {
                        if ( curTargetNode.HasChildNodes )
                            targetNodesToExpand.Enqueue( curTargetNode );
                        else
                            curTargetNode._bExpanded = true;

                        AddNodeToHashTable( targetUnmatchedNodes, curTargetNode );
                        curTargetNode = curTargetNode._nextSibling;
                        continue;
                    }

                    HTRemoveAncestors( sourceUnmatchedNodes, firstSourceNode );
                    HTRemoveDescendants( sourceUnmatchedNodes, firstSourceNode );

                    HTRemoveAncestors( targetUnmatchedNodes, curTargetNode );
                    // there are no target node descendants in the hash table

                    // find matching interval - starts at startSourceNode and startTargetNode
                    XmlDiffNode firstTargetNode = curTargetNode;
                    XmlDiffNode lastSourceNode = firstSourceNode;
                    XmlDiffNode lastTargetNode = firstTargetNode;

                    curTargetNode = curTargetNode._nextSibling;
                    XmlDiffNode curSourceNode = firstSourceNode._nextSibling;
//.........这里部分代码省略.........
开发者ID:Podracer,项目名称:DAE-notepad,代码行数:101,代码来源:XmlDiff.cs


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