SortedSet wrapper for .net 3.5
Here is a VERY basic SortedSet wrapper for .NET 3.5
The SortedSet is one of the few new features of the .NET Framework 4.0 that I hate to go without. I recently had to drop a Class Library from 4.0 to 3.5, and the SortedSet was the only thing missing. So, I just created my own SortedSet
Here is my implementation – if you need any of the really fancy features, you will need to implement them yourself.
public class SortedSet<T> : SortedList<T,byte>
{
public SortedSet() : base()
{
}
public T Min
{
get
{
if ((base.Count) >= 1)
{
return base.Keys[0];
}
else
{
return default(T);
}
}
}
public T Max
{
get
{
if ((base.Count) >= 1)
{
return base.Keys[base.Keys.Count - 1];
}
else
{
return default(T);
}
}
}
public bool Contains(T value)
{
return base.ContainsKey(value);
}
public void Add(T value)
{
base.Add(value, 0);
}
}

Actually that’s definitely different from the .net 4 SortedSet.
1 – SortedSet is implemented as Red-Black tree
i.e. insert, delete, search are O(log(n)), indexing is O(n)
SortedList is a binary tree
i.e. worst-case performance: insert, delete are O(n), search and indexing is O(n)
(all are worst-case complexities)
To be more similar, you should use SortedDictionary that is implemented as Red-black tree
2 – null can be added to SortedSet, while cannot be used as Key in the SortedList