Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Quickie Collection question

Started by Telastyn Mar 13, 2009 at 11:02 AM 3 replies 1.5k views
Original Post
Telastyn
Telastyn
Data structures are not my strong suit. I am looking for a collection that will do this general pattern better than List:

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?
Bob Janova
Bob Janova
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).
Bob Janova
Bob Janova
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 and setting the value to something (anything :p) would also do the trick but it will clearly be a bit inefficient.
Telastyn
Telastyn
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.