From 89c216dfe4fee2a72a9dc9d60034c36e58f9147d Mon Sep 17 00:00:00 2001 From: David Allemang Date: Wed, 14 Sep 2022 21:37:34 -0400 Subject: [PATCH] replace Rel with tuple --- tc/include/tc/core.hpp | 2 -- tc/include/tc/cosets.hpp | 6 ++++++ tc/include/tc/group.hpp | 7 ++++--- tc/include/tc/util.hpp | 17 ----------------- tc/src/core.cpp | 26 +++++++++++++------------- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/tc/include/tc/core.hpp b/tc/include/tc/core.hpp index 217bdd3..0e9786e 100644 --- a/tc/include/tc/core.hpp +++ b/tc/include/tc/core.hpp @@ -10,7 +10,5 @@ #include "group.hpp" namespace tc { - using Coset = unsigned int; - Cosets solve(const Group &group, const std::vector &sub_gens); } diff --git a/tc/include/tc/cosets.hpp b/tc/include/tc/cosets.hpp index aa8d696..e579cb1 100644 --- a/tc/include/tc/cosets.hpp +++ b/tc/include/tc/cosets.hpp @@ -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; + struct Cosets { int ngens; std::vector data; diff --git a/tc/include/tc/group.hpp b/tc/include/tc/group.hpp index 6d4190d..55b93a5 100644 --- a/tc/include/tc/group.hpp +++ b/tc/include/tc/group.hpp @@ -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 rels() const { diff --git a/tc/include/tc/util.hpp b/tc/include/tc/util.hpp index 9a0c291..51f2df5 100644 --- a/tc/include/tc/util.hpp +++ b/tc/include/tc/util.hpp @@ -100,21 +100,4 @@ namespace tc { return path.size(); } }; - - struct Rel { - std::array 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); - } - }; } diff --git a/tc/src/core.cpp b/tc/src/core.cpp index b99e0d8..cf159d9 100644 --- a/tc/src/core.cpp +++ b/tc/src/core.cpp @@ -63,19 +63,19 @@ namespace tc { Tables rel_tables(rels); std::vector> 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 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);