I'm looking to speed up a piece of code that merges two SortedLists
.
C# 4.0 generic SortedList
: http://msdn.microsoft.com/en-us/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);
}
I'm thinking that a union instead of the foreach
loop would be faster but I don't know how to implement a union on a SortedList
. If someone could help me out with that I would appreciate it.
Also, if there is a better way of doing this overall I'm open to suggestions.