X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=cyclegraph.cc;h=57f8fc8c42fe0033abbe83d14caa674feeedb1e7;hb=eb07120dfdbb206124f7857016a71b6ef0b9eb99;hp=00b8cd85731800fcdfb3593147d2bbd5bd84ace4;hpb=9904060b44ad97b7aa4327678dfc902f1d83bbd2;p=model-checker.git diff --git a/cyclegraph.cc b/cyclegraph.cc index 00b8cd8..57f8fc8 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -279,6 +279,18 @@ bool CycleGraph::checkForCycles() const */ CycleNode::CycleNode(const ModelAction *act) : action(act), + promise(NULL), + hasRMW(NULL) +{ +} + +/** + * @brief Constructor for a Promise CycleNode + * @param promise The Promise which was generated + */ +CycleNode::CycleNode(const Promise *promise) : + action(NULL), + promise(promise), hasRMW(NULL) { } @@ -308,6 +320,54 @@ unsigned int CycleNode::getNumBackEdges() const return back_edges.size(); } +/** + * @brief Remove an element from a vector + * @param v The vector + * @param n The element to remove + * @return True if the element was found; false otherwise + */ +template +static bool vector_remove_node(std::vector >& v, const T n) +{ + for (unsigned int i = 0; i < v.size(); i++) { + if (v[i] == n) { + v.erase(v.begin() + i); + return true; + } + } + return false; +} + +/** + * @brief Remove a (forward) edge from this CycleNode + * @return The CycleNode which was popped, if one exists; otherwise NULL + */ +CycleNode * CycleNode::removeEdge() +{ + if (edges.empty()) + return NULL; + + CycleNode *ret = edges.back(); + edges.pop_back(); + vector_remove_node(ret->back_edges, this); + return ret; +} + +/** + * @brief Remove a (back) edge from this CycleNode + * @return The CycleNode which was popped, if one exists; otherwise NULL + */ +CycleNode * CycleNode::removeBackEdge() +{ + if (back_edges.empty()) + return NULL; + + CycleNode *ret = back_edges.back(); + back_edges.pop_back(); + vector_remove_node(ret->edges, this); + return ret; +} + /** * Adds an edge from this CycleNode to another CycleNode. * @param node The node to which we add a directed edge