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


C# Stack.Where方法代码示例

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


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

示例1: _SearchBranchForFilters

        private void _SearchBranchForFilters(ElementNode node, IEnumerable<ISequenceFilterNode> filters,
            Stack<IEnumerable<ISequenceFilterNode>> filtersFound, SequenceFilterLookup lookup)
        {
            // Must push a single value for each level we enter.
            ISequenceFilterNode[] sequenceFilterNodes = _GetFiltersForNode(node, filters);
            if (sequenceFilterNodes.Length > 0) {
                filtersFound.Push(sequenceFilterNodes);
            }
            else {
                filtersFound.Push(null);
            }

            if (node.IsLeaf) {
                ISequenceFilterNode[] elementFilters = filtersFound.Where(x => x != null).Reverse().SelectMany(x => x).ToArray();
                if (elementFilters.Length > 0) {
                    lookup.AddElementFilters(node.Element, elementFilters);
                }
            }
            else {
                foreach (ElementNode childNode in node.Children) {
                    _SearchBranchForFilters(childNode, filters, filtersFound, lookup);
                }
            }

            // Pop a single value for every level we exit.
            filtersFound.Pop();
        }
开发者ID:stewmc,项目名称:vixen,代码行数:27,代码来源:SequenceFilterService.cs

示例2: TopologicalSort

        /// <summary>
        ///     Sort nodes in topological order.
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        public static IEnumerable<NodeModel> TopologicalSort(IEnumerable<NodeModel> nodes)
        {
            var sortedNodes = new Stack<NodeModel>();
            IList<NodeModel> nodeModels = nodes as IList<NodeModel> ?? nodes.ToList();

            Dictionary<NodeModel, MarkFlag> nodeFlags = nodeModels.ToDictionary(node => node, _ => MarkFlag.NoMark);

            foreach (NodeModel candidate in SortCandidates(nodeFlags))
                MarkNode(candidate, nodeFlags, sortedNodes);

            return sortedNodes.Where(nodeModels.Contains);
        }
开发者ID:heegwon,项目名称:Dynamo,代码行数:17,代码来源:AstBuilder.cs

示例3: ComputeScc

        public int[] ComputeScc(string filePath)
        {
            Dictionary<string, DfsItem> graph = new Dictionary<string, DfsItem>();
            Dictionary<string, DfsItem> graphRev = new Dictionary<string, DfsItem>();
            string[] values;
            DfsItem dfsItem;
            Stack<int> sccSize = new Stack<int>();

            using (StreamReader sr = new StreamReader(filePath))
            {
                while (sr.Peek() >= 0)
                {
                    values = sr.ReadLine().Split(' ');
                    if (graph.TryGetValue(values[0], out dfsItem))
                        dfsItem.AddEdge(values[1]);
                    else
                        graph.Add(values[0], new DfsItem(values[0], values[1]));

                    if (graphRev.TryGetValue(values[1], out dfsItem))
                        dfsItem.AddEdge(values[0]);
                    else
                        graphRev.Add(values[1],new DfsItem(values[1], values[0]));
                }
            }

            DfsLoop(graph, graphRev, sccSize);
            int[] a = sccSize.Where(x => x > 0).OrderByDescending(x => x).Take(5).ToArray();

            Array.Resize<int>(ref a, 5);

            //backtesting
            //sccSize = new Stack<int>();
            //DfsLoop(graphRev, graph, sccSize);
            //int[] b = sccSize.Where(x => x > 0).OrderByDescending(x => x).Take(5).ToArray();
            //Array.Resize<int>(ref b, 5);

            return a;
        }
开发者ID:djamelz,项目名称:Coursera-DesignAndAnalysisOfAlgorithms,代码行数:38,代码来源:Main.cs

示例4: TopologicalSort

        /// <summary>
        ///     Sort nodes in topological order.
        /// </summary>
        /// <param name="nodes"></param>
        /// <returns></returns>
        internal static IEnumerable<NodeModel> TopologicalSort(IEnumerable<NodeModel> nodes)
        {
            if (nodes == null)
                throw new ArgumentNullException("nodes");

            var sortedNodes = new Stack<NodeModel>();
            IList<NodeModel> nodeModels = nodes as IList<NodeModel> ?? nodes.ToList();

            Dictionary<NodeModel, MarkFlag> nodeFlags = nodeModels.ToDictionary(node => node, _ => MarkFlag.NoMark);

            foreach (NodeModel candidate in GetUnvisitedNodes(nodeFlags))
                MarkNode(candidate, nodeFlags, sortedNodes);

            return sortedNodes.Where(nodeModels.Contains);
        }
开发者ID:sh4nnongoh,项目名称:Dynamo,代码行数:20,代码来源:AstBuilder.cs

示例5: getCurrentAccesses

 /// <summary>
 /// Find all accesses available to all assets at the current time
 /// </summary>
 /// <param name="accesses"></param>
 /// <param name="currentTime"></param>
 /// <returns></returns>
 public static Stack<Access> getCurrentAccesses(Stack<Access> accesses, double currentTime)
 {
       return new Stack<Access>(accesses.Where(item => (item.AccessStart <= currentTime && item.AccessEnd >= currentTime)));
 }
开发者ID:emehiel,项目名称:Horizon,代码行数:10,代码来源:Access.cs

示例6: TextMatches

        public virtual IEnumerable<IMatch> TextMatches(string text)
        {
            var tags = GetTags(text);

            // return to speed-up
            if (tags.Count == 0)
            {
                return new List<IMatch>();
            }

            var sortedList = new SortedList<int, ITagMatch>();
            
            foreach (var tag in tags)
            {
                sortedList.Add(tag.Index, tag);
            }

            sortedList = DeleteOverlapping(sortedList);

            var matchedPairs = new List<Tuple<ITagMatch, ITagMatch>>();
            var startsStack = new Stack<ITagMatch>();

            foreach (var tag in sortedList.Select(pair => pair.Value))
            {
                if (tag is IStartOrEndTagMatch)
                {
                    var startOrEndTag = tag as IStartOrEndTagMatch;

                    if (startOrEndTag.IsStart)
                    {
                        var start = startOrEndTag as IStartTagMatch;
                        if (start.HasEnding)
                        {
                            startsStack.Push(start);
                        }
                        else if (startsStack.Count == 0)
                        {
                            matchedPairs.Add(new Tuple<ITagMatch, ITagMatch>(start, start));
                        }
                    }
                    else
                    {
                        if (startsStack.Count > 0)
                        {
                            ITagMatch start;
                            var end = startOrEndTag as IEndTagMatch;

                            if (ignoreNoClosingError)
                            {
                                start = NonstrickStartTagSearch(startsStack, end, text);

                                if(start == null)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                start = startsStack.Pop();

                                if (!VerifyMatch(text, start, end))
                                {
                                    throw CreateParsingErrorExceptionAtPosition(Language.Message("TagMismatch", GetErrorString(start), GetErrorString(end)), start.Index);
                                }
                            }

                            matchedPairs.Add(new Tuple<ITagMatch, ITagMatch>(start, end));
                        }
                        else if (!ignoreNoClosingError)
                        {
                            throw CreateParsingErrorExceptionAtPosition(Language.Message("RedundantEndingTag", GetErrorString(tag)), tag.Index);
                        }
                    }
                }
                else
                {
                    startsStack.Push(tag);
                }
            }

            // non-StartOrEnd tags parsing e.g. **bold**
            var nonStartEndStartsStack = new Stack<ITagMatch>();
            var potentialEnds = startsStack.Where(e => !(e is IStartOrEndTagMatch)).ToList();
            potentialEnds.Reverse();

            foreach (var potentialEnd in potentialEnds)
            {
                var start = NonstrickStartTagSearch(nonStartEndStartsStack, potentialEnd, text);

                if (start != null && nonStartEndStartsStack.Count == 0)
                {
                    matchedPairs.Add(new Tuple<ITagMatch, ITagMatch>(start, potentialEnd));
                }
                else
                {
                    nonStartEndStartsStack.Push(potentialEnd);
                }
            }

            if (!ignoreNoClosingError && startsStack.Count > 0)
//.........这里部分代码省略.........
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:101,代码来源:EMTaggedElementsParser.cs


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