本文整理汇总了C#中Stack.Take方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Take方法的具体用法?C# Stack.Take怎么用?C# Stack.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Take方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateNotificationsForUser
public void UpdateNotificationsForUser(IUser user, int maxNotificationBatchCountToCheck)
{
var notificationsUserPart = GetNotificationsUserPartOrThrow(user);
var uncheckedNotificationsQuery = _contentManager
.Query(VersionOptions.Published, Constants.NotificationBatchContentType)
.Where<CommonPartRecord>(record => record.Id > notificationsUserPart.LastProcessedNotificationId);
var uncheckedNotificationCount = uncheckedNotificationsQuery.Count();
var notifications = _notificationService.FetchNotifications(user, Math.Min(uncheckedNotificationCount, maxNotificationBatchCountToCheck));
var existingUserNotificationEntriesLookup = notificationsUserPart.RecentNotificationEntries.ToDictionary(entry => entry.NotificationId);
var existingUserNotificationEntries = new Stack<NotificationUserEntry>(notificationsUserPart.RecentNotificationEntries.Reverse());
foreach (var notification in notifications)
{
var notificationId = notification.ContentItem.Id;
if (!existingUserNotificationEntriesLookup.ContainsKey(notificationId))
{
existingUserNotificationEntries.Push(new NotificationUserEntry { NotificationId = notificationId });
}
}
notificationsUserPart.RecentNotificationEntries = existingUserNotificationEntries.Take(maxNotificationBatchCountToCheck);
var topNotification = uncheckedNotificationsQuery
.OrderByDescending<CommonPartRecord>(record => record.Id)
.Slice(1)
.SingleOrDefault();
if (topNotification != null)
{
notificationsUserPart.LastProcessedNotificationId = topNotification.Id;
}
}
示例2: PostMessages
public void PostMessages(Stack<Tuple<ConsoleColor, string>> messages)
{
//post messages
Console.SetCursorPosition(0, 20);
var messagesToDisplay = messages.Take(5).ToList();
int i = 0;
foreach (var message in messages)
{
Console.SetCursorPosition(0, 20 + i);
Console.ForegroundColor = message.Item1;
Console.WriteLine(message.Item2.Trim() + new String(' ', Console.BufferWidth));
if (i >= 4) { break; } else { i++; }
}
Console.SetCursorPosition(0, 0);
Console.CursorVisible = false;
}
示例3: DirectoryListingEnumerator
/// <summary>
/// Initializes a new instance of the <see cref="DirectoryListingEnumerator"/> class.
/// </summary>
/// <param name="entries">The file system entries to enumerate</param>
/// <param name="fileSystem">The file system of the file system entries</param>
/// <param name="pathEntries">The path entries of the current directory</param>
/// <param name="returnDotEntries"><code>true</code> when this enumerator should return the dot entries</param>
public DirectoryListingEnumerator(IEnumerable<IUnixFileSystemEntry> entries, IUnixFileSystem fileSystem, Stack<IUnixDirectoryEntry> pathEntries, bool returnDotEntries)
{
_pathEntries = pathEntries;
var topPathEntries = pathEntries.Take(3).ToList();
switch (topPathEntries.Count)
{
case 0:
CurrentDirectory = fileSystem.Root;
ParentDirectory = GrandParentDirectory = null;
break;
case 1:
CurrentDirectory = topPathEntries[0];
ParentDirectory = fileSystem.Root;
GrandParentDirectory = null;
break;
case 2:
CurrentDirectory = topPathEntries[0];
ParentDirectory = topPathEntries[1];
GrandParentDirectory = fileSystem.Root;
break;
default:
CurrentDirectory = topPathEntries[0];
ParentDirectory = topPathEntries[1];
GrandParentDirectory = topPathEntries[2];
break;
}
var dotEntries = new List<Tuple<IUnixDirectoryEntry, string>>();
if (returnDotEntries)
{
dotEntries.Add(Tuple.Create(CurrentDirectory, "."));
if (ParentDirectory != null)
dotEntries.Add(Tuple.Create(ParentDirectory, ".."));
}
_dotEntriesEnumerator = dotEntries.GetEnumerator();
_entriesEnumerator = entries.GetEnumerator();
}
示例4: EnsureStackSize
private static Stack<GuildBankLogEntry> EnsureStackSize(Stack<GuildBankLogEntry> stack)
{
if (stack.Count <= MAX_ENTRIES) return stack;
return (Stack<GuildBankLogEntry>)stack.Take(MAX_ENTRIES);
}
示例5: Parse
protected override ParseTreeNode Parse(Lexer lexer, NonTerminal root)
{
IEnumerator<Token> tokens = lexer.GetEnumerator();
var eof = !tokens.MoveNext();
if (eof)
{
if (root.Rules.Any(r => r.IsNullable()))
return new ParseTreeNode(null, new Token(new Terminal(""), "", 0, 0));
else
throw new ParseException("Empty string not matched by grammar");
}
Stack<ParseState> states = new Stack<ParseState>();
states.Push(MakeStateState(root, Grammar));
ParserAction action = ParserAction.Start;
Stack<ParseTreeNode> nodes = new Stack<ParseTreeNode>();
do
{
Production reduceProduction;
ParseState shiftState;
action = Action(states.Peek(), eof ? null : tokens.Current, out reduceProduction, out shiftState);
switch (action)
{
case ParserAction.Accept:
break;
case ParserAction.Error:
throw new ParseException(tokens.Current.ToString());
case ParserAction.Start:
default:
throw new NotImplementedException();
case ParserAction.Shift:
var newLeafNode = new ParseTreeNode(tokens.Current);
nodes.Push(newLeafNode);
states.Push(shiftState);
eof = !tokens.MoveNext();
break;
case ParserAction.Reduce:
var newNode = new ParseTreeNode(reduceProduction.Head);
var children = nodes.Take(reduceProduction.Body.Length).Reverse().Select((n, i) => new KeyValuePair<int, ParseTreeNode>(i, n));
foreach (var child in children)
{
child.Value.Parent = newNode;
nodes.Pop();
var bnfTerm = reduceProduction.Body[child.Key];
var terminal = bnfTerm as Terminal;
string match;
if (terminal != null)
{
if (!terminal.Match(child.Value.Token.Value, 0, out match))
throw new ParseException("Unexpected crap");
}
else if (!reduceProduction.Body[child.Key].Equals(child.Value.NonTerminal))
throw new ParseException("Unexpected crap");
}
nodes.Push(newNode);
for (int i = 0; i < reduceProduction.Body.Length; i++)
states.Pop();
states.Push(Goto(states.Peek(), reduceProduction.Head));
break;
}
} while (action != ParserAction.Accept);
if (nodes.Count != 1)
throw new ParseException("o_0");
return nodes.Pop();
}
示例6: CalculateEntropy
/// <summary>
/// Find the Cumulative Entropy over the last second worth of frames
/// </summary>
/// <param name="frameHistory">A stack of frames (i.e in reverse chronological order)</param>
/// <returns>The cumulative entropy over the last second</returns>
public double CalculateEntropy(Stack<List<Vector3D>> frameHistory)
{
// choose only the last second worth of frames
return frameHistory.Take(framesPerSecond+1).Aggregate(EntropyAcc.Zero, EntropyAcc.Aggregate).CumulativeEntropy;
}
示例7: GetPath
public List<TreeItem> GetPath(TreeItem root, bool leaveOutRootInReturnValue)
{
Stack<TreeItem> stack = new Stack<TreeItem>();
this.GetItemPath(root, ref stack);
return leaveOutRootInReturnValue ? stack.Take(stack.Count - 1).Reverse().ToList() : stack.Reverse().ToList();
}