std.algorithm.BinaryHeap

bearophile bearophileHUGS at lycos.com
Mon Apr 27 10:11:48 PDT 2009


Andrei Alexandrescu:
> These topology choices are used with SListRange (independent, growable 
> singly-linked list vs. a range looking at a different singly-linked 
> list). If the notion of topology turns out to be a good design, today's 
> BinaryHeap is Topology.fixed, whereas a BinaryHeap that is 
> Topology.flexible can grow no problem.

Do you mean that an heap that allows pop() to remove items is Topology.fixed?? Is extending a dynamic array a change in its topology?

I think you are over-generalizing a bit here. 99% of the times I just need a heap to push and pop items from it (eventually even many at the same time), and I don't care much of its internal implementation (that may be a dynamic array of pointers to large blocks of items, like a Deque, but with internal blocks not necessarily fully filled of items). Using a linked list to implement a binary heap doesn't sound like much efficient). So I suggest to use a simpler API, that takes a range, builds some internal representation, and allows me to push and pop items... Your design is more efficient (no copying data, for example) but its API is more hairy. Most people most of the time don't want to mess with such details.

>From what you say I guess there is currently no way to add items to an heap.

Bye,
bearophile



More information about the Digitalmars-d mailing list