diff --git a/example/path.cpp b/example/path.cpp index 9f4cd1e..d9300d6 100644 --- a/example/path.cpp +++ b/example/path.cpp @@ -8,7 +8,7 @@ int main() { auto vars = cube.solve(); for (size_t target = 1; target < vars.size(); target++) { - auto &action = vars.path[target]; + auto &action = vars.path.get(target); std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl; } diff --git a/include/tc/core.hpp b/include/tc/core.hpp index 9666ea2..7569749 100644 --- a/include/tc/core.hpp +++ b/include/tc/core.hpp @@ -16,10 +16,26 @@ namespace tc { Action(int from_idx, int gen); }; + struct Path { + std::vector path; + + Path() = default; + + Path(const Path &) = default; + + void add_row(); + + [[nodiscard]] const Action get(int to_idx) const; + + void put(int from_idx, int gen, int to_idx); + + [[nodiscard]] size_t size() const; + }; + struct Cosets { int ngens; std::vector data; - std::vector path; + Path path; Cosets(const Cosets &) = default; diff --git a/src/core.cpp b/src/core.cpp index c59f55c..081e8bf 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -8,21 +8,37 @@ namespace tc { : from_idx(from_idx), gen(gen) { } + void Path::add_row() { + path.resize(path.size() + 1); + } + + const Action Path::get(int to_idx) const { + return path[to_idx]; + } + + void Path::put(int from_idx, int gen, int to_idx) { + path[to_idx] = Action(from_idx, gen); + } + + size_t Path::size() const { + return path.size(); + } + Cosets::Cosets(int ngens) : ngens(ngens) { } void Cosets::add_row() { data.resize(data.size() + ngens, -1); - path.resize(path.size() + 1); + path.add_row(); } void Cosets::put(int coset, int gen, int target) { data[coset * ngens + gen] = target; data[target * ngens + gen] = coset; - if (path[target].from_idx == -1) { - path[target] = Action(coset, gen); + if (path.get(target).from_idx == -1) { + path.put(coset, gen, target); } } @@ -32,8 +48,8 @@ namespace tc { data[idx] = target; data[target * ngens + gen] = coset; - if (path[target].from_idx == -1) { - path[target] = Action(coset, gen); + if (path.get(target).from_idx == -1) { + path.put(coset, gen, target); } }