Skip to content
Snippets Groups Projects
utilities.py 604 B
Newer Older
  • Learn to ignore specific revisions
  • """@package docstring
    B-ASIC Operation Module.
    TODO: More info.
    """
    
    from typing import Set
    from collections import deque
    
    from b_asic.operation import Operation
    
    def breadth_first_search(start: Operation) -> Operation:
        """Use breadth first search to traverse the operation tree."""
        visited: Set[Operation] = {start}
        queue = deque([start])
        while queue:
            operation = queue.popleft()
            yield operation
            for n_operation in operation.neighbours:
                if n_operation not in visited:
                    visited.add(n_operation)
                    queue.append(n_operation)