本文整理汇总了C#中SortedDictionary.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Reverse方法的具体用法?C# SortedDictionary.Reverse怎么用?C# SortedDictionary.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
StreamReader words = new StreamReader("../../words.txt");
StreamReader textReader = new StreamReader("../../text.txt");
StreamWriter resultWriter = new StreamWriter("../../result.txt");
using (words)
{
using (textReader)
{
using (resultWriter)
{
var text = textReader.ReadToEnd().ToLower();
var result = new SortedDictionary<int, string>();
string word = words.ReadLine();
while (word != null)
{
var pattern = string.Format(@"\b{0}\b", word.ToLower());
var match = Regex.Matches(text, pattern);
result.Add(match.Count, word);
word = words.ReadLine();
}
foreach (var match in result.Reverse())
{
resultWriter.WriteLine("word: {0}-> count: {1}", match.Value, match.Key);
}
}
}
}
}
示例2: Main
static void Main()
{
using (var readerKeys = new StreamReader("../../words.txt"))
{
using (var readerText = new StreamReader("../../text.txt"))
{
using (var writerResult = new StreamWriter("../../result.txt"))
{
var text = readerText.ReadToEnd().ToLower();
var result = new SortedDictionary<int, string>();
string word;
while ((word = readerKeys.ReadLine()) != null)
{
var pattern = string.Format(@"\b{0}\b", word.ToLower());
var match = Regex.Matches(text, pattern);
result.Add(match.Count, word);
}
foreach (var match in result.Reverse())
{
writerResult.WriteLine("{0} - {1}", match.Value, match.Key);
}
}
}
}
}
示例3: Main
static void Main()
{
StreamReader readerWords = new StreamReader(@"words.txt");
StreamReader readerText = new StreamReader(@"text.txt");
StreamWriter writer = new StreamWriter(@"results.txt");
var results = new SortedDictionary<int, string>();
using (readerWords)
{
using (readerText)
{
using (writer)
{
string text = readerText.ReadToEnd().ToLower();
string word;
while ((word = readerWords.ReadLine()) != null)
{
string pattern = @"\b" + word.ToLower() + @"\b";
MatchCollection match = Regex.Matches(text, pattern);
results.Add(match.Count, word);
}
foreach (var item in results.Reverse())
{
writer.WriteLine("{0}-{1}", item.Value, item.Key);
}
}
}
}
}
示例4: Update
private float Update(float mainThrottle, LiquidFuelEngine targetEngine)
{
if (targetEngine.State != PartStates.ACTIVE) { return mainThrottle; }
if (Time.frameCount != lastFrame)
{
lastFrame = Time.frameCount;
var engineGroups = new SortedDictionary<float, List<LiquidFuelEngine>>();
float thrust = 0;
foreach (var part in targetEngine.vessel.parts)
{
var engine = part as LiquidFuelEngine;
if (engine != null)
{
if (engine.State != PartStates.ACTIVE) { continue; }
thrust += engine.maxThrust;
if (!engineGroups.ContainsKey(engine.realIsp)) { engineGroups[engine.realIsp] = new List<LiquidFuelEngine>(); }
engineGroups[engine.realIsp].Add(engine);
}
}
thrust *= mainThrottle;
throttleValues = new Dictionary<LiquidFuelEngine, float>();
foreach (var kvp in engineGroups.Reverse())
{
var group = kvp.Value;
float availableThrust = 0;
foreach (var engine in group)
{
availableThrust += engine.maxThrust;
}
var groupThrust = Math.Min(availableThrust, thrust);
thrust -= groupThrust;
var throttle = groupThrust / availableThrust;
foreach (var engine in group)
{
throttleValues[engine] = throttle;
}
}
}
if (throttleValues.ContainsKey(targetEngine))
{
return throttleValues[targetEngine];
}
else
{
MonoBehaviour.print(String.Format("[MajiirKerbalLib] Couldn't find throttle level for {0}", targetEngine.name));
return mainThrottle;
}
}
示例5: ShowResults_Click
private void ShowResults_Click(object sender, RoutedEventArgs e)
{
String login = Login.Text;
int dependencyLevel = 0;
if (DependencyLevel.Text.Length > 0)
{
try
{
dependencyLevel = int.Parse(DependencyLevel.Text);
}
catch (System.FormatException)
{
MessageBox.Show("Invalid format of Dependency Level: nonnegativ number required");
return;
}
if (dependencyLevel < 0)
{
MessageBox.Show("Invalid format of Dependency Level: nonnegativ number required");
return;
}
}
//MessageBox.Show(login + " " + dependencyLevel);
Dictionary<Tuple<string, string>, int> x;
Dictionary<Tuple<String, String>, int> dependencies;
analyzer.FilterPositiveDependencies(analyzer.GetDependencies(), out dependencies, out x);
Login1.Items.Clear();
Login2.Items.Clear();
Value.Items.Clear();
SortedDictionary<long,Tuple<string,string>> dep = new SortedDictionary<long,Tuple<string,string>>();
long i = 0;
long Mult = 1000000000;
foreach (KeyValuePair<Tuple<String, String>, int> element in dependencies)
if (dependencyLevel <= element.Value && (login.Equals("") || login.CompareTo(element.Key.Item1) == 0 || login.CompareTo(element.Key.Item2) == 0))
{
dep.Add(Mult * element.Value + i, element.Key);
i++;
}
i=0;
foreach(KeyValuePair<long,Tuple<string, string>> element in dep.Reverse())
if (i < 27)
{
Login1.Items.Add(element.Value.Item1);
Login2.Items.Add(element.Value.Item2);
Value.Items.Add(element.Key/Mult);
i++;
}
}
示例6: Main
static void Main(string[] args)
{
string key = Console.ReadLine();
int numParagraphs = int.Parse(Console.ReadLine());
SortedDictionary<int, string> dict = new SortedDictionary<int, string>();
char[] symbols = new char[] { ',', '.', '(', ')', ';', '-', '!', '?', ' ' };
List<string> sortedList = new List<string>();
for (int i = 0; i < numParagraphs; i++)
{
string data = Console.ReadLine();
string[] words = data.Split(symbols, StringSplitOptions.RemoveEmptyEntries);
int count = 0;
for (int j = 0; j < words.Length; j++)
{
if (key.ToUpper().Equals(words[j].ToUpper()))
{
words[j] = key.ToUpper();
count++;
}
}
dict.Add(count, String.Join(" ", words));
}
foreach (var element in dict.Reverse())
{
Console.WriteLine(element.Value);
}
}
示例7: Main
static void Main(string[] args)
{
using (var wordsReader = new StreamReader("../../words.txt"))
{
using (var textReader = new StreamReader("../../text.txt"))
{
using (var writer = new StreamWriter("../../result.txt"))
{
var words = new List<string>();
var word = wordsReader.ReadLine();
while (word != null)
{
words.Add(word);
word = wordsReader.ReadLine();
}
var text = textReader.ReadToEnd().ToLower();
var result = new SortedDictionary<int, string>();
words.ForEach(x =>
{
var regex = @"\b" + x.ToLower() + @"\b";
var match = Regex.Matches(text, regex);
result.Add(match.Count, x);
});
foreach (var foundWord in result.Reverse())
{
writer.WriteLine("{0} - {1}", foundWord.Value, foundWord.Key);
}
}
}
}
Console.WriteLine("File done");
}
示例8: SortScores
private static void SortScores(out Guild winner)
{
winner = null;
List<string> ret = new List<string>();
SortedDictionary<uint, SortEntry<uint, Guild>> sortdict = new SortedDictionary<uint, SortEntry<uint, Guild>>();
foreach (Guild guild in Scores.Values)
{
if (!ServerBase.Kernel.Guilds.ContainsKey(guild.ID))
continue;
if (sortdict.ContainsKey(guild.WarScore))
{
sortdict[guild.WarScore].Values.Add(guild.ID, guild);
}
else
{
sortdict.Add(guild.WarScore, new SortEntry<uint, Guild>());
sortdict[guild.WarScore].Values = new Dictionary<uint, Guild>();
sortdict[guild.WarScore].Values.Add(guild.ID, guild);
}
}
int Place = 0;
foreach (KeyValuePair<uint, SortEntry<uint, Guild>> entries in sortdict.Reverse())
{
foreach (Guild guild in entries.Value.Values.Values)
{
if (Place == 0)
winner = guild;
string str = "No " + (Place + 1).ToString() + ": " + guild.Name + "(" + entries.Key + ")";
ret.Add(str);
Place++;
if (Place == 4)
break;
}
if (Place == 4)
break;
}
changed = false;
scoreMessages = ret.ToArray();
}
示例9: SortPersonByRatingAndName
static StringBuilder SortPersonByRatingAndName(Dictionary<string, int> jobsByRating, Dictionary<string, List<string>> jobsAndPersons)
{
SortedDictionary<int, List<string>> ratingAndNames = new SortedDictionary<int, List<string>>();
StringBuilder result = new StringBuilder();
int rating = 0;
List<string> names = null;
bool toExecute = false;
foreach (var job in jobsByRating.Keys)
{
if (jobsByRating.ContainsKey(job) && jobsAndPersons.ContainsKey(job))
{
rating = jobsByRating[job];
names = jobsAndPersons[job];
if (ratingAndNames.ContainsKey(rating))
{
ratingAndNames[rating].AddRange(names);
}
else
{
ratingAndNames.Add(rating, names);
}
toExecute = true;
ratingAndNames[rating].Sort();
}
}
if (toExecute)
{
foreach (var pair in ratingAndNames.Reverse())
{
foreach (var personName in pair.Value)
{
string[] reorderNames = personName.Split(' ');
result.AppendLine(reorderNames[1] + ' ' + reorderNames[0]);
}
}
}
return result;
}
示例10: Sort
public static void Sort(uint updateUID)
{
SortedDictionary<ulong, SortEntry<uint, NobilityInformation>> sortdict = new SortedDictionary<ulong, SortEntry<uint, NobilityInformation>>();
foreach (NobilityInformation info in Board.Values)
{
if (sortdict.ContainsKey(info.Donation))
{
SortEntry<uint, NobilityInformation> entry = sortdict[info.Donation];
entry.Values.Add(info.EntityUID, info);
}
else
{
SortEntry<uint, NobilityInformation> entry = new SortEntry<uint, NobilityInformation>();
entry.Values = new Dictionary<uint, NobilityInformation>();
entry.Values.Add(info.EntityUID, info);
sortdict.Add(info.Donation, entry);
}
}
SafeDictionary<uint, NobilityInformation> sortedBoard = new SafeDictionary<uint, NobilityInformation>(10000);
int Place = 0;
foreach (KeyValuePair<ulong, SortEntry<uint, NobilityInformation>> entries in sortdict.Reverse())
{
foreach (KeyValuePair<uint, NobilityInformation> value in entries.Value.Values)
{
Client.GameState client = null;
try
{
int previousPlace = value.Value.Position;
value.Value.Position = Place;
NobilityRank Rank = NobilityRank.Serf;
if (Place >= 50)
{
if (value.Value.Donation >= 200000000)
{
Rank = NobilityRank.Earl;
//ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To Earl in Nobility Rank.", System.Drawing.Color.White, Message.TopLeft), ServerBase.Kernel.GamePool.Values);
//Rank = NobilityRank.Earl;
}
else if (value.Value.Donation >= 100000000)
{
Rank = NobilityRank.Baron;
//ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To Baron in Nobility Rank.", System.Drawing.Color.White, Message.TopLeft), ServerBase.Kernel.GamePool.Values);
//Rank = NobilityRank.Baron;
}
else if (value.Value.Donation >= 30000000)
{
Rank = NobilityRank.Knight;
//ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To Knight in Nobility Rank.", System.Drawing.Color.White, Message.TopLeft), ServerBase.Kernel.GamePool.Values);
//Rank = NobilityRank.Knight;
}
}
else
{
if (Place < 3)
{
//Conquer_Online_Server.ServerBase.Kernel.SendWorldMessage(new Conquer_Online_Server.Network.GamePackets.Message("Congratulation! " + client.Entity.Name + "Donation To King in Nobility Rank!", System.Drawing.Color.White, 2011), Conquer_Online_Server.ServerBase.Kernel.GamePool.Values);
Rank = NobilityRank.King;
//Conquer_Online_Server.Clan.nobmas(client);
// ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To King/Queen in Nobility Rank.", System.Drawing.Color.White, Message.Center), ServerBase.Kernel.GamePool.Values);
//Rank = NobilityRank.King;
}
else if (Place < 15)
{
Rank = NobilityRank.Prince;
//Conquer_Online_Server.Clan.nobmas(client);
// ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To Prince in Nobility Rank.", System.Drawing.Color.White, Message.Center), ServerBase.Kernel.GamePool.Values);
// Rank = NobilityRank.Prince;
}
else
{
Rank = NobilityRank.Duke;
//Conquer_Online_Server.Clan.nobmas(client);
//ServerBase.Kernel.SendWorldMessage(new Message("Congratulation! " + client.Entity.Name + "Donation To Duke in Nobility Rank.", System.Drawing.Color.White, Message.Center), ServerBase.Kernel.GamePool.Values);
//Rank = NobilityRank.Duke;
}
}
var oldRank = value.Value.Rank;
value.Value.Rank = Rank;
if (ServerBase.Kernel.GamePool.TryGetValue(value.Key, out client))
{
bool updateTheClient = false;
if (oldRank != Rank)
{
updateTheClient = true;
}
else
{
if (previousPlace != Place)
{
updateTheClient = true;
}
}
if (updateTheClient || client.Entity.UID == updateUID)
{
NobilityInfo update = new NobilityInfo(true);
update.Type = NobilityInfo.Icon;
//.........这里部分代码省略.........
示例11: YesterdaySort
public static void YesterdaySort()
{
SortedDictionary<ulong, SortEntry<uint, ArenaStatistic>> sortDictionary = new SortedDictionary<ulong, SortEntry<uint, ArenaStatistic>>();
foreach (ArenaStatistic info in ArenaStatistics.Values)
{
if (sortDictionary.ContainsKey(info.LastSeasonArenaPoints))
{
SortEntry<uint, ArenaStatistic> entry = sortDictionary[info.LastSeasonArenaPoints];
entry.Values.Add(info.EntityID, info);
}
else
{
SortEntry<uint, ArenaStatistic> entry = new SortEntry<uint, ArenaStatistic>();
entry.Values = new Dictionary<uint, ArenaStatistic>();
entry.Values.Add(info.EntityID, info);
sortDictionary.Add(info.LastSeasonArenaPoints, entry);
}
}
SafeDictionary<uint, ArenaStatistic> toReplace = new SafeDictionary<uint, ArenaStatistic>(10000);
uint Place = 1;
foreach (KeyValuePair<ulong, SortEntry<uint, ArenaStatistic>> entries in sortDictionary.Reverse())
{
foreach (uint e in entries.Value.Values.Keys)
{
if (ArenaStatistics[e].YesterdayTotal != 0)
{
ArenaStatistics[e].LastSeasonRank = Place;
Place++;
toReplace.Add(e, ArenaStatistics[e]);
}
}
}
YesterdayArenaStatistics = toReplace;
}
示例12: Sort
public static void Sort()
{
SortedDictionary<ulong, SortEntry<uint, ArenaStatistic>> sortDictionary = new SortedDictionary<ulong, SortEntry<uint, ArenaStatistic>>();
foreach (ArenaStatistic info in ArenaStatistics.Values)
{
if (sortDictionary.ContainsKey(info.ArenaPoints))
{
SortEntry<uint, ArenaStatistic> entry = sortDictionary[info.ArenaPoints];
entry.Values.Add(info.EntityID, info);
}
else
{
SortEntry<uint, ArenaStatistic> entry = new SortEntry<uint, ArenaStatistic>();
entry.Values = new Dictionary<uint, ArenaStatistic>();
entry.Values.Add(info.EntityID, info);
sortDictionary.Add(info.ArenaPoints, entry);
}
}
Dictionary<uint, ArenaStatistic> toReplace = new Dictionary<uint, ArenaStatistic>();
Dictionary<uint, ArenaStatistic> addAtEnd = new Dictionary<uint, ArenaStatistic>();
uint Place = 1;
InArenaListCount = 0;
foreach (KeyValuePair<ulong, SortEntry<uint, ArenaStatistic>> entries in sortDictionary.Reverse())
{
foreach (uint e in entries.Value.Values.Keys)
{
if (ArenaStatistics[e].TodayBattles != 0)
{
ArenaStatistics[e].Rank = Place;
Place++;
InArenaListCount++;
toReplace.Add(e, ArenaStatistics[e]);
}
else
{
ArenaStatistics[e].Rank = 0;
addAtEnd.Add(e, ArenaStatistics[e]);
}
}
}
foreach (var v in addAtEnd)
{
toReplace.Add(v.Key, v.Value);
}
ArenaStatistics = toReplace;
ArenaStatisticsList = ArenaStatistics.Values.ToList();
}
示例13: SynchroniseZOrders
private static void SynchroniseZOrders(SortedDictionary<int, Shape> shapeOriginalZOrders)
{
Shape lastShape = null;
foreach (var entry in shapeOriginalZOrders.Reverse())
{
var shape = entry.Value;
if (lastShape != null)
{
Graphics.MoveZUntilBehind(shape, lastShape);
}
lastShape = shape;
}
}
示例14: ShowEvaluation
private static void ShowEvaluation(int recordNum, ModelWritter feature_index, LBFGS lbfgs, int termNum, int itr, int[,] merr, int[] yfreq, double diff, DateTime startDT, long nonzero_feature_num, EncoderArgs args)
{
var ts = DateTime.Now - startDT;
if (args.debugLevel > 1)
{
for (var i = 0; i < feature_index.y_.Count; i++)
{
var total_merr = 0;
var sdict = new SortedDictionary<double, List<string>>();
for (var j = 0; j < feature_index.y_.Count; j++)
{
total_merr += merr[i, j];
var v = (double)merr[i, j] / (double)yfreq[i];
if (v > 0.0001)
{
if (sdict.ContainsKey(v) == false)
{
sdict.Add(v, new List<string>());
}
sdict[v].Add(feature_index.y_[j]);
}
}
var vet = (double)total_merr / (double)yfreq[i];
vet = vet * 100.0F;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("{0} ", feature_index.y_[i]);
Console.ResetColor();
Console.Write("[FR={0}, TE=", yfreq[i]);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("{0:0.00}%", vet);
Console.ResetColor();
Console.WriteLine("]");
var n = 0;
foreach (var pair in sdict.Reverse())
{
for (int index = 0; index < pair.Value.Count; index++)
{
var item = pair.Value[index];
n += item.Length + 1 + 7;
if (n > 80)
{
//only show data in one line, more data in tail will not be show.
break;
}
Console.Write("{0}:", item);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0:0.00}% ", pair.Key * 100);
Console.ResetColor();
}
if (n > 80)
{
break;
}
}
Console.WriteLine();
}
}
var act_feature_rate = (double)(nonzero_feature_num) / (double)(feature_index.feature_size()) * 100.0;
Console.WriteLine("iter={0} terr={1:0.00000} serr={2:0.00000} diff={3:0.000000} fsize={4}({5:0.00}% act)", itr, 1.0 * lbfgs.err / termNum, 1.0 * lbfgs.zeroone / recordNum, diff, feature_index.feature_size(), act_feature_rate);
Console.WriteLine("Time span: {0}, Aver. time span per iter: {1}", ts, new TimeSpan(0, 0, (int)(ts.TotalSeconds / (itr + 1))));
}
示例15: textProcessorWorker_DoWork
private void textProcessorWorker_DoWork(object sender, DoWorkEventArgs e)
{
const float READ_MILESTONE = 20.0f;
const float SORT_MILESTONE = 60.0f;
const float ACUM_MILESTONE = 20.0f;
tp = new TextProcessor();
DirectoryInfo dirInfo = new DirectoryInfo("C:\\Users\\Riseven\\Desktop\\texts");
FileInfo[] finfos = dirInfo.GetFiles();
for (int fileIndex = 0; fileIndex < finfos.Length ; fileIndex++)
{
tp.processFile(finfos[fileIndex]);
textProcessorWorker.ReportProgress((int)(READ_MILESTONE * (fileIndex + 1) / finfos.Length));
}
textProcessorWorker.ReportProgress((int)READ_MILESTONE);
Dictionary<string, int> dictionary = tp.WordFrequency;
SortedDictionary<int, List<string>> sorted = new SortedDictionary<int, List<string>>();
// Sort words by frequency
int totalWords = 0;
foreach (int freq in dictionary.Values)
{
totalWords += freq;
}
int sortedWords = 0;
foreach (KeyValuePair<string, int> pair in dictionary)
{
sortedWords += pair.Value;
if (sorted.ContainsKey(pair.Value) == false)
{
List<string> newList = new List<string>();
newList.Add(pair.Key);
sorted[pair.Value] = newList;
}
else
{
List<string> list = sorted[pair.Value];
list.Add(pair.Key);
}
textProcessorWorker.ReportProgress((int)(READ_MILESTONE + SORT_MILESTONE * sortedWords / totalWords));
}
textProcessorWorker.ReportProgress((int)(READ_MILESTONE + SORT_MILESTONE));
int currentWords = 0;
int currentIndex = 0;
foreach (KeyValuePair<int, List<string>> pair in sorted.Reverse())
{
foreach (string word in pair.Value)
{
currentWords += pair.Key;
currentIndex += 1;
int freq = (int)((((Int64)pair.Key) * 1000000) / totalWords);
int cummFreq = currentWords * 100 / totalWords;
rows.Add( new object[]{currentIndex, word, freq, cummFreq} );
textProcessorWorker.ReportProgress((int)(READ_MILESTONE + SORT_MILESTONE + ACUM_MILESTONE * currentWords / totalWords));
}
}
textProcessorWorker.ReportProgress(100);
System.Threading.Thread.Sleep(1000);
}