def _plain_bfs(G, source):
 Gsucc = G.succ
 Gpred = G.pred
 seen = set()
 nextlevel = {source}
 while nextlevel:
  thislevel = nextlevel
  nextlevel = set()
  for v in thislevel:
   if (v not in seen):
    (yield v)
    seen.add(v)
    nextlevel.update(Gsucc[v])
    nextlevel.update(Gpred[v])

def _plain_bfs ( G , source ) : Gsucc = G . succ Gpred = G . pred seen = set ( ) nextlevel = { source } while nextlevel : thislevel = nextlevel nextlevel = set ( ) for v in thislevel : if ( v not in seen ) : ( yield v ) seen . add ( v ) nextlevel . update ( Gsucc [ v ] ) nextlevel . update ( Gpred [ v ] )
a fast bfs node generator the direction of the edge between nodes is ignored .