Several weeks ago, I tried hard to search an implement of balance binary tree in C#, what i needed was something like std::set<key, comparator> in C++: the data should be sorted, can be inserted and deleted at low cost and provides iterator which can move forward and backward. It looks like this can be easily achieved by List<T> with List<T>.Sort and List<T>.BinarySearch, the problem is that the performance of List<T> is not acceptable when the data collection size is big in my case.
I failed to find anything that can be used directly, it is hard to believe, a lot of implement of red-black tree in Java or C++ can be easily got from internet (although none of them meets my requirement), but none in C#.
So I had to implement one, it was translated from a C++ implement and modified to provide an immutable node.
1 RBTree<int> rbt = new RBTree<int>(Comparer<int>.Default);
8 RBNode<int> node6 = rbt.GetNode(6);
11 RBNode<int> node = rbt.GetNode(3);
12 node = node.Prev;
13 while (null != node)
16 node = node.Next;