private void PollMessages(object state) { var copyOfCachedMessages = new HashSet<Message>(_messageCache); var sinceId = copyOfCachedMessages.OrderByDescending(x => x.Created).First().IdValue; var messageService = CreateBaseMessageService.Invoke(); var messages = messageService.GetMessagesSinceAsync(sinceId).Result.ToList(); if (messages.Count == 0) return; foreach (var message in messages) { copyOfCachedMessages.Add(message); } if (copyOfCachedMessages.Count > MaxCacheCount) { var reducedCachedMessages = copyOfCachedMessages .OrderByDescending(x => x.Created) .Take(MaxCacheCount); copyOfCachedMessages.Clear(); foreach (var message in reducedCachedMessages) { copyOfCachedMessages.Add(message); } } lock (_padlock) { _messageCache = copyOfCachedMessages; } }
public void WriteListings() { HashSet<ArchiveListing> set = new HashSet<ArchiveListing>(); foreach (ArchiveListing listing in _set) { ArchiveListing item = listing; while (item != null && set.Add(item)) item = item.Parent; } Action<ArchiveListing> writer; switch (InteractionService.GamePart) { case FFXIIIGamePart.Part1: writer = ArchiveListingWriterV1.Write; break; case FFXIIIGamePart.Part2: writer = ArchiveListingWriterV2.Write; break; default: throw new NotSupportedException(InteractionService.GamePart.ToString()); } foreach (ArchiveListing listing in set.OrderByDescending(l => l.Accessor.Level)) writer(listing); }
public void WriteListings() { HashSet<ArchiveListing> set = new HashSet<ArchiveListing>(); foreach (ArchiveListing listing in _set) { ArchiveListing item = listing; while (item != null && set.Add(item)) item = item.Parent; } foreach (ArchiveListing listing in set.OrderByDescending(l => l.Accessor.Level)) ArchiveListingWriter.Write(listing); }
internal IEnumerable<RepositoryCommitModel> GetTags(string name, int page, int p, out string referenceName, out int totalCount) { var commit = GetCommitByName(name, out referenceName); if (commit == null) { totalCount = 0; return Enumerable.Empty<RepositoryCommitModel>(); } var tags = _repository.Tags; var commits = new HashSet<RepositoryCommitModel>(AnonymousComparer.Create<RepositoryCommitModel>((x, y) => x.ID == y.ID, obj => obj.ID.GetHashCode())); foreach (var tag in tags) { var c = _repository.Lookup(tag.Target.Id) as Commit; commits.Add(ToModel(c)); } totalCount = commits.Count(); return commits.OrderByDescending(x => x, (x, y) => x.Date.CompareTo(y.Date)); }
public List<LSHashTweet> GetNearestNeighbors(LSHashTweet tweet, int n) { if (_content.Count == 0) return new List<LSHashTweet>(); HashSet<LSHashTweet> candidates = new HashSet<LSHashTweet>(); List<long> wordIDs = tweet.Vector.GetItemIDs(); foreach (long wordID in wordIDs) { if (_wordIndex.ContainsKey(wordID)) { foreach (LSHashTweet candidate in _wordIndex[wordID]) candidates.Add(candidate); } } if (candidates.Count == 0) return new List<LSHashTweet>(); return candidates.OrderByDescending(t => t.Vector * tweet.Vector).Take(n).ToList(); }
static void Main(string[] args) { Console.WriteLine(11111); //SortedSet<TestSort> s = new SortedSet<TestSort>(new TestSort[] {new TestSort {Name="bar", Age=1}}); HashSet<TestSort> s = new HashSet<TestSort>(); s.Add( new TestSort {Name="foo6", Age=6} ); s.Add( new TestSort {Name="bar1", Age=1} ); s.Add( new TestSort {Name="hoge5", Age=5} ); //SortedSet<TestSort> s = new SortedSet<TestSort>(new TestSort[] { // new TestSort {Name="foo", Age=6}, // new TestSort {Name="bar", Age=1}, // new TestSort {Name="hoge", Age=5}, //}); Console.WriteLine(22222); Console.WriteLine(s); IEnumerable<TestSort>new_s = s.OrderByDescending(pet => pet.Age); foreach (TestSort ts in new_s) { Console.WriteLine(ts.Name); } }
public static ulong[] GetScores() { var scores = new HashSet<ulong>(); // row scores. for (var col = 0; col < 4; col++) { for (var row = 0; row < 6; row++) { ulong line = 0x0F; line <<= col + (row << 3); scores.Add(line); } } // column scores. for (var col = 0; col < 7; col++) { for (var row = 0; row < 3; row++) { ulong line = 0x01010101; line <<= col + (row << 3); scores.Add(line); } } // diagonal scores. for (var col = 0; col < 4; col++) { for (var row = 0; row < 3; row++) { ulong dig0 = 0x08040201; ulong dig1 = 0x01020408; dig0 <<= col + (row << 3); dig1 <<= col + (row << 3); scores.Add(dig0); scores.Add(dig1); } } return scores.OrderByDescending(s => s).ToArray(); }
/// <summary> /// Writes a player to the scoreboard database. /// </summary> /// <param name="player">PLayer to be written.</param> public void WriteToScoreBoard(IPlayer player) { ICollection<IPlayer> currentScoreBoard = new HashSet<IPlayer>(); currentScoreBoard = this.ReadScoreboard(); bool reorder = true; foreach (var currPlayer in currentScoreBoard.Where(cp => cp.Name == player.Name)) { if (currPlayer.Score <= player.Score) { currPlayer.Score = player.Score; reorder = false; } } var sortedScoreBoard = currentScoreBoard; if (reorder) { currentScoreBoard.Add(player); sortedScoreBoard = currentScoreBoard.OrderByDescending(pl => Convert.ToInt32(pl.Score)).ThenBy(pl => pl.Name).ToList(); } DataSerialization.WriteToFile(sortedScoreBoard, FileNames.scoreboard); }
/// <summary> /// Finds the most common word /// </summary> /// <param name="rank">How far down the list you want to go. for example if you wanted the 4th equal words you's pass 3</param> /// <returns>a list of either one or more strings that represtent the word or words equally tied at that rank</returns> public List<string> FindMostCommonWord(int rank) { var groupedWords = Words.GroupBy(e => e.WordText) // this linq statement groups and counts words based on their length .Select(group => new { Value = group.Key, Count = group.Count() }) .OrderByDescending(x => x.Count) .ToList(); ISet<int> commoness = new HashSet<int>(); foreach (var item in groupedWords) { commoness.Add(item.Count); // add the count of each word to the set } int i = commoness.OrderByDescending(e => e).ToList()[rank]; // this gets the number of times the most common word occured List<string> commonWords = new List<string>(); foreach (var word in groupedWords.Where(e => e.Count == i)) // this filters for words that occured that many times { commonWords.Add(word.Value); } return commonWords; }
public void RemoveActivities(System.Collections.IList items) { var indexes = new HashSet<int>(); foreach (Activity activity in items) { indexes.Add(this.Activities.IndexOf(activity)); } foreach (int index in indexes.OrderByDescending(i=>i)) { this.Activities.RemoveAt(index); } }
private void UpdateBehaviorTreeView() { behaviorTreeView.BeginUpdate(); behaviorTreeView.Nodes.Clear(); var rootKeys = new HashSet<string>(BT.Roots().Select(r => r.Key)); foreach (var key in PublicRoots) rootKeys.Add(key); foreach (var key in rootKeys.OrderByDescending(k => PublicRoots.Contains(k)).ThenBy(k => k)) { Behavior root; if (BT.Tree.TryGetValue(key, out root)) { var btPath = new BTPath { Path = new List<Behavior>() }; var newNode = AddNode(btPath, root, behaviorTreeView.Nodes); btPath.Path.Add(root); Expand(newNode, btPath); if (expandedPaths.Contains(newNode.Tag.ToString())) newNode.Expand(); } } behaviorTreeView.EndUpdate(); if (configParser.Errors.Count > 0 || analyzer.Errors.Count > 0) { errorListBox.BeginUpdate(); errorListBox.Items.Clear(); foreach (var error in configParser.Errors) errorListBox.Items.Add(error); foreach (var error in analyzer.Errors) errorListBox.Items.Add(error); errorListBox.EndUpdate(); errorListBox.Show(); errorLabel.Show(); } else { errorListBox.Hide(); errorLabel.Hide(); } overviewTooltipStatuslabel.Text = string.Format("{0} files, {1} nodes", layers.Count(l => l.Enabled), BT.Tree.Count); expandedPaths.Clear(); }
private void GetAllVariablesByDescending() { var variables = new HashSet<Variable>(); foreach (var equation in _equationsList) { equation.MoveAllVarsToLeft(); foreach (var expression in equation.LeftPart) { var variable = expression.Variable; if (!variable.Equals(Variable.NULL)) variables.Add(variable); } } _variablesList = variables.OrderByDescending(x => x.Name).ToList(); }
/// <summary> /// This gets the longest words excluding punctuation /// </summary> /// <param name="rank">How far down the list you want to go. for example if you wanted the 4th equal words you's pass 3</param> /// <returns>a list of either one or more strings that represtent the word or words equally tied at that rank</returns> public List<string> FindLongestWord(int rank) { ISet<int> wordLengths = new HashSet<int>(); // a set is needed for this because we need to avoid duplication i.e. two words of length 13 should only be counted once foreach (Word word in Words) { wordLengths.Add(word.WordLength); // add the lengths of all words to the set } List<int> sortedWordLengths = wordLengths.OrderByDescending(e => e).ToList(); // sort them from highest to lowest so we can fetch highest, 3rd highest, etc List<string> longestWords = new List<string>(); int wordLength = 0; try { wordLength = sortedWordLengths[rank]; // try to use what has been passed in with the rank parameter but it might be out of range } catch (IndexOutOfRangeException) { wordLength = sortedWordLengths.Last(); // if out of range just call the last one (this doesn't help if there's nothing in the list though) } foreach (Word word in Words.Where(e => e.WordLength == wordLength)) // filter words by their length, the length to use is calc using rank { longestWords.Add(word.WordText); } return longestWords; }
private static IEnumerable<Obj_AI_Hero> TargetWeights(List<Obj_AI_Hero> targets) { try { foreach (var item in WeightedItems.Where(w => w.Weight > 0)) { item.UpdateMinMax(targets); } var targetsList = new HashSet<Target>(); var multiplicator = _menu.Item(_menu.Name + ".weights.heroes.weight-multiplicator").GetValue<Slider>().Value; foreach (var target in targets) { var tmpWeight = WeightedItems.Where(w => w.Weight > 0).Sum(w => w.CalculatedWeight(target)); if (_menu != null) { tmpWeight += (_menu.Item(_menu.Name + ".weights.heroes." + target.ChampionName).GetValue<Slider>().Value * _averageWeight + 0.1f) * multiplicator; } targetsList.Add(new Target(target, tmpWeight)); } return targetsList.Count > 0 ? targetsList.OrderByDescending(t => t.Weight).Select(t => t.Hero) : null; } catch (Exception ex) { Global.Logger.AddItem(new LogItem(ex)); } return null; }
private static void ShowAchievementUnlocked(Achievement a) { var content = new GUIContent("ACHIEVEMENT UNLOCKED\n" + a.Title, GetIcon ()); // Find the best window to display this on var allWindows = new HashSet<EditorWindow>((EditorWindow[])Resources.FindObjectsOfTypeAll(typeof(EditorWindow))); allWindows.RemoveWhere (IsEditorWindowHiddenTab); var targetWindow = allWindows.OrderByDescending(w => Mathf.Pow(w.position.width, WidthBias) * w.position.height).FirstOrDefault(); if(targetWindow) { targetWindow.ShowNotification(content); } Debug.Log (string.Format("ACHIEVEMENT UNLOCKED: {0}\n{1}\n\n\n\n\n", a.Title, a.Description)); }
public Task<IEnumerable<Message>> GetMessagesAsync() { var copyOfCachedMessages = new HashSet<Message>(_messageCache); return Task.FromResult( copyOfCachedMessages .OrderByDescending(x => x.Created) .Take(Count)); }
/// <summary> /// Finds a list of sentances with the highest or highest equal word count /// </summary> /// <returns>Returns a list containing either a single or mulitple sentences</returns> public List<Sentence> FindSentenceWithMostWords(int rank) { ISet<int> sentenceWordCount = new HashSet<int>(); // a set is needed for this because we need to avoid duplication i.e. two sentances of count 13 should only be counted once foreach (Sentence sentence in Sentences) // this loop adds the word count of each sentence to the set { sentenceWordCount.Add(sentence.WordCount);// if a count already exists, say there has already been a count of 13, it trys to add a different sentence that has a count of 13, this statement will skip over that silently } List<int> sortedSentenceWordCount = sentenceWordCount.OrderByDescending(e => e).ToList(); // the set in order say { 16, 7, 13 } need to be sorted to { 16, 13, 7 } return Sentences.Where(e => e.WordCount == sortedSentenceWordCount[rank]).ToList(); // this gets all the sentances with the requird word count }