topN using a heap
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 17 14:20:30 PST 2016
On 01/17/2016 03:32 PM, Ivan Kazmenko wrote:
> Here is a more verbose version.
OK, very nice. Thanks! I've modified topN to work as follows. In a loop:
* If nth <= r.length / log2(r.length)^^2 (or is similarly close to
r.length), use topNHeap with one heap and stop
* If nth <= r.length / log2(r.length) (or is similarly close to
r.length), use topNHeap with two heaps and stop
* Take a quickselect step, adjust r and nth, and continue
That seems to work nicely for all values involved.
All - let me know how things can be further improved. Thx!
Andrei
More information about the Digitalmars-d
mailing list