rustworkx.ancestors#

ancestors(graph, node, /)#

Return the ancestors of a node in a graph.

This differs from PyDiGraph.predecessors() method in that predecessors returns only nodes with a direct edge into the provided node. While this function returns all nodes that have a path into the provided node.

Parameters:
  • graph (PyDiGraph) – The graph to get the ancestors from.

  • node (int) – The index of the graph node to get the ancestors for

Returns:

A set of node indices of ancestors of provided node.

Return type:

set