Sign in to follow this  
Telastyn

[.net] Quickie Collection question

Recommended Posts

Data structures are not my strong suit. I am looking for a collection that will do this general pattern better than List<T>:
if( Collection.Contains( foo ) ){
    return;
}
Collection.Add( foo );

// process foo.
// recurse.

foo is some arbitrary reference type. Normally I'd go for some list wrapper over a balanced tree, but .NET sorted stuff seems to require pairs and seems not to want to just use the references (or some internal token) as the balance condition. Something in the standard lib I'm missing? Some well known non-standard lib I'm missing? Advise, questions?

Share this post


Link to post
Share on other sites
I don't have an answer but let me check I understand the question ... you want something which will permit one and only one instance of a particular object (I think this is a 'set' in mathematical terms).

Share this post


Link to post
Share on other sites
That looks like exactly the right thing but it is only in 3.5, which implies there is no Framework class for the job in 2.0.

Using a Hashtable<T,object> and setting the value to something (anything :p) would also do the trick but it will clearly be a bit inefficient.

Share this post


Link to post
Share on other sites
Yes, a set would be acceptable, though I don't necessarily need the behavior of a set. And I am constrained to 2.0 for now, but that looks good. [edit: though this 2.0 compatible lib provides a simple hashset and seems to work well]

Thank you gentlemen.

[Edited by - Telastyn on March 13, 2009 1:49:55 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this