- class BFSPredecessors#
A custom class for the return from
The class can is a read-only sequence of tuples of the form:
[(node, [predecessor_a, predecessor_b])]
predecessor_bare the data payloads for the nodes in the graph.
This class is a container class for the results of the
rustworkx.bfs_predecessors()function. It implements the Python sequence protocol. So you can treat the return as read-only sequence/list that is integer indexed. If you want to use it as an iterator you can by wrapping it in an
iter()that will yield the results in order.
import rustworkx as rx graph = rx.generators.directed_path_graph(5) bfs_succ = rx.bfs_predecessors(0) # Index based access third_element = bfs_succ # Use as iterator bfs_iter = iter(bfs_succ) first_element = next(bfs_iter) second_element = next(bfs_iter)