package algorithm;
import java.util.HashSet;
import models.*;
import models.dataFlowModel.*;
public class DataStorageDecision {
static private HashSet<Node> arrivedNode = new HashSet<>();
static public void run(ResourceDependencyGraph graph) {
for (Node n : graph.getNodes()) {
ResourceNode resource = (ResourceNode) n;
trackNode(resource);
}
}
static private void trackNode(ResourceNode resource) {
if (arrivedNode.contains(resource))
return;
arrivedNode.add(resource);
boolean flag = false;
for (Edge e : resource.getInEdges()) {
if (((PushPullAttribute) e.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) {
trackNode((ResourceNode) e.getSource());
flag = true;
}
}
if (resource.getInEdges().size() == 0)
flag = true;
((StoreAttribute) resource.getAttribute()).setStored(flag);
}
}