本文整理汇总了C#中ISet.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# ISet.SelectMany方法的具体用法?C# ISet.SelectMany怎么用?C# ISet.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISet
的用法示例。
在下文中一共展示了ISet.SelectMany方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveResourceDependencies
/// <summary>
/// Given a set of processes which are not interdependent, split up into multiple sets which do not use the same resource concurrently
/// </summary>
/// <param name="processes">The processes.</param>
/// <returns></returns>
private IEnumerable<ISet<OrderedProcess>> SolveResourceDependencies(ISet<OrderedProcess> processes)
{
// if there are no resources in this graph, or none of the processes in this set have any
// resources, we can simply return the set of processes
if (_resources.Count == 0 || !processes.SelectMany(p => p.ResourcesSet).Any())
yield return processes;
else
{
HashSet<HashSet<OrderedProcess>> result = new HashSet<HashSet<OrderedProcess>>();
foreach (var process in processes)
{
var process1 = process;
//all sets this process may be added to
IEnumerable<HashSet<OrderedProcess>> agreeableSets = result //from the set of result sets
.Where(set => set //select a candidate set to add to
.Where(p => p.ResourcesSet.Overlaps(process1.Resources)) //select processes whose resource usage overlaps this one
.IsEmpty()); //if there are none which overlap, then this is a valid set
//the single best set to add to
HashSet<OrderedProcess> agreeableSet;
if (agreeableSets.IsEmpty())
{
//no sets can hold this process, create a new one
agreeableSet = new HashSet<OrderedProcess>();
result.Add(agreeableSet);
}
else
agreeableSet = agreeableSets.Aggregate((a, b) => a.Count < b.Count ? a : b); //pick the smallest set
//finally, add this process to the selected set
agreeableSet.Add(process);
}
foreach (var set in result)
yield return set;
}
}