Note
This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.
BFSPredecessors#
- class BFSPredecessors#
Bases:
object
A custom class for the return from
rustworkx.bfs_predecessors()
The class can is a read-only sequence of tuples of the form:
[(node, [predecessor_a, predecessor_b])]
where
node
,predecessor_a
, andpredecessor_b
are 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 aniter()
that will yield the results in order.For example:
import rustworkx as rx graph = rx.generators.directed_path_graph(5) bfs_succ = rx.bfs_predecessors(0) # Index based access third_element = bfs_succ[2] # Use as iterator bfs_iter = iter(bfs_succ) first_element = next(bfs_iter) second_element = next(bfs_iter)