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


C# SortedList.Take方法代码示例

本文整理汇总了C#中SortedList.Take方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Take方法的具体用法?C# SortedList.Take怎么用?C# SortedList.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedList的用法示例。


在下文中一共展示了SortedList.Take方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MovingAverage

 /// <summary>
 /// Computes the moving average of a quote list
 /// 
 /// Leaves off the first N-1 points before the window is fileld with data
 /// </summary>
 /// <param name="quoteList">The quote list to average</param>
 /// <param name="averageLength">The length of the moving average window</param>
 /// <returns>moving average quote list</returns>
 private SortedList<DateTime, double> MovingAverage(SortedList<DateTime, double> quoteList, int averageLength)
 {
     return quoteList.Skip(averageLength - 1).Aggregate(
         new
         {
             // Initialize list to hold results
             Result = new SortedList<DateTime, double>(),
             // Initialize Working list with the first N-1 items
             Working = new List<double>(quoteList.Take(averageLength - 1).Select(item => item.Value))
         },
         (list, item) =>
         {
             // Add the price from the current date to the working list
             list.Working.Add(item.Value);
             // Calculate the N item average for the past N days and add to the result list for the current date
             list.Result.Add(item.Key, list.Working.Average());
             // Remove the item from N days ago
             list.Working.RemoveAt(0);
             return list;
         }
     ).Result;
 }
开发者ID:anndream,项目名称:StockChart,代码行数:30,代码来源:MainWindow.xaml.cs

示例2: GetSuggestions

        public SortedList<double, List<string>> GetSuggestions(Int32 qty, bool considerSuffixLength,PrDel getWordProbability,Comparer<double> c)
        {
            if (qty < 0) return null;
            if (suffixes == null) return (new SortedList<double, List<string>>(c));

            if (suffixes.Count < qty) qty = suffixes.Count;
            var suggestions = new SortedList<double, List<string>>(c);
            double pr;
            List<string> li;
            foreach (var s in suffixes)
            {
                pr = getWordProbability(s.word);
                if (considerSuffixLength) pr *= (s.word.Length - GetPrefix().Length + 1); // +1 for the space (' ')
                if (suggestions.ContainsKey(pr)) {
                    li = suggestions[pr];
                    suggestions.Remove(pr);
                }
                else
                    li = new List<string>();
                if (li.Count < 5)
                    li.Add(s.word);
                suggestions.Add(pr,li);
            }
            int  count = 0;
            int amt = qty;
            foreach (var list in suggestions.Values)
            {
                amt -= list.Count;
                count++;
                if (amt <= 0) break;
            }
            var res = suggestions.Take(count);
            var ret = new SortedList<double, List<string>>(c);
            count = 0;
            foreach(var kvp in res)
            {
                count += kvp.Value.Count;
                if (count > qty)
                {
                    var range = kvp.Value.Count - (count-qty);
                    ret.Add(kvp.Key,kvp.Value.GetRange(0,range));
                    break;
                }
                else
                    ret.Add(kvp.Key,kvp.Value);
            }
            return ret;
        }
开发者ID:roeibux,项目名称:text-predict,代码行数:48,代码来源:TrieNode.cs


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