Is there a function for this?
Adam D. Ruppe
destructionator at gmail.com
Sat Oct 6 13:34:44 UTC 2018
On Saturday, 6 October 2018 at 13:17:22 UTC, bauss wrote:
> My first thought was "uniq", but it can't really do it like
> that, but it doesn't work.
uniq needs it to be sorted first, it only compares side-by-side
(to avoid allocating space to remember what it has already seen)
> Is there another function in Phobos that perhaps would work?
If the set is small enough and it is at least a forward range,
you could do a O(n^2) search with like filter with !canFind
(making sure the one it finds is not the one you are currently
looking at).
But I think you are better off doing your own thing. I like to
just stick them all in an associative array, then loop over that.
The duplicate keys will naturally be filtered that way.
Of course, it allocates memory for that but that's often
preferable to running the expensive search anyway.
More information about the Digitalmars-d-learn
mailing list