std.string and ranges
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Feb 11 18:10:10 PST 2009
Denis Koroskin wrote:
[about shuffling ranges]
> I'm with bearophile here. Not because his version is shorter, but because
> 1) some containers/ranges might not have a dup method
> 2) it is potentially faster because it may avoid unnecessary data
> copying (relevant for large arrays).
>
> That said, having both versions is preferred by me with names like
> shuffle and shuffledCopy.
> The same could be applied to sort - sortedCopy might be useful, too.
Oh, I understand now. Incidentally topNCopy exists already, and it
becomes a sortedCopy for n = input.length. But perhaps an explicit
function would drive the point home better.
About shuffleCopy, you and Leonardo are both right that it could be
significantly faster than copying and then shuffling the copy. The
solution that I see most in the spirit of the new range design is to
have a ShuffledRange that, given another range, iterates it in a random
manner. An ordinary copy() call closes the deal if a copy is needed.
Thanks,
Andrei
More information about the Digitalmars-d
mailing list