@@ -300,8 +300,7 @@ then node ``i`` is a root node.
300300 R"pbdoc(
301301:sig=(self: Forest, i: int) -> list[int]:
302302
303- Returns a list containing the labels of the edges on the path from a root node
304- to *i*.
303+ Returns a list containing the labels of the edges on the path from the node *i* to a root node.
305304
306305:param i: the node.
307306:type i: int
@@ -340,6 +339,185 @@ Set the parent and edge label for a node. This function sets the parent of
340339 if *node* or *parent* exceeds :any:`number_of_nodes()`.
341340
342341:complexity: Constant.
342+ )pbdoc" );
343+
344+ // //////////////////////////////////////////////////////////////////////
345+ // Helpers
346+ // //////////////////////////////////////////////////////////////////////
347+
348+ m.def (
349+ " forest_path_to_root" ,
350+ [](Forest const & f, node_type n) { return forest::path_to_root (f, n); },
351+ py::arg (" f" ),
352+ py::arg (" n" ),
353+ R"pbdoc(
354+ :sig=(f: Forest, n: int) -> list[int]:
355+
356+ Returns a list containing the labels of the edges on the path from node *n* to
357+ a root node.
358+
359+ :param f: the Forest.
360+ :type f: Forest
361+
362+ :param n: the node.
363+ :type n: int
364+
365+ :returns: The word labelling the path from the root to *n*.
366+ :rtype: list[int]
367+
368+ :raises LibsemigroupsError:
369+ if *n* is greater than or equal to :any:`Forest.number_of_nodes`.
370+ )pbdoc" );
371+
372+ m.def (
373+ " forest_depth" ,
374+ [](Forest const & f, node_type n) { return forest::depth (f, n); },
375+ py::arg (" f" ),
376+ py::arg (" n" ),
377+ R"pbdoc(
378+ :sig=(f: Forest, n: int) -> int:
379+
380+ Returns the depth of a node in the forest, i.e. the distance, in terms of the
381+ number of edges, from a root.
382+
383+ This function returns the length of the word returned by
384+ :any:`path_to_root` and :any:`path_from_root`.
385+
386+ :param f: the Forest.
387+ :type f: Forest
388+
389+ :param n: the node.
390+ :type n: int
391+
392+ :returns: The depth of *n*.
393+ :rtype: int
394+
395+ :raises LibsemigroupsError:
396+ if *n* is out of bounds (i.e. it is greater than or equal to
397+ :any:`Forest.number_of_nodes`).
398+ )pbdoc" );
399+
400+ m.def (
401+ " forest_dot" ,
402+ [](Forest const & f) { return forest::dot (f); },
403+ py::arg (" f" ),
404+ R"pbdoc(
405+ Returns a :any:`Dot` object representing a Forest.
406+
407+ This function returns a :any:`Dot` object representing the :any:`Forest` *f*.
408+
409+ :param f: the Forest.
410+ :type f: Forest
411+
412+ :returns: A :any:`Dot` object.
413+
414+ :rtype: Dot
415+ )pbdoc" );
416+
417+ m.def (
418+ " forest_dot" ,
419+ [](Forest const & f, std::vector<std::string> const & labels) {
420+ return forest::dot (f, labels);
421+ },
422+ py::arg (" f" ),
423+ py::arg (" labels" ),
424+ R"pbdoc(
425+ :sig=(f: Forest, labels: list[str]) -> Dot:
426+
427+ Returns a :any:`Dot` object representing a Forest.
428+
429+ This function returns a :any:`Dot` object representing the :any:`Forest` *f*.
430+ If *labels* is not empty, then each node is labelled with the path from
431+ that node to the root of its tree with each letter replaced by the string
432+ in the corresponding position of *labels*. If *labels* is empty, then
433+ the nodes are not labelled by their paths.
434+
435+ :param f: the Forest.
436+ :type f: Forest
437+
438+ :param labels: substitute for each edge label.
439+ :type labels: list[str]
440+
441+ :returns: A :any:`Dot` object.
442+ :rtype: Dot
443+
444+ :raises LibsemigroupsError:
445+ if the size of *labels* is not the same as the :any:`max_label` plus one.
446+ )pbdoc" );
447+
448+ m.def (" forest_is_root" ,
449+ &forest::is_root,
450+ py::arg (" f" ),
451+ py::arg (" n" ),
452+ R"pbdoc(
453+ :sig=(f: Forest, n: int) -> bool:
454+
455+ Check if a node is the root of any tree in the :any:`Forest`.
456+
457+ This function returns ``True`` if the node *n* in the :any:`Forest` *f* is
458+ a root node, and ``False`` if it is not.
459+
460+ :param f: the Forest.
461+ :type f: Forest
462+
463+ :param n: the node.
464+ :type n: int
465+
466+ :returns: Whether or not *n* is a root of *f*.
467+ :rtype: bool
468+
469+ :raises LibsemigroupsError:
470+ if *n* is out of bounds (i.e. it is greater than or equal to
471+ :any:`Forest.number_of_nodes`).
472+ )pbdoc" );
473+
474+ m.def (
475+ " forest_max_label" ,
476+ [](Forest const & f) -> int_or_unsigned_constant<Forest::label_type> {
477+ return from_int (forest::max_label (f));
478+ },
479+ py::arg (" f" ),
480+ R"pbdoc(
481+ :sig=(f: Forest) -> int | Undefined:
482+
483+ Returns the maximum label of any edge in a :any:`Forest`.
484+
485+ This function returns the maximum label of any edge in the :any:`Forest` *f*
486+ or :any:`UNDEFINED` if there are no edges.
487+
488+ :param f: the Forest.
489+ :type f: Forest
490+
491+ :returns: The maximum label or :any:`UNDEFINED`.
492+ :rtype: int | Undefined
493+ )pbdoc" );
494+
495+ m.def (
496+ " forest_path_from_root" ,
497+ [](Forest const & f, Forest::node_type n) {
498+ return forest::path_from_root (f, n);
499+ },
500+ py::arg (" f" ),
501+ py::arg (" n" ),
502+ R"pbdoc(
503+ :sig=(f: Forest, n: int) -> list[int]:
504+
505+ Returns a word containing the labels of the edges on the path from a root node
506+ to *n*.
507+
508+ This function returns a word containing the labels of the edges on the path
509+ from a root node to the node *n*.
510+
511+ :param f: the forest.
512+ :type f: Forest
513+
514+ :param n: the node.
515+ :type n: int
516+
517+ :returns: The word labelling the path from a root node to *n*.
518+ :rtype: list[int]
519+
520+ .. seealso:: :any:`PathsFromRoots`
343521)pbdoc" );
344522 }
345523} // namespace libsemigroups
0 commit comments