Need a collection of unique elements (like C++ std::set).
Brad Anderson
eco at gnuk.net
Wed Jan 1 14:02:09 PST 2014
On Wednesday, 1 January 2014 at 21:54:13 UTC, Cooler wrote:
> Example in C++:
> set<int> uniqueInts;
> assert(uniqueInts.count(99) == 0);
> uniqueInts.insert(99);
> assert(uniqueInts.count(99) == 1);
> uniqueInts.erase(99);
> assert(uniqueInts.count(99) == 0);
>
> Which it will be analogue solution in D?
>
> I need a collection that can hold number of items, and can tell
> me weather is an item in the collection or not. I found that
> RedBlackTree can help me. But RedBlackTree uses O(log(n)) time
> for insert/remove operations. On the other hand we have
> built-in associative arrays with hashed keys. But associative
> arrays requires pairs of (key, value), which is quite wasting
> in my case.
> May be it will be convenient to allow void[key] built-in
> collections?
> Any suggestion?
C++'s std::set is actually almost always implemented as a
red-black tree so it's pretty much the exact same thing as D's
RedBlackTree.
void[key] is a commonly requested feature but so far no one has
implemented it. In C++ the equivalent would be
std::unordered_set.
More information about the Digitalmars-d
mailing list