Simplest way to convert an array into a set
Steven Schveighoffer
schveiguy at gmail.com
Mon Feb 13 18:23:31 UTC 2023
On 2/13/23 1:04 PM, Matt wrote:
> Obviously, there is no "set" object in D, but I was wondering what the
> quickest way to remove duplicates from an array would be. I was
> convinced I'd seen a "unique" method somewhere, but I've looked through
> the documentation for std.array, std.algorithm AND std.range, and I've
> either missed it, or my memory is playing tricks on me. That, or I'm
> looking in the wrong place entirely, of course
If you sort, you can use the `std.algorithm.iteration.uniq` function to
get that information. I don't believe there's a specific method to
remove duplicates in place.
Also, although there isn't a set type, you can use `bool[T]` as a crude
set type.
-Steve
More information about the Digitalmars-d-learn
mailing list