X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=cyclegraph.cc;h=750086c5c1c37fa63ab18072a5a2a7d94b504879;hp=c1fea4f3d0a96f14de433b6aac8b61e6f6479131;hb=9209688c955f7924af15da0c79c70948eb481b8c;hpb=f3ef22bef8d339c7d45b7d7232cdcf183a0b7776 diff --git a/cyclegraph.cc b/cyclegraph.cc index c1fea4f3..750086c5 100644 --- a/cyclegraph.cc +++ b/cyclegraph.cc @@ -1,9 +1,14 @@ #include "cyclegraph.h" +#include "action.h" + +/** Initializes a CycleGraph object. */ CycleGraph::CycleGraph() { hasCycles=false; } +/** Returns the CycleNode for a given ModelAction. */ + CycleNode * CycleGraph::getNode(ModelAction * action) { CycleNode *node=actionToNode.get(action); if (node==NULL) { @@ -13,6 +18,8 @@ CycleNode * CycleGraph::getNode(ModelAction * action) { return node; } +/** Adds an edge between two ModelActions. */ + void CycleGraph::addEdge(ModelAction *from, ModelAction *to) { CycleNode *fromnode=getNode(from); CycleNode *tonode=getNode(to); @@ -23,18 +30,20 @@ void CycleGraph::addEdge(ModelAction *from, ModelAction *to) { fromnode->addEdge(tonode); } +/** Checks whether the first CycleNode can reach the second one. */ + bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { - std::vector queue; - HashTable discovered; - + std::vector queue; + HashTable discovered; + queue.push_back(from); discovered.put(from, from); while(!queue.empty()) { - class CycleNode * node=queue.back(); + CycleNode * node=queue.back(); queue.pop_back(); if (node==to) return true; - + for(unsigned int i=0;igetEdges()->size();i++) { CycleNode *next=(*node->getEdges())[i]; if (!discovered.contains(next)) { @@ -46,14 +55,25 @@ bool CycleGraph::checkReachable(CycleNode *from, CycleNode *to) { return false; } +/** Returns whether a CycleGraph contains cycles. */ +bool checkForCycles() { + return hasCycles; +} + +/** Constructor for a CycleNode. */ + CycleNode::CycleNode(ModelAction *modelaction) { action=modelaction; } -std::vector * CycleNode::getEdges() { +/** Returns a vector of the edges from a CycleNode. */ + +std::vector * CycleNode::getEdges() { return &edges; } +/** Adds an edge to a CycleNode. */ + void CycleNode::addEdge(CycleNode * node) { edges.push_back(node); }