forked from mirror/toddcox-faster
add path struct
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
26
src/core.cpp
26
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user