How to use sets in D?

Jan Hönig hrominium at gmail.com
Fri Feb 7 19:40:35 UTC 2020


On Friday, 7 February 2020 at 19:37:08 UTC, mark wrote:
> I am porting code from other languages to D as part of learning 
> D, and I find I've used sets quite a lot. AFAIK D doesn't have 
> a built-in set type or one in the std. lib.
>
> However, I've been perfectly successfully using int[E] where E 
> is my ElementType, and adding with set[element] = 0. I mostly 
> only need add, remove, iteration, and in, with uniqueness what 
> I care most about.
>
> I know I could use bool[E] and set[element] = false, or I 
> suppose container.rbtree. Would either of these--or something 
> else built-in or in the std. lib.--be better?

I have not that much experience, but i have asked the exact same 
thing in the IRC.
rbtree was recommended. However, if it is not performance 
critical (in terms of speed or size), your solution works fine as 
well.


More information about the Digitalmars-d-learn mailing list