Lazy sort?

bearophile bearophileHUGS at lycos.com
Sun Oct 2 12:47:37 PDT 2011


Sometimes in my code I have to find the first few smaller (or bigger) items of an array, I don't know how many I will need, but I know in general I will need only few of them, much less than the whole array.

Turnign the array into an heap is slow if I need only few items, and I can't use std.algorithm.partialSort because I don't know how many items I will need.

So I have written this very simple LazySort range, based on partialSort (note: it is lazy in its output, but its input can't be lazy):
http://ideone.com/iEPO6

I have not done benchmarks on it yet.
Do you like it? Is something like it generally useful?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list