大多数我咨询的地方都建议使用SortedList,但问题是我正在移植的程序实际上使用了重复的键(通过顺序区分),这在TreeMap中是允许的,但不适用于SortedList。
有什么建议吗?
大多数我咨询的地方都建议使用SortedList,但问题是我正在移植的程序实际上使用了重复的键(通过顺序区分),这在TreeMap中是允许的,但不适用于SortedList。
有什么建议吗?
我认为C#本身没有这个功能。不过,有很多红黑树实现的例子。这是其中一个:
通常使用排序集合
public class ItemComparer : IComparer<int[]>
{
public int Compare(int[] item1, int[] item2)
{
if (item1[0] != item2[0]) return item1[0].CompareTo(item2[0]);
return item1[1].CompareTo(item2[1]);
}
}
var s = new SortedSet<int[]>(new ItemComparer());
SortedDictionary<of TKey, of TValue>.Item[TKey]
属性设置器,如果键已经存在于树中,则替换其值。 - Leonid Vasilev