www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BinaryHeap crashes upon insertion if heapified with an array of length

reply TheGag96 <thegag96 gmail.com> writes:
I'm trying to use a binary heap initialized with one element. 
However, this always seems to cause a range violation for some 
reason. This small example will do it:

import std.stdio, std.container;

void main() {
   auto pq = heapify([5]);
   pq.insert(8);
}

...And it produces this error: https://pastebin.com/dyLNRz2W

Oddly enough, if I heapify an array with any other length than 1, 
I can insert as much as I want (that includes an empty array!). 
Is this a bug in Phobos or some odd expected behavior? Thanks 
guys!
Apr 08
parent reply Michael Coulombe <kirsybuu gmail.com> writes:
On Sunday, 9 April 2017 at 00:36:00 UTC, TheGag96 wrote:
 I'm trying to use a binary heap initialized with one element. 
 However, this always seems to cause a range violation for some 
 reason. This small example will do it:

 import std.stdio, std.container;

 void main() {
   auto pq = heapify([5]);
   pq.insert(8);
 }

 ...And it produces this error: https://pastebin.com/dyLNRz2W

 Oddly enough, if I heapify an array with any other length than 
 1, I can insert as much as I want (that includes an empty 
 array!). Is this a bug in Phobos or some odd expected behavior? 
 Thanks guys!
This is a bug in the insert method. I created a bug report for you and submitted a pull request for a fix: https://issues.dlang.org/show_bug.cgi?id=17314
Apr 09
parent TheGag96 <thegag96 gmail.com> writes:
On Sunday, 9 April 2017 at 13:31:05 UTC, Michael Coulombe wrote:
 This is a bug in the insert method. I created a bug report for 
 you and submitted a pull request for a fix:

 https://issues.dlang.org/show_bug.cgi?id=17314
Ah, so it is. Thanks!!
Apr 10