in .NET, two data structures are useful when you need data to be sorted:
- SortedList<TKey,TValue> insert, edit, remove, search are in O(N), and index lookup in O(1).
- SortedDictionary<TKey,TValue> insert, edit, remove, search are in O(lg(N)), and index lookup is not supported.
MCollections provided two collections with insert, edit, remove, search and index lookup In O(Lg(N)).
download using NuGet: MCollections
IndexedDictionary<string, int> dictionary = new IndexedDictionary<string, int>()
{
{ "Zero", 0 },
{ "One", 1 },
{ "Two", 2 },
};
int valueWithIndex2 = dictionary.GetByIndex(2); // 0
int someValue = dictionary["One"]; // 1
IndexedSet<string> set = new IndexedSet<string>();
set.Add("two");
set.Add("one");
set.Add("zero");
string first = set[0]; // "one"