1

I have a tree-like structure using Node objects with references to other Node objects. Node is a class. Now, one of the routines I'm writing needs a minimum priority queue, which I'm implementing using std.container.BinaryHeap and std.container.Array. I'm instantiating it as follows:

Node[] r;
auto heap = BinaryHeap!(Array!(Node), "a > b")(Array!Node(r));

As part of the routine, I insert elements into heap using insert and remove elements from it using removeAny. Now, the routine works correctly, but afterwards, the tree-like structure breaks (my invariants for it fail), due to nodes being missing. What's going on here and why is this happening?

4
  • Is Node a clas or struct? Commented Mar 25, 2014 at 1:53
  • It's a class. I've edited my original post to make this clear.
    – Koz Ross
    Commented Mar 25, 2014 at 2:07
  • can you post a minimal sequence of calls that reproduces the behavior? Commented Mar 25, 2014 at 11:00
  • As per request, here is a minimal sequence of calls that reproduces this behaviour. This clearly shows nodes are missing from the structure: gist.github.com/mrsinister13/9821806
    – Koz Ross
    Commented Mar 27, 2014 at 23:50

1 Answer 1

1

could be http://d.puremagic.com/issues/show_bug.cgi?id=6998 - std.container.Array destroys class instances

2
  • This was reported in 2011-12 and still hasn't been addressed? That's a bit of a worry - I suspected that was the problem. Short of brute copying, is there any way around this? I'm using Array for BinaryHeap and no other reason, so is there a way I can avoid it?
    – Koz Ross
    Commented Mar 29, 2014 at 4:02
  • For anyone who is watching - it appears the issue was fixed about 14 days ago.
    – Koz Ross
    Commented Apr 26, 2014 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.