fix issue 16072 - container.binaryheap should be extendable for arrays#4359
fix issue 16072 - container.binaryheap should be extendable for arrays#4359andralex merged 1 commit intodlang:masterfrom
Conversation
|
|
Can you add a unittest? Otherwise, LGTM. |
|
Maybe |
Done. Also added a check + fix for the case of a zero-length arrays.
Afaict is See also: http://dlang.org/phobos-prerelease/std_container.html |
I don't see how they would interfere. Arrays already support a bunch of the container primitives. Adding the rest seems more natural to me than special casing functions that work on containers. |
I actually asked the same question before and IIRC it was about guareenting runtime based on the name (?). Ping @schveiguy |
|
@wilzbach I have no experience with binary heap, so I don't really have any opinion on it. |
I thought the container API is similiar between all storages. Sorry.
See #4038 - ping @JackStouffer |
|
What if store is a slice of an array? |
You mean a dynamic array? Should work. |
|
I guess I misunderstood how _store worked. |
| } | ||
| else | ||
| { | ||
| // can't grow |
There was a problem hiding this comment.
This change would be cleaner if it was written in the following way
else static if (isDynamicArray!Store)
{
if (_store.length == 0)
_store.length = 10;
if (length == _store.length)
_store.length = length * 2;
_store[_length] = value;
}
else
{
// can't grow
enforce(length < _store.length,
"Cannot grow a heap created over a range");
}
There was a problem hiding this comment.
I didn't know the reason for setting the element after an exception was thrown, so I didn't change the code, but thanks for the heads-up -> changed :)
|
OK, interesting... wonder what the consequences of this precedent will be :) |
What consequences do you expect? I think the other containers support insertions ;-) (rebased) |
|
@andralex So is this PR a go or no-go? |
I would interpret the "OK, interesting" as an approval, but maybe other diviner are better in interpreting (?) |
|
@quickfur I see Andrei's comment as consent I think this PR is ready to go |
|
Auto-merge toggled on |
While trying to create an top-level unittest for this module (#4331), I realized that with an array as storage, it's not possible to insert new items, which seems like a bug.
Here's the fix ;-)