本文整理汇总了C#中Queue.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Any方法的具体用法?C# Queue.Any怎么用?C# Queue.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.Any方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandLineParser
public CommandLineParser(params string[] args)
{
var queue = new Queue<string>(args);
Options = new Dictionary<string, string>();
var errors = new List<string>();
while (queue.Any())
{
var item = queue.Dequeue();
if (!queue.Any() || IsKey(queue.Peek()))
{
errors.Add(string.Format("Option {0} is missing its required value.", item));
break;
}
var key = KeyName(item);
var value = queue.Dequeue();
Options.Add(key, value);
}
Errors = errors.ToArray();
}
示例2: MadeRows
private static void MadeRows(string[] words)
{
Queue<string> queue = new Queue<string>();
for (int i = 0; i < words.Length; i++)
{
queue.Enqueue(words[i]);
}
int currentRowLength = 0;
int wordsCount = 0;
string currentWord = String.Empty;
List<string> current = new List<string>();
int counter = 0;
while (true)
{
if (!queue.Any())
{
break;
}
currentWord = queue.Peek();
currentRowLength += currentWord.Length + 1;
wordsCount++;
if (currentRowLength <= lineWidth + 1)
{
current.Add(queue.Dequeue());
counter++;
}
if (currentRowLength > lineWidth + 1 || !queue.Any())
{
int spaces = lineWidth - String.Join("", current).Trim().Length;
int i = 0;
while (spaces > 0)
{
if (current.Count > 1)
{
if (i == current.Count - 1)
{
i = 0;
}
if (i < current.Count - 1)
{
current[i] = current[i] + " ";
spaces--;
}
i++;
}
else
{
break;
}
}
Console.WriteLine(String.Join("", current).Trim());
current.Clear();
currentRowLength = 0;
}
}
}
示例3: GetEventsWhile
private static IEnumerable<GherkinEvent> GetEventsWhile(Queue<GherkinEvent> events, Predicate<GherkinEvent> continueIfEventIsNot)
{
if (events.Any() == false)
yield break;
GherkinEvent nextEvent;
do
{
yield return events.Dequeue();
nextEvent = (events.Any()) ? events.Peek() : null;
} while (events.Any() && !(continueIfEventIsNot(nextEvent)));
}
示例4: AsyncExecute
public async Task AsyncExecute(Item[] items, int runnerCount) {
var queue = new Queue<Item>(items);
var tasks = new List<Task<Item>>();
while (tasks.Any() || queue.Any()) {
while (tasks.Count() != runnerCount && queue.Any())
tasks.Add(CompressUsingZipFile(queue.Dequeue()));
var task = await Task.WhenAny(tasks);
tasks.Remove(task);
await task;
}
}
示例5: GeraGrade
private Matricula GeraGrade()
{
var grade = new Matricula(_restricoes);
var fila = new Queue<Disciplina>();
var continua = true;
foreach (var disciplina in ranking.Keys.ToList())
{
fila.Enqueue(disciplina);
}
do
{
if (fila.Any())
{
grade.AdicionarDisciplina(fila.Dequeue());
}
else
{
continua = false;
}
} while (continua);
return grade;
}
示例6: GetSupportedChildProjects
/// <summary>
/// Recursively retrieves all supported child projects of a virtual folder.
/// </summary>
/// <param name="project">The root container project</param>
public static IEnumerable<Project> GetSupportedChildProjects(this Project project)
{
if (!project.IsSolutionFolder())
{
yield return project;
}
var containerProjects = new Queue<Project>();
containerProjects.Enqueue(project);
while (containerProjects.Any())
{
var containerProject = containerProjects.Dequeue();
foreach (ProjectItem item in containerProject.ProjectItems)
{
var nestedProject = item.SubProject;
if (nestedProject == null)
{
continue;
}
else if (nestedProject.IsSupported())
{
yield return nestedProject;
}
else if (nestedProject.IsSolutionFolder())
{
containerProjects.Enqueue(nestedProject);
}
}
}
}
示例7: EnumerateTargets
public IEnumerable<Tuple<Vector, Stack<RobotMove>>> EnumerateTargets(Func<Map, Vector, HashSet<Vector>, int, bool> isTarget)
{
var q = new Queue<WaveCell>();
q.Enqueue(new WaveCell(startPosition, 0, null, RobotMove.Wait, map.WaterproofLeft, map.Razors));
var used = new HashSet<Vector>();
used.Add(startPosition);
int stepsDone = 0;
while (q.Any() && stepsDone < maxStepsCount)
{
stepsDone++;
var cell = q.Dequeue();
MapCell toCell = map.GetCell(cell.Pos);
if (!cell.Pos.Equals(startPosition)
&& (isTarget(map, cell.Pos, used, cell.StepNumber)))
yield return CreateTarget(cell);
if (toCell == MapCell.OpenedLift || toCell == MapCell.ClosedLift)
Lift = CreateTarget(cell);
foreach (var move in map.IsInWater(cell.StepNumber, cell.Pos.Y) ? RobotMovesInWater : RobotMoves)
{
Vector newPos = cell.Pos.Add(move.ToVector());
if (!map.IsValidMoveWithoutMovingRocks(cell.Pos, newPos)) continue;
newPos = map.GetTrampolineTarget(newPos);
var mapcell = map.GetCell(newPos);
if ((!used.Contains(newPos) && (map.GetCell(newPos) == MapCell.OpenedLift || map.IsSafeMove(cell.Pos, newPos, cell.StepNumber + 1, cell.WaterproofLeft)))
&& (mapcell != MapCell.Beard || cell.RazorsLeft > 0))
{
var wp = map.IsInWater(cell.StepNumber, newPos.Y) ? cell.WaterproofLeft - 1 : map.Waterproof;
q.Enqueue(new WaveCell(newPos, cell.StepNumber + 1, cell, move, wp, mapcell == MapCell.Beard ? map.Razors - 1: map.Razors));
used.Add(newPos);
}
}
}
}
示例8: V
public static string V(ICode c) {
var method = c.Ctx.MRef;
StringBuilder sb = new StringBuilder();
sb.Append(method.FullName);
var seen = new HashSet<ICode>() { c };
var todo = new Queue<Stmt>();
todo.Enqueue((Stmt)c);
while (todo.Any()) {
var cBlock = todo.Dequeue();
var v = new ShowVisitor();
v.Visit(cBlock);
sb.AppendLine();
sb.Append(GetStmtName(cBlock) + ":");
sb.Append(v.Code);
foreach (var continuation in v.Continuations) {
if (seen.Add(continuation.To)) {
todo.Enqueue(continuation.To);
}
}
}
sb.AppendLine();
sb.Append("}");
return sb.ToString();
}
示例9: AllPositions
public IList<Tuple<Unit, IList<MoveType>>> AllPositions(Unit currentUnit)
{
if (!currentUnit.IsCorrect(map))
{
return new Tuple<Unit, IList<MoveType>>[0];
}
var checker = new ForbiddenSequenceChecker(currentUnit);
var visited = new Dictionary<Unit, List<MoveType>>
{
{ currentUnit, new List<MoveType>() },
};
var queue = new Queue<Unit>(new[] { currentUnit });
while (queue.Any())
{
var unit = queue.Dequeue();
foreach (var move in allowedMoves.Where(m => checker.CheckLastMove(visited[unit], m)))
{
var next = unit.Move(move);
if (!next.IsCorrect(map) || visited.ContainsKey(next))
continue;
queue.Enqueue(next);
visited[next] = visited[unit].Concat(new[] { move }).ToList();
}
}
return visited.Keys.Select(u => Tuple.Create(u, (IList<MoveType>)visited[u])).ToList();
}
示例10: ForNodes
public static void ForNodes(this Dictionary<IToken, List<INode>> nodeDependencies, TreeContext context, Action<INode> action)
{
var nodesQueue = new Queue<INode>(new[] { context.Tree.Root });
var assigned = new HashSet<IToken> { context.Tree.Root.Token };
while (nodesQueue.Any())
{
var current = nodesQueue.Dequeue();
List<INode> children;
if (!nodeDependencies.TryGetValue(current.Token, out children))
{
continue;
}
foreach (var child in children)
{
var dependencies = context.GetDependencies(child);
if (!dependencies.All(x => assigned.Contains(x.Token)))
{
continue;
}
action(child);
assigned.Add(child.Token);
nodesQueue.Enqueue(child);
}
}
}
示例11: ConstructHypergraph
//
// On-Demand hypergraph construction.
//
public Hypergraph.Hypergraph<Region, SimpleRegionEquation> ConstructHypergraph()
{
Queue<Region> worklist = new Queue<Region>();
List<ShapeRegion> shapeRegions = new List<ShapeRegion>();
// Add all the shapes to the worklist.
foreach(Figure fig in figures)
{
ShapeRegion r = new ShapeRegion(fig);
shapeRegions.Add(r);
worklist.Enqueue(r);
}
//
// Deconstruct non-atomic regions, construct atomic regions.
//
while(worklist.Any())
{
Region currRegion = worklist.Dequeue();
if (!currRegion.IsAtomic()) RegionDecomposition(currRegion, shapeRegions, worklist);
if (currRegion.IsAtomic()) RegionComposition(currRegion, shapeRegions, worklist);
}
graph.DebugDumpClauses();
Debug.WriteLine(graph.ToString());
return graph;
}
示例12: TraverseTheMatrix
public static int[,] TraverseTheMatrix(int[,] matrix, Cell startingCell)
{
var queue = new Queue<Cell>();
queue.Enqueue(startingCell);
while (queue.Any())
{
var cell = queue.Dequeue();
matrix[cell.X, cell.Y] = cell.Value;
for (int index = 0; index < Direction.Length; index += 2)
{
if (IsNextCellUsable(matrix,cell,index))
{
queue.Enqueue(new Cell
(
cell.X + Direction[index],
cell.Y + Direction[index + 1],
cell.Value + 1
));
}
}
}
return matrix;
}
示例13: FillFrom
public void FillFrom(Point currentPoint, byte label, byte[] imageData, Size imageSize, byte[] labelData)
{
var nextPointsQueue = new Queue<Point>();
nextPointsQueue.Enqueue(currentPoint);
while (nextPointsQueue.Any())
{
currentPoint = nextPointsQueue.Dequeue();
var currentLabel = _GetPixel(currentPoint, labelData, imageSize);
if (currentLabel != 0) { continue; }
_SetPixel(currentPoint, label, labelData, imageSize);
var currentValue = _GetPixel(currentPoint, imageData, imageSize);
var sameValueNeighborPoints =
_testPoints
.Select(tp => new Point(currentPoint.X + tp.X, currentPoint.Y + tp.Y))
.Where(p => _GetPixel(p, imageData, imageSize) != null) // Izbaci susjede van slike
.Where(p => _GetPixel(p, imageData, imageSize) == currentValue) // Izbaci elemente koji nisu iste boje kao trenutni
.Where(p => _GetPixel(p, labelData, imageSize) == 0) // Izbaci elemente koji vec imaju labelu
.ToList();
sameValueNeighborPoints.ForEach(nextPointsQueue.Enqueue);
}
}
示例14: Process
void Process(Node targetNode, Queue<Token> tokenQueue, TreeBuilderState state)
{
state.ProcessingState = new ProcessingState(targetNode, tokenQueue);
while (tokenQueue.Any())
{
var token = tokenQueue.Dequeue();
var tokenType = token.Type;
var rule = rules
.Where(r => r.TokenType == tokenType)
.FirstOrDefault();
if (rule == null)
{
targetNode.AddChild(new ParseFailureNode(token, "unexpected token"));
break;
}
var node = rule.NodeBuilder(token, state);
if (node != null)
targetNode.AddChild(node);
}
}
示例15: Transitize
public void Transitize()
{
Queue<Flow> q = new Queue<Flow>(_flows.Values);
// DEBUG only
// var copy = new List<KeyValuePair<SignalBase, Flow>>(_flows);
while (q.Any())
{
var flow = q.Dequeue();
SignalFlow sflow = flow as SignalFlow;
if (sflow != null)
{
Flow trflow;
if (_flows.TryGetValue(sflow.Source, out trflow))
{
SignalFlow strflow = trflow as SignalFlow;
if (strflow != null)
{
trflow = new SignalFlow(strflow.Source, sflow.Target);
}
ValueFlow vtrflow = trflow as ValueFlow;
if (vtrflow != null)
{
trflow = new ValueFlow(vtrflow.Value, sflow.Target);
}
_flows[sflow.Target] = trflow;
if (trflow.Equals(sflow))
throw new InvalidOperationException("Cyclic dataflow");
q.Enqueue(trflow);
}
}
}
}