Node*
module にある s のヒープに対して次のコードを作成しましたnode
。
import std.exception, std.container;
public import node;
alias NodeArray = Array!(const (Node)*);
alias NodeHeap = BinaryHeap!(NodeArray, cmp_node_ptr);
auto make_heap() {
return new NodeHeap(NodeArray(cast(const(Node)*)[]));
}
void insert(NodeHeap* heap, in Node* u) {
enforce(heap && u);
heap.insert(u);
}
pure bool cmp_node_ptr(in Node* a, in Node* b) {
enforce(a && b);
return (a.val > b.val);
}
次に、次の単体テストを実行してみました。ここでは、指定された引数で初期化されたをmake_leaf
返します。Node*
unittest {
auto u = make_leaf(10);
auto heap = make_heap();
insert(heap, u); //bad things happen here
assert(heap.front == u);
auto v = make_leaf(20);
insert(heap, v);
assert(heap.front == u); //assures heap property
}
テストは、コメント マークを付けた行に到達し、その行enforce(a && b)
で強制エラーをスローしcmp_node_ptr
ます。なぜこれが起こっているのか、私は完全に迷っています。