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.

PathMapping#

class PathMapping#

Bases: object

A custom class for the return of paths to target nodes

The class is a read-only mapping of node indices to a list of node indices representing a path of the form:

{node_c: [node_a, node_b, node_c]}

where node_a, node_b, and node_c are integer node indices.

This class is a container class for the results of functions that return a mapping of target nodes and paths. It implements the Python mapping protocol. So you can treat the return as a read-only mapping/dict. If you want to use it as an iterator you can by wrapping it in an iter() that will yield the results in order.

For example:

import rustworkx as rx

graph = rx.generators.directed_path_graph(5)
edges = rx.dijkstra_shortest_paths(0)
# Target node access
third_element = edges[2]
# Use as iterator
edges_iter = iter(edges)
first_target = next(edges_iter)
first_path = edges[first_target]
second_target = next(edges_iter)
second_path = edges[second_target]

Methods