当前位置: 首页>>代码示例>>C#>>正文


C# ConcurrentDictionary.OrderByDescending方法代码示例

本文整理汇总了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;

            }
        }
开发者ID:razaba,项目名称:WebGag2,代码行数:27,代码来源:StatsController.cs

示例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();
        }
开发者ID:RichTeaMan,项目名称:EulerProblems,代码行数:27,代码来源:Program.cs

示例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);
        }
开发者ID:BarberaErrera,项目名称:TechnicalTests,代码行数:14,代码来源:Program.cs

示例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");
        }
开发者ID:gglavas,项目名称:light-ls,代码行数:50,代码来源:WikipediaPreprocessing.cs

示例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))));
        }
开发者ID:wnossair,项目名称:Clout,代码行数:25,代码来源:Engine.cs

示例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);
        }
开发者ID:rsgoheen,项目名称:PlayListConsole,代码行数:36,代码来源:AggregateListTest.cs

示例7: getMaxID

 private long getMaxID(ConcurrentDictionary<long, Cycle> cycles)
 {
     return cycles.OrderByDescending(cycle => cycle.Value.ID).First().Value.ID;
 }
开发者ID:pksorensen,项目名称:CycleR,代码行数:4,代码来源:FreeForAll.cs

示例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()));
        }
开发者ID:richorama,项目名称:AzureStorageExtensions,代码行数:29,代码来源:TextSearchIndex.cs


注:本文中的ConcurrentDictionary.OrderByDescending方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。