[Issue 17094] std.container.binaryheap doesn't manage store length consistently when inserting

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 29 23:33:42 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=17094

--- Comment #4 from Jon Degenhardt <jrdemail2000-dlang at yahoo.com> ---
A bit of a follow-up to the last pair of comments: The discussion of whether
size was reserved, the implied notions of reference vs value semantics, etc.,
is in my view an incorrect focus. The key issue involved is this paragraph in
the documentation:

    Simply extracting elements from a $(D BinaryHeap) container is
    tantamount to lazily fetching elements of $(D Store) in descending
    order. Extracting elements from the $(D BinaryHeap) to completion
    leaves the underlying store sorted in ascending order but, again,
    yields elements in descending order.

The second sentence is the key issue - A key use case of a binary heap is to
take a top-n set of items, then generate the top-n order by extracting as
described. This is what fails, and why this is a bug. The documentation
indicates binary heap supports this, as it should. If there are cases where it
does not support it, it should be clear about this. But really, this use case
should be supported.

--


More information about the Digitalmars-d-bugs mailing list