I want to store some values in a balanced binary search tree using C#. I looked through the collections in the generics namespace and I haven’t found an equivalent of the stl set.
What generic collection can I use? (I don’t want to store key/value pairs… just values.)
If you require sorted set, use
SortedDictionary<T,U>. This is implemented using a binary search tree. Admittedly, you will be using 64-bits per entry because you are storing a key-value pair underneath. You can write a wrapper around it like this:If you don’t require a sorted set, use
HashSet<T>.Otherwise, check out C5 Generic Collection Library. In particular
TreeSet<T>. It is a red-black tree and only stores the values.