BinaryHeap is a range so it goes in std.range. Agree?

jlquinn jlquinn at optonline.net
Tue Jun 8 10:29:29 PDT 2010


Steven Schveighoffer Wrote:
> >> You might say the same about
> >> an array, but an array is special in that if I append to one array, it
> >> does not affect the other.
> >>
> >> I don't know where it belongs. To me, a range is a type that in itself
> >> cannot affect the topology of the data structure. It's like a window
> >> into the data structure that provides a common interface. A container is
> >> the owner of the data structure, and can provide ranges over its data.
> >> This may be an inadequate view, but its worked for me so far.
> >
> > Actually if a heap is built on top of a container, it can affect its  
> > topology because it has the sensible primitive of adding to the heap.
> 
> Yes, that is my point of why at least growable heaps should not be  
> considered ranges.

I second this point.  In STL parlance, BinaryHeap would be a container adapter.  Also, to me a range feels morally equivalent to an iterator and binary heap feels like a data structure that you can iterate over.  And the fact that you can insert objects into it and later remove them in a manipulated order makes it feel even more like an active component and thus a container.

So I'd naturally go looking for it in std.container and be a little confused to find it in std.range.  It would become a quirk that one adjusts to.

Jerry




More information about the Digitalmars-d mailing list