本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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);
}
示例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)));
}
示例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)
//.........这里部分代码省略.........