On 10-Jul-12 16:50, Nick Treleaven wrote:
On 10/07/2012 12:37, Jacob Carlborg wrote:
The corresponding D version would be:

auto a = [5, 3, 5, 6, 8].uniq.map!(x => x.to!(string)).array.sort.array;
writeln(a);

I'm guessing that's three allocations. But that doesn't even work, it
prints:

["3", "5", "5", "6", "8"]

uniq needs sorted input:

auto r = [5, 3, 5, 6, 8].sort.uniq.map!(x => x.to!string);
writeln(r);

Tested with dmd 2.059.
I think the above should be one allocation (except for the strings).

Yup and that was my whole point.
You get fast and easy way with D
or just very easy way with any suitable scripting language.


Maybe uniq should require a SortedRange?


+1

And say so explicitly in the docs.


--
Dmitry Olshansky


Reply via email to