Jump to content
  • Advertisement
Sign in to follow this  

std::set equivalent in C# ?

This topic is 4347 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Or just a simple sorted container, I don’t want an associative container. I see SortedList and SortedDictionary are both associative. And I don’t see any other sorted containers.

Share this post


Link to post
Share on other sites
Advertisement
If you want a container that's sorted but not associative, use a List<T> and .Sort() as needed. If you want a container that's sorted, not associative, and won't allow duplicates, you need a Set. One example is here, and the corresponding generic extensions (by a different author) are here.

hope that helps,

Share this post


Link to post
Share on other sites
Quote:
Original post by NotAYakk
Can't you just map your key to a null or empty type?


Given that SortedList sorts the keys, and not the values, I guess not.

Share this post


Link to post
Share on other sites
A map "maps" the key to a value.

If the key maps to a null or empty type, then the values are empty types, and the keys are non-null.

Share this post


Link to post
Share on other sites
This may be a silly suggestions but...

Couldn't you just use the object itself as both the key AND the value? That would also effectively give you a set.

Share this post


Link to post
Share on other sites
I'm still not sure that he really wants a set (in the mathematical sense), since sets aren't ordered. Taken in context, there is no such thing as "the fourth element of a set", for instance.

Share this post


Link to post
Share on other sites
Quote:
Original post by kSquared
If you want a container that's sorted but not associative, use a List<T> and .Sort() as needed. If you want a container that's sorted, not associative, and won't allow duplicates, you need a Set. One example is here, and the corresponding generic extensions (by a different author) are here.



hope that helps,

I’ll check out both of those, however how stable/reliable are they?
Quote:
Original post by smitty1276
This may be a silly suggestions but...

Couldn't you just use the object itself as both the key AND the value? That would also effectively give you a set.

Ok is this a good solution? Sounds like a waste of memory.


Quote:
Original post by kSquared
I'm still not sure that he really wants a set (in the mathematical sense), since sets aren't ordered. Taken in context, there is no such thing as "the fourth element of a set", for instance.
What I want specifically is a container that guarantees O(log n) and doesn’t allow duplicates, and that isn’t associative.

Why isn’t this in the .Net library?
I swear for all the raving I hear about how wonderful and easy to use C# and .Net are... They have given me nothing but headaches.

Share this post


Link to post
Share on other sites
O(log n) what? Sorting, searching, insertion, deletion? An array is O(1) lookup but O(n) inserting, for instance. You need to be more specific. You're right that a "set" in the mathematical sense does not exist in the .NET framework, though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!