Skip to content

Commit

Permalink
Implementation of bfs_nodes now uses bfs_edges
Browse files Browse the repository at this point in the history
  • Loading branch information
BenWeber42 committed Jun 18, 2024
1 parent e17c931 commit 815028f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions dace/sdfg/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def sink_nodes(self) -> List[NodeT]:
"""Returns nodes with no outgoing edges."""
return [n for n in self.nodes() if self.out_degree(n) == 0]

def bfs_nodes(self, source: NodeT = None) -> Sequence[NodeT]:
def bfs_nodes(self, source: NodeT = None) -> Iterable[NodeT]:
"""Returns nodes in topological order iff the graph contains exactly
one node with no incoming edges."""
if source is not None:
Expand All @@ -375,17 +375,9 @@ def bfs_nodes(self, source: NodeT = None) -> Sequence[NodeT]:
sources = [self.nodes()[0]]
if len(sources) > 1:
sources = [self.nodes()[0]]
seen = OrderedDict() # No OrderedSet in Python
queue = deque(sources)
while len(queue) > 0:
node = queue.popleft()
seen[node] = None
for e in self.out_edges(node):
succ = e.dst
if succ not in seen:
seen[succ] = None
queue.append(succ)
return seen.keys()

for edge in self.bfs_edges(sources):
yield edge.src

def all_simple_paths(self,
source_node: NodeT,
Expand Down

0 comments on commit 815028f

Please sign in to comment.