On Fri, Jan 29, 2016 at 10:27 AM, John Cowan <xxxxxx@mercury.ccil.org> wrote:
Alex Shinn scripsit:

> +1 to Daniel's suggestion for partial sorting.  I would rather make
> it a selection algorithm (top k elements unsorted), though.  It's
> easy enough to sort the result with ranged vector-sort!, and we could
> provide a utility for this if needed.

Indeed.  I don't know how to do this in n log n time or better, though.
Can you or someone explain it?

https://en.wikipedia.org/wiki/Selection_algorithm

It works roughly like quicksort but only recursing on the smaller side
and skipping the sort step, giving linear time.

I can provide a reference implementation if no one else wants to.

-- 
Alex