本文整理汇总了C#中ConcurrentDictionary.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentDictionary.OrderByDescending方法的具体用法?C# ConcurrentDictionary.OrderByDescending怎么用?C# ConcurrentDictionary.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentDictionary
的用法示例。
在下文中一共展示了ConcurrentDictionary.OrderByDescending方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MostFunnyUsers
public JsonResult MostFunnyUsers()
{
using (GagsDbContext model = new GagsDbContext())
{
var allGags = model.Gags.Include("Owner");
ConcurrentDictionary<Guid, int> counters = new ConcurrentDictionary<Guid, int>();
foreach (var gag in allGags)
{
if (!counters.ContainsKey(gag.Owner.Id))
counters[gag.Owner.Id] = 0;
counters[gag.Owner.Id]++;
}
var top10 = counters.OrderByDescending(x => x.Value).Take(10);
var context = new List<StatsModel>(10);
foreach (var user in top10)
{
context.Add(new StatsModel()
{
Name = model.Users.Where(x => x.Id == user.Key).First().Nickname,
Value = user.Value
});
}
JsonResult result = new JsonResult() { Data = context, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
return result;
}
}
示例2: Main
static void Main(string[] args)
{
cache = new ConcurrentDictionary<long, long>();
var results = new ConcurrentDictionary<int, int>();
Console.WriteLine("Processing data...");
Parallel.ForEach(Enumerable.Range(2, 999998), start =>
{
long i = start;
var d = new List<long>();
int number = start;
int steps = 1;
while (i > 1)
{
d.Add(i);
i = ProcessNumber(i);
steps++;
}
results.TryAdd(number, steps);
});
foreach (var result in results.OrderByDescending(r => r.Value).Take(100))
{
Console.WriteLine("n={0}, steps {1}", result.Key, result.Value);
}
Console.ReadKey();
}
示例3: Top10OccuringWords
public static IDictionary<string, int> Top10OccuringWords(string path)
{
var result = new ConcurrentDictionary<string, int>(StringComparer.OrdinalIgnoreCase);
Parallel.ForEach(File.ReadLines(path), line =>
{
var words = Regex.Split(line, @"\W");
foreach (var word in words.Where(word => !string.IsNullOrWhiteSpace(word)))
{
result.AddOrUpdate(word.ToString(), 1, (_, x) => x + 1);
}
});
return result.OrderByDescending(pair => pair.Value).Take(10).ToDictionary(pair => pair.Key, pair => pair.Value);
}
示例4: Preprocess
public void Preprocess(string outputDirPath)
{
ConcurrentDictionary<string, int> wordCount = new ConcurrentDictionary<string, int>();
ConcurrentDictionary<string, int> wordPageCount = new ConcurrentDictionary<string, int>();
WikiDataProvider wdp = new WikiDataProvider();
EngTokenizer tokenizer = new EngTokenizer();
EngMorphology morph = new EngMorphology();
Stopwatch timer = Stopwatch.StartNew();
Parallel.For(0, 13000, i => {
//for(int i = 0; i < 5 /*1300*/; i++)
//{
Console.WriteLine("Thread taking iteration: " + i);
Console.WriteLine("Loading 1K pages from DB");
var pages = wdp.GetPageByIDInRange(i * 1000, (i+1)*1000);
pages.ForEach(page => {
if (page.Language == "en")
{
if (page.PageID % 100 == 0) Console.WriteLine("Processing page: " + page.PageID);
var tokens = tokenizer.Annotate(page.Text).Select(x => ((TokenAnnotation)x)).ToList();
var distWords = tokens.Select(x => x.Text.Trim()).Distinct().ToList();
distWords.ForEach(dw => {
if (!wordPageCount.ContainsKey(dw)) wordPageCount.TryAdd(dw, 0);
wordPageCount[dw] += 1;
});
tokens.ForEach(t =>
{
if (!string.IsNullOrEmpty(t.Text))
{
if (!wordCount.ContainsKey(t.Text.ToLower())) wordCount.TryAdd(t.Text.ToLower(), 0);
wordCount[t.Text.ToLower()]++;
}
});
}
});
});
timer.Stop();
Console.WriteLine("Processing finished in: " + timer.Elapsed.ToString());
Console.WriteLine("Finished processing, writing freqs...");
TakeLab.Utilities.IO.StringWriter<string>.WriteDictionary<int>(wordCount.OrderByDescending(x => x.Value).ToList(), outputDirPath + "\\wikipedia-english-word-freq.txt");
Console.WriteLine("Finished processing, writing page freqs...");
TakeLab.Utilities.IO.StringWriter<string>.WriteDictionary<int>(wordPageCount.OrderByDescending(x => x.Value).ToList(), outputDirPath + "\\wikipedia-english-word-page-freq.txt");
}
示例5: Clout
/// <summary>
/// Calculates the clout for all users in the database
/// Responds to the command: clout
/// </summary>
/// <returns>Whether it succeeded and the results</returns>
public CommandResult Clout()
{
var results = new ConcurrentDictionary<Person, int>();
IEnumerable<Person> people = DataAccess.GetAllPeople();
Parallel.ForEach(
people,
person => results.AddOrUpdate(
person,
GetClout(person),
(key, oldValue) => oldValue));
return new CommandResult(
true,
string.Join(
Environment.NewLine,
results
.OrderByDescending(c => c.Value)
.Select(c => this.FormatCloutMessage(c.Key.Name, c.Value))));
}
示例6: GenerateLists
public void GenerateLists()
{
var tasks = new List<Task>();
for (int i = 0; i < 300; i++)
{
var task = new Task<HashSet<Song>>(() => DoGenerateList(new List<Song>(_songs)));
task.ContinueWith(AddPlaylistStats);
tasks.Add(task);
task.Start();
}
Task.WaitAll(tasks.ToArray());
Console.WriteLine("All Done -- Printing Stats");
Console.WriteLine("");
var sum = new ConcurrentDictionary<int, int>();
using (var file = new System.IO.StreamWriter("F:\\SongCount.txt"))
foreach (var key in count.OrderByDescending(x => x.Value).Select(x => x.Key))
{
Console.WriteLine("{0:d4}, {1}", count[key], key);
file.WriteLine("{0:d4}, {1}", count[key], key);
sum.AddOrUpdate(count[key], 1, (k, val) => ++val);
}
Console.WriteLine("Stats");
Console.WriteLine("Total: " + count.Count());
Console.WriteLine("Total count == 1: " + count.Where(x => x.Value == 1).Count());
Console.WriteLine("Total count > 1: " + count.Where(x => x.Value > 1).Count());
Console.WriteLine("Total count > 10: " + count.Where(x => x.Value > 10).Count());
Console.WriteLine("");
foreach (var key in sum.OrderByDescending( x => x.Value).Select(x => x.Key))
Console.WriteLine("{0:d4}, {1}", sum[key], key);
}
示例7: getMaxID
private long getMaxID(ConcurrentDictionary<long, Cycle> cycles)
{
return cycles.OrderByDescending(cycle => cycle.Value.ID).First().Value.ID;
}
示例8: Search
public IEnumerable<SearchResult> Search(string text)
{
// find the unique tokens in the input
var tokens = Tokenizer.Tokenize(text).Distinct().ToArray();
if (0 == tokens.Length) return new SearchResult[] { };
var results = new ConcurrentDictionary<string, IndexEntry<Metadata>[]>();
Parallel.ForEach(tokens, x => results.TryAdd(x, this.indexStore.Query(x).ToArray()));
var documents = new ConcurrentDictionary<string, List<string>>();
// count the results
Parallel.ForEach(results.Keys, token =>
{
foreach (var doc in results[token])
{
documents.AddOrUpdate(doc.Value, new List<string>(new[] {token}), (t, x) =>
{
x.Add(token);
return x;
});
}
});
// resturn the results
return documents.OrderByDescending(x => x.Value.Count()).Select(x => new SearchResult(x.Key, x.Value.ToArray()));
}