MCPcopy Index your code
hub / github.com/clips/pattern / breadth_first_search

Function breadth_first_search

pattern/graph/__init__.py:708–720  ·  view source on GitHub ↗

Visits all the nodes connected to the given root node, breadth-first.

(node, visit=lambda node: False, traversable=lambda node, edge: True)

Source from the content-addressed store, hash-verified

706dfs = depth_first_search;
707
708def breadth_first_search(node, visit=lambda node: False, traversable=lambda node, edge: True):
709 """ Visits all the nodes connected to the given root node, breadth-first.
710 """
711 q = [node]
712 _visited = {}
713 while q:
714 node = q.pop(0)
715 if not node.id in _visited:
716 if visit(node):
717 return True
718 q.extend((n for n in node.links if traversable(node, node.links.edge(n)) is not False))
719 _visited[node.id] = True
720 return False
721
722bfs = breadth_first_search;
723

Callers

nothing calls this directly

Calls 3

popMethod · 0.45
extendMethod · 0.45
edgeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…