MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ build_forest_index()

template<FieldArray Array, typename Parent>
std::optional< ForestIndex > MayaFlux::Kakshya::build_forest_index ( const Array & array,
Parent && parent,
std::string & error,
uint64_t * error_row = nullptr )
nodiscard

Build a ForestIndex from an array whose elements carry a parent row.

Template Parameters
ArrayIndexed array satisfying FieldArray.
ParentCallable taking a borrowed element and returning std::optional<uint64_t>; an empty result marks a root.
Parameters
errorReceives the reason when nullopt is returned.
error_rowReceives the failing row when given.
Returns
The index, or nullopt for an unreadable row or a parent that does not precede its child.

Definition at line 19 of file DataForestTraversal.hpp.

22{
23 std::vector<uint64_t> parents;
24 parents.reserve(array.size());
25 for (size_t row = 0; row < array.size(); ++row) {
26 const auto element = array.at(row);
27 if (!element) {
28 if (error_row)
29 *error_row = row;
30 error = "row is unreadable";
31 return std::nullopt;
32 }
33 const std::optional<uint64_t> link = std::invoke(parent, *element);
34 parents.push_back(link.value_or(ForestIndex::no_parent));
35 }
36 return ForestIndex::build(parents, error, error_row);
37}
static constexpr uint64_t no_parent
Parent value of a root row.
static std::optional< ForestIndex > build(std::span< const uint64_t > parents, std::string &error, uint64_t *error_row=nullptr)
Build the index from one parent per row.

References MayaFlux::Kakshya::ForestIndex::build(), and MayaFlux::Kakshya::ForestIndex::no_parent.

Referenced by index_composite_forest().

Here is the call graph for this function:
Here is the caller graph for this function: