我正在寻找加速合并两个 SortedLists 代码的方法。
C# 4.0 泛型 SortedList:http://msdn.microsoft.com/zh-cn/library/ms132319(v=vs.100).aspx
我在考虑使用联合操作代替
另外,如果有更好的方法来完成这个任务,我也愿意听取建议。
C# 4.0 泛型 SortedList:http://msdn.microsoft.com/zh-cn/library/ms132319(v=vs.100).aspx
public Trait getTrait(decimal thisValue)
{
if (ParentStructure != null && ParentStructure.RankedTraits.Count > 0)
{
SortedList<decimal, Trait> tempTraits = this.RankedTraits;
// Improve here (union?)
foreach (KeyValuePair<decimal, Trait> kvp in (ParentStructure.RankedTraits))
{
if (!tempTraits.ContainsKey(kvp.Key))
{
tempTraits.Add(kvp.Key, kvp.Value);
}
}
return _getTrait(tempTraits, thisValue);
}
}
return _getTrait(_rankTraits, thisValue);
}
我在考虑使用联合操作代替
foreach
循环可能更快,但我不知道如何在SortedList
上实现联合操作。如果有人能帮助我解决这个问题,我将不胜感激。另外,如果有更好的方法来完成这个任务,我也愿意听取建议。