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.)
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community. Many versions of UNIX-based operating systems are written in C.
-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A.
You could use an HashSet
The
HashSet<T>
class provides high performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.
The capacity of a HashSet<T>
object is the number of elements that the object can hold. A HashSet<T>
object's capacity automatically increases as elements are added to the object.
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:
class Set<T> : SortedDictionary<T, bool>
{
public void Add(T item)
{
this.Add(item, true);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With