mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
replace Rel with tuple
This commit is contained in:
@@ -10,7 +10,5 @@
|
||||
#include "group.hpp"
|
||||
|
||||
namespace tc {
|
||||
using Coset = unsigned int;
|
||||
|
||||
Cosets solve(const Group &group, const std::vector<Coset> &sub_gens);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
#include "cosets.hpp"
|
||||
|
||||
namespace tc {
|
||||
using Coset = uint32_t;
|
||||
using Gen = uint16_t;
|
||||
using Mult = uint16_t;
|
||||
|
||||
using Rel = std::tuple<Gen, Gen, Mult>;
|
||||
|
||||
struct Cosets {
|
||||
int ngens;
|
||||
std::vector<int> data;
|
||||
|
||||
@@ -23,11 +23,12 @@ namespace tc {
|
||||
}
|
||||
|
||||
void set(const Rel &r) {
|
||||
_mults(r.gens[0], r.gens[1]) = r.mult;
|
||||
auto &[i, j, m] = r;
|
||||
_mults(i, j) = m;
|
||||
}
|
||||
|
||||
[[nodiscard]] int get(int a, int b) const {
|
||||
return _mults(a, b);
|
||||
[[nodiscard]] int get(int i, int j) const {
|
||||
return _mults(i, j);
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<Rel> rels() const {
|
||||
|
||||
@@ -100,21 +100,4 @@ namespace tc {
|
||||
return path.size();
|
||||
}
|
||||
};
|
||||
|
||||
struct Rel {
|
||||
std::array<int, 2> gens;
|
||||
int mult;
|
||||
|
||||
Rel() = default;
|
||||
|
||||
Rel(const Rel &) = default;
|
||||
|
||||
Rel(int a, int b, int m)
|
||||
: gens({a, b}), mult(m) {
|
||||
}
|
||||
|
||||
[[nodiscard]] Rel shift(int off) const {
|
||||
return Rel(gens[0] + off, gens[1] + off, mult);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,19 +63,19 @@ namespace tc {
|
||||
Tables rel_tables(rels);
|
||||
std::vector<std::vector<size_t>> tables_for(ngens);
|
||||
int rel_idx = 0;
|
||||
for (Rel m: rels) {
|
||||
tables_for[m.gens[0]].push_back(rel_idx);
|
||||
tables_for[m.gens[1]].push_back(rel_idx);
|
||||
for (const auto &[i, j, m]: rels) {
|
||||
tables_for[i].push_back(rel_idx);
|
||||
tables_for[j].push_back(rel_idx);
|
||||
rel_idx++;
|
||||
}
|
||||
|
||||
std::vector<Coset> lst_vals;
|
||||
rel_tables.add_row();
|
||||
for (int table_idx = 0; table_idx < rel_tables.size(); ++table_idx) {
|
||||
Rel &rel = rel_tables.rels[table_idx];
|
||||
const auto &[i, j, m] = rel_tables.rels[table_idx];
|
||||
Row &row = rel_tables.rows[0][table_idx];
|
||||
|
||||
if (cosets.get(rel.gens[0]) + cosets.get(rel.gens[1]) == -2) {
|
||||
if (cosets.get(i) + cosets.get(j) == -2) {
|
||||
row.lst_idx = lst_vals.size();
|
||||
lst_vals.push_back(0);
|
||||
row.free = false;
|
||||
@@ -133,12 +133,12 @@ namespace tc {
|
||||
|
||||
// If the product stays within the coset todo
|
||||
for (size_t table_idx: tables_for[gen]) {
|
||||
auto &rel = rel_tables.rels[table_idx];
|
||||
auto &[i, j, m] = rel_tables.rels[table_idx];
|
||||
auto &trow = rel_tables.rows[target][table_idx];
|
||||
auto &crow = rel_tables.rows[coset][table_idx];
|
||||
|
||||
// Test if loop is closed
|
||||
Coset other_gen = rel.gens[0] == gen ? rel.gens[1] : rel.gens[0];
|
||||
Coset other_gen = (i == gen) ? j : i;
|
||||
|
||||
if (trow.free) {
|
||||
if (target == coset) {
|
||||
@@ -149,16 +149,16 @@ namespace tc {
|
||||
trow.gnr++;
|
||||
|
||||
if (trow.idem) {
|
||||
if (trow.gnr == rel.mult) {
|
||||
if (trow.gnr == m) {
|
||||
// loop is closed, but internal, so the target links to itself via this generator.
|
||||
// todo might be able to move this logic up into the (target == coset) block and avoid those computations.
|
||||
facts.push(target * ngens + other_gen);
|
||||
}
|
||||
} else {
|
||||
if (trow.gnr == rel.mult - 1) {
|
||||
if (trow.gnr == m - 1) {
|
||||
// loop is almost closed. record that the target closes this loop.
|
||||
lst_vals[trow.lst_idx] = target;
|
||||
} else if (trow.gnr == rel.mult) {
|
||||
} else if (trow.gnr == m) {
|
||||
// loop is closed. We know the last element in the loop must link with this one.
|
||||
lst = lst_vals[trow.lst_idx];
|
||||
// delete trow.lst_ptr;
|
||||
@@ -172,12 +172,12 @@ namespace tc {
|
||||
// If any target row wasn't identified with a loop,
|
||||
// then assign it a new loop.
|
||||
for (size_t table_idx = 0; table_idx < rel_tables.size(); table_idx++) {
|
||||
auto &rel = rel_tables.rels[table_idx];
|
||||
auto &[i, j, m] = rel_tables.rels[table_idx];
|
||||
auto &trow = rel_tables.rows[target][table_idx];
|
||||
|
||||
if (trow.free) {
|
||||
if ((cosets.get(target, rel.gens[0]) != target) and
|
||||
(cosets.get(target, rel.gens[1]) != target)) {
|
||||
if ((cosets.get(target, i) != target) and
|
||||
(cosets.get(target, j) != target)) {
|
||||
trow.lst_idx = lst_vals.size();
|
||||
trow.free = false;
|
||||
lst_vals.push_back(0);
|
||||
|
||||
Reference in New Issue
Block a user