Is there a function for this?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Oct 6 20:53:04 UTC 2018


On Sat, Oct 06, 2018 at 08:07:42PM +0000, bauss via Digitalmars-d-learn wrote:
[...]
> The whole problem is actually that they do not work with ranges that
> aren't sorted. Things like .group and .uniq should work without sorted
> ranges. You can't always expect a range to be sorted to perform such
> algorithms.

The reason they don't work with ranges that aren't sorted is because the
algorithms that don't require sorted ranges are more expensive, or need
to allocate (non- at nogc), and are sometimes application-specific, meaning
that you're better off writing your own algorithm for it that takes
advantage of the specific knowledge you have about your data, rather
than some poorly-performing generic algorithm that can't possibly
optimize for every possible use case.

Not to mention, the expensiveness of such algorithms comes from having
to do work that basically amounts to sorting the data, so you might as
well sort them yourself in the first place.


T

-- 
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth


More information about the Digitalmars-d-learn mailing list