Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't .Net have a Set data structure?

One of my biggest issues dealing with a move from Java to .Net is the fact that there isn't a Set interface in .Net. I know there are libraries I could go and download but what is the reason for not having it built in? There are Maps (Dictionary) and Lists but why not a Set?

Edit: I should clarify that not everyone uses .Net 3.5 yet -- so I'm more or less referring to older versions of .Net

like image 673
Joe Phillips Avatar asked Sep 16 '09 15:09

Joe Phillips


People also ask

What is set data structure?

A set is a data structure that stores unique elements of the same type in a sorted order. Each value is a key, which means that we access each value using the value itself. With arrays, on the other hand, we access each value by its position in the container (the index). Accordingly, each value in a set must be unique.

Does C# have a tree class?

In the C# language a tree can be implemented with classes (nodes) that point to further nodes. In this simple implementation, we use a Dictionary. AddWord This method takes a string argument and adds it to the tree by creating (or using existing) nodes (one per character).

Do sets exist in Golang?

Although Go doesn't have sets natively, we can make use of maps to act the same way. We were able to execute all operations that are characteristic of a set, with the same time complexity of O(1) for adding and removing members from a set.


3 Answers

I think it's simply an omission by the BCL writers. .NET 3.5 has a HashSet class; for earlier versions, I recommend wrapping a Dictionary<T, object>, with nulls in the value field, to replicate O(1) add, remove and lookup time.

like image 57
thecoop Avatar answered Oct 19 '22 05:10

thecoop


In .NET 4.0 HashSet will be retrofitted to even implement new ISet interface.

like image 5
alex Avatar answered Oct 19 '22 04:10

alex


.NET 3.5 has HashSet which does all set operations.

like image 4
Akash Kava Avatar answered Oct 19 '22 04:10

Akash Kava