本文整理汇总了C#中SortedDictionary.Where方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Where方法的具体用法?C# SortedDictionary.Where怎么用?C# SortedDictionary.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Where_OnSortedDictionary_ReturnsDictionary
public void Where_OnSortedDictionary_ReturnsDictionary()
{
var instance = new SortedDictionary<int, int> { { 1, 1 }, { 2, 1 }, { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 }, { 7, 13 } };
var actual = instance.Where(kv => kv.Value > 3);
Assert.IsInstanceOf<Dictionary<int, int>>(actual);
}
示例2: Main
public static void Main()
{
#if DEBUG
Console.SetIn(new StreamReader("../../input.txt"));
#endif
var list = new SortedDictionary<string, int>();
var input = Console.ReadLine()
.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
foreach (var word in input)
{
if (list.ContainsKey(word))
{
list[word] += 1;
}
else
{
list[word] = 1;
}
}
var result = list.Where(n => n.Value % 2 != 0).Select(x => x.Key).ToList();
Console.WriteLine(string.Join(", ", result));
}
示例3: GetAlgorithmPerformance
/// <summary>
/// Returns the performance of the algorithm in the specified date range
/// </summary>
/// <param name="fromDate">The initial date of the range</param>
/// <param name="toDate">The final date of the range</param>
/// <param name="trades">The list of closed trades</param>
/// <param name="profitLoss">Trade record of profits and losses</param>
/// <param name="equity">The list of daily equity values</param>
/// <param name="pointsPerformance">The list of algorithm performance values</param>
/// <param name="pointsBenchmark">The list of benchmark values</param>
/// <param name="startingCapital">The algorithm starting capital</param>
/// <returns>The algorithm performance</returns>
private static AlgorithmPerformance GetAlgorithmPerformance(
DateTime fromDate,
DateTime toDate,
List<Trade> trades,
SortedDictionary<DateTime, decimal> profitLoss,
SortedDictionary<DateTime, decimal> equity,
List<ChartPoint> pointsPerformance,
List<ChartPoint> pointsBenchmark,
decimal startingCapital)
{
var periodTrades = trades.Where(x => x.ExitTime.Date >= fromDate && x.ExitTime < toDate.AddDays(1)).ToList();
var periodProfitLoss = new SortedDictionary<DateTime, decimal>(profitLoss.Where(x => x.Key >= fromDate && x.Key.Date < toDate.AddDays(1)).ToDictionary(x => x.Key, y => y.Value));
var periodEquity = new SortedDictionary<DateTime, decimal>(equity.Where(x => x.Key.Date >= fromDate && x.Key.Date < toDate.AddDays(1)).ToDictionary(x => x.Key, y => y.Value));
var listPerformance = new List<double>();
var performance = ChartPointToDictionary(pointsPerformance, fromDate, toDate);
performance.Values.ToList().ForEach(i => listPerformance.Add((double)(i / 100)));
var benchmark = ChartPointToDictionary(pointsBenchmark, fromDate, toDate);
var listBenchmark = CreateBenchmarkDifferences(benchmark, periodEquity);
EnsureSameLength(listPerformance, listBenchmark);
var runningCapital = equity.Count == periodEquity.Count ? startingCapital : periodEquity.Values.FirstOrDefault();
return new AlgorithmPerformance(periodTrades, periodProfitLoss, periodEquity, listPerformance, listBenchmark, runningCapital);
}
示例4: GetPosition
private Vector2 GetPosition(Identifier512 id, SortedDictionary<Identifier512, Peer> peers)
{
Peer end;
if (!peers.TryGetValue(id, out end))
end = peers.Where(a => a.Key >= id).Select(a => a.Value).FirstOrDefault() ?? peers.Last().Value;
return end.Position;
}
示例5: FilterPara
/// <summary>
/// 除去数组中的空值和签名参数并以字母a到z的顺序排序
/// </summary>
internal static Dictionary<string, string> FilterPara(SortedDictionary<string, string> dicArrayPre)
{
return
dicArrayPre.Where(
temp =>
temp.Key.ToLower() != "sign" && temp.Key.ToLower() != "sign_type" &&
!string.IsNullOrEmpty(temp.Value)).ToDictionary(temp => temp.Key, temp => temp.Value);
}
示例6: button1_Click
private void button1_Click(object sender, EventArgs e)
{
SortedDictionary<string, int> tDic = new SortedDictionary<string, int>(sDicKeyWords);
foreach (KeyValuePair<string, int> kvp in tDic.Where(entry => entry.Value < trackBarCutoffFreq.Value))
sDicKeyWords.Remove(kvp.Key);
ShowDictionary();
}
示例7: WriteDependencies
/// <summary>
/// Write given dependencies to file.
/// </summary>
/// <param name="dependencies"></param>
public void WriteDependencies(SortedDictionary<string, IAnalyzedSourceFile> dependencies)
{
foreach (var entry in dependencies.Where(entry => entry.Value.Provided.Count > 0))
{
_writer.WriteLine("goog.addDependency('{0}', [{1}], [{2}]);",
entry.Key,
String.Join(", ", entry.Value.Provided.Select(x => "'" + x + "'")),
String.Join(", ", entry.Value.Required.Select(x => "'" + x + "'")));
}
}
示例8: IsFarmingDone
private static bool IsFarmingDone(SortedDictionary<string, int> items)
{
var successMessages = new Dictionary<string, string>
{
{ "shards", "Shadowmourne obtained!" },
{ "fragments", "Valanyr obtained!" },
{ "motes", "Dragonwrath obtained!" }
};
foreach (var item in items.Where(item => item.Value >= 250))
{
items[item.Key] -= 250;
Console.WriteLine(successMessages[item.Key]);
return true;
}
return false;
}
示例9: Main
public static void Main()
{
var numbers = new List<int> { 2, 2, 3, 3, 2, 3, 4, 3, 3 };
int counterOccurs = (numbers.Count / 2) + 1;
var result = new SortedDictionary<int, int>();
foreach (var num in numbers)
{
if (result.ContainsKey(num))
{
result[num] += 1;
}
else
{
result[num] = 1;
}
}
Console.WriteLine(string.Join(", ", result.Where(n => n.Value >= counterOccurs).Select(n => n.Key)));
}
示例10: GetCellStyle
private static ICellStyle GetCellStyle(ICell cell, SortedDictionary<string, string> dic)
{
var wb = cell.Sheet.Workbook;
ICellStyle cellStyle = wb.CreateCellStyle();
cellStyle.CloneStyleFrom(cell.CellStyle);
var fontStyles = dic.Where(w => w.Key.StartsWith("font-")).ToArray();
var fontDic = new SortedDictionary<string, string>();
foreach (var kv in fontStyles)
{
fontDic.Add(kv.Key, kv.Value);
}
var font = wb.GetFont(fontDic);
var xdic = dic.Except(fontDic);
cellStyle.SetFont(font);//TODO 在基于style.xls基础的样式上增加css时,会造成原字体设置的丢失
foreach (var kvp in xdic)
{
FireCssAccess(cellStyle, wb, kvp);
}
return cellStyle;
}
示例11: Main
static void Main()
{
string entry = Console.ReadLine();
var vladkosNotebook = new SortedDictionary<string, Player>();
while (entry != "END")
{
string[] data = entry.Split('|');
string color = data[0];
if (!vladkosNotebook.ContainsKey(color))
{
vladkosNotebook[color] = new Player();
vladkosNotebook[color].Opponents = new List<string>();
}
Player currentPlayer = vladkosNotebook[color];
if (data[1] == "age")
{
int age = int.Parse(data[2]);
currentPlayer.Age = age;
}
else if (data[1] == "loss")
{
currentPlayer.LossCount += 1;
currentPlayer.Opponents.Add(data[2]);
}
else if (data[1] == "win")
{
currentPlayer.WinCount += 1;
currentPlayer.Opponents.Add(data[2]);
}
else if (data[1] == "name")
{
string name = data[2];
currentPlayer.Name = name;
}
entry = Console.ReadLine();
}
var validPages = vladkosNotebook
.Where(page => page.Value.Age != 0 && page.Value.Name != null);
if (validPages.Count() == 0)
{
Console.WriteLine("No data recovered.");
return;
}
var output = new StringBuilder();
foreach (var page in validPages)
{
output.AppendLine(string.Format("Color: {0}", page.Key));
output.AppendLine(string.Format("-age: {0}",page.Value.Age));
output.AppendLine(string.Format("-name: {0}", page.Value.Name));
if (page.Value.Opponents.Count > 0)
{
var sortedOpponents = page.Value.Opponents.OrderBy(o => o, StringComparer.Ordinal);
output.AppendLine(string.Format("-opponents: {0}", string.Join(", ", sortedOpponents)));
}
else
{
output.AppendLine(string.Format("-opponents: (empty)"));
}
double rank = (double)(page.Value.WinCount + 1) / (page.Value.LossCount + 1);
output.AppendLine(string.Format("-rank: {0:F2}", rank));
}
Console.WriteLine(output.ToString());
}
示例12: GetDataSet
//.........这里部分代码省略.........
if (!res.ContainsKey(groupDay)) res[groupDay] = new List<double>();
res[groupDay].Add(p.Value);
}
else if (ds.DData != null)
{
return new List<SortedDictionary<double, double>>() { ds.DData };
}
SortedDictionary<double, double> r = new SortedDictionary<double, double>();
switch (ds.GroupingOperation)
{
case GroupingOperations.count:
r = (from n in res select new KeyValuePair<double, double>(n.Key, n.Value.Count)).ToSortedDictionary(k => k.Key, k => k.Value);
break;
case GroupingOperations.maximum:
r = (from n in res select new KeyValuePair<double, double>(n.Key, n.Value.Max())).ToSortedDictionary(k => k.Key, k => k.Value);
break;
case GroupingOperations.minimum:
r = (from n in res select new KeyValuePair<double, double>(n.Key, n.Value.Min())).ToSortedDictionary(k => k.Key, k => k.Value);
break;
case GroupingOperations.average:
r = (from n in res select new KeyValuePair<double, double>(n.Key, n.Value.Average())).ToSortedDictionary(k => k.Key, k => k.Value);
break;
case GroupingOperations.total:
r = (from n in res select new KeyValuePair<double, double>(n.Key, n.Value.Sum())).ToSortedDictionary(k => k.Key, k => k.Value);
break;
}
SortedDictionary<double, double> f = new SortedDictionary<double, double>();
switch (ds.FunctionOperation)
{
case FunctionOperations.none:
f = r;
break;
case FunctionOperations.reduction:
{
var m = new MathFunctions();
var temp = (from n in r select new Point(n.Key, n.Value)).ToList();
var euclistx = new List<double>();
var euclisty = new List<double>();
for (int i = 0; i < temp.Count - 1; i++)
{
euclistx.Add(Math.Sqrt((temp[i].X - temp[i + 1].X)*(temp[i].X - temp[i + 1].X)));
euclisty.Add(Math.Sqrt((temp[i].Y - temp[i + 1].Y)*(temp[i].Y - temp[i + 1].Y)));
}
var thresholdx = Convert.ToDouble(euclistx.Average());
var thresholdy = Convert.ToDouble(euclisty.Average());
var dp = m.DouglasPeuckerReduction(temp, 10*thresholdx);
f = (from n in dp select new KeyValuePair<double, double>(n.X, n.Y)).ToSortedDictionary(k => k.Key,
k => k.Value);
}
break;
case FunctionOperations.auto:
{
if (ds.ReducedData == null)
ds.ReducedData = mf.CalculateReduction(r, 0.95); ;
f = ds.ReducedData;
if (ds.AggregatedData == null)
{
ds.AggregatedData = CalculateAggregate(f);
}
var actualsize = Math.Max(_view.Plot.ActualWidth - 60, 20);
var v = model.Axes.FirstOrDefault(k => k.Position == AxisPosition.Bottom);
var points = f.Where(k => k.Key > v.Minimum && k.Key < v.Maximum).Count();
if (points > actualsize / 2)
{
return ds.AggregatedData;
}
}
break;
case FunctionOperations.periodic:
{
var first = r.First();
var test = DateTimeAxis.ToDouble(new DateTime());
var period = DateTimeAxis.ToDouble(new DateTime() + ds.Periodic)-test;
var idx = 1.0;
var resultlist = new List<SortedDictionary<double, double>>();
foreach (var val in r)
{
if (val.Key - first.Key > period*idx)
{
resultlist.Add(f.ToSortedDictionary(k=>k.Key,k=>k.Value));
while (val.Key - first.Key > period*idx)
idx++;
f.Clear();
}
f.Add(first.Key + ((val.Key - first.Key) - period*(idx-1)),val.Value);
}
resultlist.Add(f.ToSortedDictionary(k => k.Key, k => k.Value));
return resultlist;
}
// FIXME TODO: Unreachable code
// break;
}
return new List<SortedDictionary<double, double>>() { f };
}
示例13: UpdateAnalysisTree
private static void UpdateAnalysisTree(IPythonProjectEntry pyEntry, SortedDictionary<int, ParseResult> parseResults) {
IAnalysisCookie cookie = new VersionCookie(
parseResults.ToDictionary(
x => x.Key,
x => new BufferVersion(x.Value.Version, x.Value.Ast)
)
);
var asts = parseResults.Where(x => x.Value.Ast != null).Select(x => x.Value.Ast).ToArray();
PythonAst finalAst;
if (asts.Length == 1) {
finalAst = asts[0];
} else if (asts.Length > 0) {
// multiple ASTs, merge them together
finalAst = new PythonAst(
new SuiteStatement(
asts.Select(ast => ast.Body).ToArray()
),
new NewLineLocation[0],
asts[0].LanguageVersion
);
} else {
// we failed to get any sort of AST out, so we can't analyze...
// But we need to balance the UpdateTree call, so just fetch the
// last valid ast and cookie.
pyEntry.GetTreeAndCookie(out finalAst, out cookie);
}
pyEntry.UpdateTree(finalAst, cookie);
}
示例14: ParseFile
private void ParseFile(IProjectEntry entry, IDictionary<int, CodeInfo> buffers) {
IPythonProjectEntry pyEntry;
IExternalProjectEntry externalEntry;
SortedDictionary<int, ParseResult> parseResults = new SortedDictionary<int, ParseResult>();
if ((pyEntry = entry as IPythonProjectEntry) != null) {
foreach (var buffer in buffers) {
var errorSink = new CollectingErrorSink();
var tasks = new List<AP.TaskItem>();
ParserOptions options = MakeParserOptions(errorSink, tasks);
using (var parser = buffer.Value.CreateParser(Project.LanguageVersion, options)) {
var ast = ParseOneFile(parser);
parseResults[buffer.Key] = new ParseResult(
ast,
errorSink,
tasks,
buffer.Value.Version
);
}
}
// Save the single or combined tree into the project entry
UpdateAnalysisTree(pyEntry, parseResults);
// update squiggles for the buffer. snapshot may be null if we
// are analyzing a file that is not open
SendParseComplete(pyEntry, parseResults);
// enqueue analysis of the file
if (parseResults.Where(x => x.Value.Ast != null).Any()) {
_analysisQueue.Enqueue(pyEntry, AnalysisPriority.Normal);
}
} else if ((externalEntry = entry as IExternalProjectEntry) != null) {
foreach (var keyValue in buffers) {
externalEntry.ParseContent(keyValue.Value.GetReader(), null);
_analysisQueue.Enqueue(entry, AnalysisPriority.Normal);
}
}
}
示例15: ToRequest
private string ToRequest(SortedDictionary<string, string> fields)
{
var values = new List<string>();
foreach (var item in fields.Where(x => x.Key != "signature"))
{
values.Add(string.Format("{0}={1}", item.Key,
UrlEncodeUpperCase(item.Value)));
}
return string.Join("&", values.ToArray());
}