1
0

add path struct

This commit is contained in:
2020-01-07 23:14:48 -05:00
parent 462ebf7c25
commit c5f87942c9
3 changed files with 39 additions and 7 deletions

View File

@@ -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;
}

View File

@@ -16,10 +16,26 @@ namespace tc {
Action(int from_idx, int gen);
};
struct Path {
std::vector<Action> 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<int> data;
std::vector<Action> path;
Path path;
Cosets(const Cosets &) = default;

View File

@@ -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);
}
}