Most places I've consulted say to use SortedList, but the problem is that the program I'm porting actually uses duplicate keys (differentiated by order), which is permissible with TreeMap, but not SortedList.
Any advice?
Most places I've consulted say to use SortedList, but the problem is that the program I'm porting actually uses duplicate keys (differentiated by order), which is permissible with TreeMap, but not SortedList.
Any advice?
Does SortedDictionary class help?
SortedDictionary<of TKey, of TValue>.Item[TKey]
property setter, it replaces value if the key is already in a tree. –
Paedogenesis Another great implementation of a Red Black Tree in .NET can be found here: http://www.itu.dk/research/c5/
I don't think C# has one natively. However there are plenty of examples of Red-Black implementations out there. Here is one:-
Generally use the sorted set
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());
© 2022 - 2025 — McMap. All rights reserved.