std::set equivalent in C# ?
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.
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,
hope that helps,
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.
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.
If the key maps to a null or empty type, then the values are empty types, and the keys are non-null.
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.
Couldn't you just use the object itself as both the key AND the value? That would also effectively give you a set.
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.
True, but when speaking of containers, doesn't "set" generally just mean that no element may be present more than one time?
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 kSquaredWhat I want specifically is a container that guarantees O(log n) and doesn’t allow duplicates, and that isn’t associative.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement