本文整理汇总了C#中HashSet.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.OrderByDescending方法的具体用法?C# HashSet.OrderByDescending怎么用?C# HashSet.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.OrderByDescending方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PollMessages
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;
}
}
示例2: WriteListings
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);
}
示例3: WriteListings
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);
}
示例4: GetTags
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));
}
示例5: GetNearestNeighbors
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();
}
示例6: Main
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);
}
}
示例7: GetScores
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();
}
示例8: WriteToScoreBoard
/// <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);
}
示例9: FindMostCommonWord
/// <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;
}
示例10: RemoveActivities
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);
}
}
示例11: UpdateBehaviorTreeView
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();
}
示例12: GetAllVariablesByDescending
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();
}
示例13: FindLongestWord
/// <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;
}
示例14: TargetWeights
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;
}
示例15: ShowAchievementUnlocked
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));
}