什么是stl集合的C#等价物? [英] What is the C# equivalent of the stl set?
问题描述
我可以使用什么通用集合? (我不想存储键/值对...只是值。)
-
如果您需要排序集,请使用
SortedDictionary< T,U>
。这是使用二叉搜索树来实现的。诚然,您将使用64位每个条目,因为您正在存储一个键值对。你可以这样写一个包装:class Set< T> :SortedDictionary< T,bool>
{
public void Add(T item)
{
this.Add(item,true);
}
}
-
如果您不需要排序设置,请使用
HashSet< T>
。 -
否则,请查看 C5通用收藏库。特别是
TreeSet< T> ;
。它是一个红黑树,仅存储值。
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: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.
这篇关于什么是stl集合的C#等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!