How to sort a range
Edwin van Leeuwen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 9 05:13:31 PST 2016
On Wednesday, 9 March 2016 at 13:04:31 UTC, rcorre wrote:
> On Wednesday, 9 March 2016 at 12:31:18 UTC, Edwin van Leeuwen
> wrote:
>> On Wednesday, 9 March 2016 at 12:21:55 UTC, rcorre wrote:
>>>> If you are looking for a lazy uniq that works on non sorted
>>>> ranges, I implemented one not to long ago:
>>>> http://github.com/BlackEdder/ggplotd/blob/master/source/ggplotd/range.d
>>>
>>> That sounds like the kind of thing I was looking for. I'll
>>> take a look, thanks!
>>
>> Well that one does allocate, because it keeps track of which
>> values have already been seen.
>
> Yup, just noticed that >.<
Of course it only allocates when the actual result is used, so
this will probably be more efficient if you only need a small
number of unique results or need to keep the unsorted range
around/intact. Sorting without allocating and then using uniq
should indeed be more efficient in other cases.
Did you try different SwapStrategy values in your original?
More information about the Digitalmars-d-learn
mailing list