diff --git a/example/path.cpp b/example/path.cpp index d9300d6..fca33e3 100644 --- a/example/path.cpp +++ b/example/path.cpp @@ -7,10 +7,20 @@ int main() { auto cube = tc::group::B(3); auto vars = cube.solve(); - for (size_t target = 1; target < vars.size(); target++) { - auto &action = vars.path.get(target); - std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl; + auto words = vars.path.walk( + "", + {"a", "b", "c"}, + [](auto a, auto b) { return a + b; } + ); + + for (const auto &word : words) { + std::cout << word << std::endl; } +// for (size_t target = 1; target < vars.size(); target++) { +// auto &action = vars.path.get(target); +// std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl; +// } + return 0; } diff --git a/include/tc/core.hpp b/include/tc/core.hpp index 7569749..f7ad487 100644 --- a/include/tc/core.hpp +++ b/include/tc/core.hpp @@ -1,8 +1,9 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include namespace tc { struct Action { @@ -25,10 +26,30 @@ namespace tc { void add_row(); - [[nodiscard]] const Action get(int to_idx) const; + [[nodiscard]] Action get(int to_idx) const; void put(int from_idx, int gen, int to_idx); + template + [[nodiscard]] std::vector walk( + T start, + std::vector gen_values, + std::function op + ) const { + std::vector res(size()); + res[0] = start; + + for (int i = 1; i < res.size(); ++i) { + auto action = path[i]; + const auto &from = res[action.from_idx]; + const auto &val = gen_values[action.gen]; + res[i] = op(from, val); + } + + return res; + } + + [[nodiscard]] size_t size() const; }; diff --git a/src/core.cpp b/src/core.cpp index 081e8bf..00346b0 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -12,7 +12,7 @@ namespace tc { path.resize(path.size() + 1); } - const Action Path::get(int to_idx) const { + Action Path::get(int to_idx) const { return path[to_idx]; }