What is the C # equivalent for a set of stl?

I want to store some values ​​in a balanced binary search tree using C #. I looked at collections in the generics namespace and I did not find the equivalent of the stl set.

What universal collection can I use? (I don't want to store key / value pairs ... just values.)

+3
source share
4 answers
  • If you need a sorted set, use SortedDictionary<T,U>. This is implemented using a binary search tree. Admittedly, you will use a 64-bit record because you store a pair of key values ​​under it. You can write a wrapper around it like this:

    class Set<T> : SortedDictionary<T, bool>
    {
        public void Add(T item)
        {
            this.Add(item, true);
        }
    }
    
  • , HashSet<T>.

  • C5 Generic Collection Library. TreeSet<T>. - .

+7

HashSet

HashSet<T> . , , .

HashSet<T> - , . A HashSet<T> .

+14

RedBlackTree.NET. VB, , #.

, - . .

, HashSet. , :

HashSet - O (1) (n)
- O (log n) O (log n)

, HashSet.

+3

HashSet, but HashSet is not available in version 2.0 of the framework. If you need something for version 2.0, then use the dictionary and specify the type of the dummy type (for example, an object, int or bool), for which you will specify a dummy value (for example, null, 0 or false) as the second / value parameter ( i.e. use the Dictionary as a set of keys without worrying about related values).

+2
source

Source: https://habr.com/ru/post/1703652/


All Articles