Skip to content
Snippets Groups Projects
Commit 648bc91c authored by Jacob Wahlman's avatar Jacob Wahlman :ok_hand:
Browse files

changed docstring and changed to set in BFS

parent 740e51da
No related branches found
No related tags found
1 merge request!7Resolve "Operation Traversing"
Pipeline #10184 passed
This commit is part of merge request !7. Comments created here will be created in the context of that merge request.
...@@ -4,7 +4,7 @@ TODO: More info. ...@@ -4,7 +4,7 @@ TODO: More info.
""" """
from abc import abstractmethod from abc import abstractmethod
from typing import List, Dict, Optional, Any from typing import List, Set, Dict, Optional, Any
from numbers import Number from numbers import Number
from b_asic.port import InputPort, OutputPort from b_asic.port import InputPort, OutputPort
...@@ -107,14 +107,8 @@ class AbstractOperation(Operation, AbstractGraphComponent): ...@@ -107,14 +107,8 @@ class AbstractOperation(Operation, AbstractGraphComponent):
return neighbours return neighbours
def traverse(self) -> List[Operation]: def traverse(self) -> Set[Operation]:
"""Traverse the the operation tree and return operation where type matches. """Traverse the operation tree and return a generator with start point in the operation."""
If the type is None then return the entire tree.
Keyword arguments:
type_ -- the operation type to search for (default None)
"""
return breadth_first_search(self) return breadth_first_search(self)
# TODO: More stuff. # TODO: More stuff.
...@@ -3,19 +3,19 @@ B-ASIC Operation Module. ...@@ -3,19 +3,19 @@ B-ASIC Operation Module.
TODO: More info. TODO: More info.
""" """
from typing import List from typing import Set
from collections import deque from collections import deque
from b_asic.operation import Operation from b_asic.operation import Operation
def breadth_first_search(start: Operation) -> List[Operation]: def breadth_first_search(start: Operation) -> Operation:
"""Use breadth first search to traverse the operation tree.""" """Use breadth first search to traverse the operation tree."""
visited: List[Operation] = [start] visited: Set[Operation] = {start}
queue = deque([start]) queue = deque([start])
while queue: while queue:
operation = queue.popleft() operation = queue.popleft()
yield operation yield operation
for n_operation in operation.neighbours: for n_operation in operation.neighbours:
if n_operation not in visited: if n_operation not in visited:
visited.append(n_operation) visited.add(n_operation)
queue.append(n_operation) queue.append(n_operation)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment