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
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.
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).
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.
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.
In .NET 4.0 HashSet
will be retrofitted to even implement new ISet
interface.
.NET 3.5 has HashSet which does all set operations.
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