Heap: container or range?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jan 30 06:17:53 PST 2009


Sean Kelly wrote:
> I don't know if it matters, but I added the heap routines to Tango 
> because I wanted heapsort, so they kind of came for free.  Perhaps a key 
> distinction between ranges and algorithms is that algorithms may mutate 
> the underlying data, but ranges may not?  I've been trying to think of 
> another example of a mutating range and I haven't come up with one 
> yet... unless you consider input ranges mutating, I suppose.

A great use for heaps is topNCopy: given an input range (!), give me 
back the top N items in it, fast. The way that works is by maintaining a 
heap in the return value.

I'm sure interesting cases will arise with ranges that mutate their 
host, but heap doesn't look like a good candidate.


Andrei



More information about the Digitalmars-d mailing list