use of edu.iu.dsc.tws.api.tset.link.TLink in project twister2 by DSC-SPIDAL.
the class TBaseGraph method conditionalBFS.
/**
* Same case as above this but can handle multiple roots
*
* @return build seq
*/
private Set<TBase> conditionalBFS(Collection<? extends BuildableTSet> roots, AdjNodesExtractor adjNodesExtractor) {
Set<TBase> buildSequence = new LinkedHashSet<>();
Set<TBase> visited = new HashSet<>();
Deque<TBase> queue = new LinkedList<>();
for (TBase root : roots) {
visited.add(root);
queue.add(root);
while (queue.size() != 0) {
TBase t = queue.poll();
for (TBase adj : adjNodesExtractor.extract(t)) {
if (!visited.contains(adj)) {
visited.add(adj);
queue.add(adj);
}
}
if (t instanceof TLink && !allAdjNodesTraversed((TLink) t, buildSequence, adjNodesExtractor)) {
queue.add(t);
continue;
} else if (t instanceof BatchRowTLink && !allAdjNodesTraversed((BatchRowTLink) t, buildSequence, adjNodesExtractor)) {
queue.add(t);
continue;
}
buildSequence.add(t);
}
}
return buildSequence;
}
Aggregations