From: weiyu Date: Tue, 8 Oct 2019 20:28:49 +0000 (-0700) Subject: BFS with distance was not implemented correctly X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=477eca0fc4117c867d55b5391986b5de49df5c6a;p=c11tester.git BFS with distance was not implemented correctly --- diff --git a/funcnode.cc b/funcnode.cc index a3407b44..5333bce7 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -648,31 +648,35 @@ int FuncNode::compute_distance(FuncNode * target, int max_step) { if (target == NULL) return -1; + else if (target == this) + return 0; SnapList queue; - HashTable distances; + HashTable distances(128); - int dist = 0; queue.push_back(this); - distances.put(this, dist); + distances.put(this, 0); while (!queue.empty()) { FuncNode * curr = queue.front(); queue.pop_front(); + int dist = distances.get(curr); - if (max_step < dist) + if (max_step <= dist) return -1; - else if (curr == target) - return dist; - dist++; ModelList * outEdges = curr->get_out_edges(); mllnode * it; for (it = outEdges->begin(); it != NULL; it = it->getNext()) { FuncNode * out_node = it->getVal(); + + /* This node has not been visited before */ if ( !distances.contains(out_node) ) { + if (out_node == target) + return dist + 1; + queue.push_back(out_node); - distances.put(out_node, dist); + distances.put(out_node, dist + 1); } } }