Defined in forest.hpp.
This class represents a range object that facilitates iterating through the paths from the roots in a Forest object to every node. These nodes are taken in numerical order, so the first value returned by get is the word from a root to node 0, after next is called, get returns the word from a root to node 1, and so on.
The point of this class is to permit more efficient iteration over many paths in a Forest object than path_from_root_no_checks (and its associated helper functions). path_from_root_no_checks traverses the Forest from the given node to the root of its tree. If the path from nodes m and n to the root of their tree share a long common prefix, then this prefix will be traversed twice in two calls to path_from_root_no_checks. PathsFromRoots avoids this by finding the least common ancestor of m and n, so that the prefix is not re-traversed. This works best when the nodes in the Forest are specified in a sensible order (such as via a depth-first or breadth-first traversal).
So that the PathsFromRoots class can be used efficiently with the functionality of rx::ranges, the usual naming conventions in libsemigroups are not used for the member functions:
of PathsFromRoots. In particular, none of these member functions check their arguments, but they do not have the suffix _no_checks.
Public Types | |
| using | node_type = Forest::node_type |
| The type of nodes in the underlying Forest. | |
| using | output_type = word_type const& |
| The type of the output of a PathsFromRoots object. | |
| using | size_type = typename std::vector<word_type>::size_type |
| Alias for the size type. | |
Static Public Attributes | |
| static constexpr bool | is_finite = true |
| Value indicating that the range is finite. | |
| static constexpr bool | is_idempotent = true |
Public Member Functions | |
| bool | at_end () const noexcept |
| Check if the range is exhausted. | |
| auto | begin () noexcept |
| Returns an input iterator pointing to the first word in the range. | |
| size_type | count () const noexcept |
| Get the size of the range. | |
| auto | end () noexcept |
| Returns an input iterator pointing one beyond the last word in the range. | |
| Forest const & | forest () const noexcept |
| Returns the underlying Forest object. | |
| output_type | get () const noexcept |
| Returns a reference to the current path. | |
| PathsFromRoots & | init (Forest const &f) |
| Re-initialize from a Forest. | |
| void | next () |
| Advance to the next path in the range. | |
| PathsFromRoots ()=delete | |
| Deleted. | |
| PathsFromRoots (Forest const &f) | |
| Construct from a Forest. | |
| PathsFromRoots (PathsFromRoots &&)=default | |
| Default move constructor. | |
| PathsFromRoots (PathsFromRoots const &)=default | |
| Default copy constructor. | |
| size_type | size_hint () const noexcept |
| Get the size of the range. | |
| PathsFromRoots & | skip_n (size_type n) |
| Skip a number of paths in the range. | |
| node_type | target () const noexcept |
| Get the current target of the path. | |
Public Member Functions inherited from PathsFromRoots | |
| PathsFromRoots ()=delete | |
| Deleted. | |
| PathsFromRoots (Forest const &f) | |
| Construct from a Forest. | |
| PathsFromRoots (PathsFromRoots &&)=default | |
| Default move constructor. | |
| PathsFromRoots (PathsFromRoots const &)=default | |
| Default copy constructor. | |
| bool | at_end () const noexcept |
| Check if the range is exhausted. | |
| size_type | count () const noexcept |
| Get the size of the range. | |
| Forest const & | forest () const noexcept |
| Returns the underlying Forest object. | |
| output_type | get () const noexcept |
| Returns a reference to the current path. | |
| PathsFromRoots & | init (Forest const &f) |
| Re-initialize from a Forest. | |
| PathsFromRoots & | operator= (PathsFromRoots &&)=default |
| Default move assignment operator. | |
| PathsFromRoots & | operator= (PathsFromRoots const &)=default |
| Default copy assignment operator. | |
| size_type | size_hint () const noexcept |
| Get the size of the range. | |
| node_type | target () const noexcept |
| Get the current target of the path. | |
|
inlinenodiscardnoexcept |
This function returns true if there are no more paths in the range, and false otherwise.
|
inlinenodiscardnoexcept |
This function returns an input iterator pointing to the first word in a PathsFromRoots object.
noexcept and is guaranteed never to throw.paths in a range-based for-loop such as: paths is copied, and so will be constant inside the for-loop. For example, in The value of t will be constant, even though the value of path may change.
|
inlinenodiscardnoexcept |
This function returns the number of paths in the range.
|
inlinenodiscardnoexcept |
This function returns an input iterator pointing one beyond the last word in a PathsFromRoots object.
noexcept and is guaranteed never to throw.
|
inlinenodiscardnoexcept |
This function returns the Forest object used to constructor or initialise a PathsFromRoots object.
noexcept and is guaranteed never to throw.
|
inlinenodiscardnoexcept |
| PathsFromRoots & init | ( | Forest const & | f | ) |
This function re-initializes a PathsFromRoots so that its underlying Forest object is f. This puts the PathsFromRoots object back into the same state it would have been in if it had been newly constructed from f.
| f | the Forest. |
| void next | ( | ) |
Advance to the current path in the range. If at_end returns true, then this function does nothing.
|
delete |
A Forest object is required to construct or initialise a PathsFromRoots object.
|
explicit |
This function constructs a new PathsFromRoots for the Forest f. The newly constructed object does not copy f and is not valid if f is destroyed.
| f | the Forest. |
|
inlinenodiscardnoexcept |
This function returns the number of paths in the range. The output is identical to that of count, and is included for compatibility with rx::ranges.
| PathsFromRoots & skip_n | ( | size_type | n | ) |
This function skips n paths in the range. If n is 1, then this is the same as calling next. If n is 0, then this function does nothing.
| n | the number of paths to skip. |
*this.
|
inlinenodiscardnoexcept |
This function returns the current target of the path returned by get.
noexcept and is guaranteed never to throw.
|
staticconstexpr |
Value indicating that if get() is called twice on a PathsFromRoots object that is not changed between the two calls, then the return value of get() is the same both times.