@@ -222,18 +222,33 @@ pub fn bfs_predecessors(
222
222
}
223
223
}
224
224
225
- /// Return the ancestors of a node in a graph.
225
+ /// Retrieve all ancestors of a specified node in a directed graph.
226
226
///
227
- /// This differs from :meth:`PyDiGraph.predecessors` method in that
228
- /// ``predecessors`` returns only nodes with a direct edge into the provided
229
- /// node. While this function returns all nodes that have a path into the
230
- /// provided node.
227
+ /// This function differs from the :meth:`PyDiGraph.predecessors` method,
228
+ /// which only returns nodes that have a direct edge leading to the specified
229
+ /// node. In contrast, this function returns all nodes that have a path
230
+ /// leading to the specified node, regardless of the number of edges in
231
+ /// between.
231
232
///
232
- /// :param PyDiGraph graph: The graph to get the ancestors from.
233
- /// :param int node: The index of the graph node to get the ancestors for
233
+ /// >>> G = rx.PyDiGraph()
234
+ /// >>> G.add_nodes_from(range(5))
235
+ /// NodeIndices[0, 1, 2, 3, 4]
236
+ /// >>> G.add_edges_from_no_data([(0, 2), (1, 2), (2, 3), (3, 4)])
237
+ /// [0, 1, 2, 3]
238
+ /// >>> rx.ancestors(G, 3)
239
+ /// {0, 1, 2}
234
240
///
235
- /// :returns: A set of node indices of ancestors of provided node.
236
- /// :rtype: set
241
+ /// .. seealso ::
242
+ /// See also :func:`~predecessors`.
243
+ ///
244
+ /// :param PyDiGraph graph: The directed graph from which to retrieve ancestors.
245
+ /// :param int node: The index of the node for which to find ancestors.
246
+ ///
247
+ /// :returns: A set containing the indices of all ancestor nodes of the
248
+ /// specified node.
249
+ /// :rtype: set[int]
250
+ ///
251
+ /// :raises IndexError: If the specified node is not present in the directed graph.
237
252
#[ pyfunction]
238
253
#[ pyo3( text_signature = "(graph, node, /)" ) ]
239
254
pub fn ancestors ( graph : & digraph:: PyDiGraph , node : usize ) -> PyResult < HashSet < usize > > {
@@ -250,18 +265,33 @@ pub fn ancestors(graph: &digraph::PyDiGraph, node: usize) -> PyResult<HashSet<us
250
265
. collect ( ) )
251
266
}
252
267
253
- /// Return the descendants of a node in a graph.
268
+ /// Retrieve all descendants of a specified node in a directed graph.
269
+ ///
270
+ /// This function differs from the :meth:`PyDiGraph.successors` method,
271
+ /// which only returns nodes that have a direct edge leading from the specified
272
+ /// node. In contrast, this function returns all nodes that have a path
273
+ /// leading from the specified node, regardless of the number of edges in
274
+ /// between.
275
+ ///
276
+ /// >>> G = rx.PyDiGraph()
277
+ /// >>> G.add_nodes_from(range(5))
278
+ /// NodeIndices[0, 1, 2, 3, 4]
279
+ /// >>> G.add_edges_from_no_data([(0, 1), (1, 2), (2, 3), (2, 4)])
280
+ /// [0, 1, 2, 3]
281
+ /// >>> rx.descendants(G, 1)
282
+ /// {2, 3, 4}
283
+ ///
284
+ /// .. seealso ::
285
+ /// See also :func:`~ancestors`.
254
286
///
255
- /// This differs from :meth:`PyDiGraph.successors` method in that
256
- /// ``successors``` returns only nodes with a direct edge out of the provided
257
- /// node. While this function returns all nodes that have a path from the
258
- /// provided node.
287
+ /// :param PyDiGraph graph: The directed graph from which to retrieve descendants.
288
+ /// :param int node: The index of the node for which to find descendants.
259
289
///
260
- /// :param PyDiGraph graph: The graph to get the descendants from
261
- /// :param int node: The index of the graph node to get the descendants for
290
+ /// :returns: A set containing the indices of all descendant nodes of the
291
+ /// specified node.
292
+ /// :rtype: set[int]
262
293
///
263
- /// :returns: A set of node indices of descendants of provided node.
264
- /// :rtype: set
294
+ /// :raises IndexError: If the specified node is not present in the directed graph.
265
295
#[ pyfunction]
266
296
#[ pyo3( text_signature = "(graph, node, /)" ) ]
267
297
pub fn descendants ( graph : & digraph:: PyDiGraph , node : usize ) -> PyResult < HashSet < usize > > {
0 commit comments