Comments about Set<T> implementation

Feb 22, 2008 at 2:10 AM
Hi there,

I have some observations about the Set<T> class. First, a Set<T> wraps some other CollectionBase<T>, which it takes as a constructor parameter. Since there is no guarantee that the wrapped collection is a set of unique entities (it may be populated with several duplicates), then there is no guarantee that any Set<T> is actually a unique set. However, since Set<T> already implements CollectionBase<T>, I don't see why it's necessary to wrap another collection at all. Since all of the collection manipulation methods (Add, Remove, etc.) operate directly on the wrapped set, then why not simply have Set<T> extend a fully-functional collection type (e.g. a BinarySearchTree<T> with an IComparer<T> implementation that compares hashcodes) and override the Add method to include a uniqueness check?

Cheers,
Mike
Coordinator
Feb 22, 2008 at 12:07 PM
I'll look into it

Thanks,

Granville


mstrobel wrote:
Hi there,

I have some observations about the Set<T> class. First, a Set<T> wraps some other CollectionBase<T>, which it takes as a constructor parameter. Since there is no guarantee that the wrapped collection is a set of unique entities (it may be populated with several duplicates), then there is no guarantee that any Set<T> is actually a unique set. However, since Set<T> already implements CollectionBase<T>, I don't see why it's necessary to wrap another collection at all. Since all of the collection manipulation methods (Add, Remove, etc.) operate directly on the wrapped set, then why not simply have Set<T> extend a fully-functional collection type (e.g. a BinarySearchTree<T> with an IComparer<T> implementation that compares hashcodes) and override the Add method to include a uniqueness check?

Cheers,
Mike