diff --git a/tc/include/tc/core.hpp b/tc/include/tc/core.hpp index 0e9786e..268cb3b 100644 --- a/tc/include/tc/core.hpp +++ b/tc/include/tc/core.hpp @@ -10,5 +10,5 @@ #include "group.hpp" namespace tc { - Cosets solve(const Group &group, const std::vector &sub_gens); + 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 e579cb1..4d59b4b 100644 --- a/tc/include/tc/cosets.hpp +++ b/tc/include/tc/cosets.hpp @@ -6,55 +6,67 @@ namespace tc { using Coset = uint32_t; - using Gen = uint16_t; + using Gen = uint8_t; using Mult = uint16_t; - + using Rel = std::tuple; struct Cosets { - int ngens; + const Coset UNSET = Coset(-1); + + Gen ngens; std::vector data; Path path; Cosets(const Cosets &) = default; - explicit Cosets(int ngens) + explicit Cosets(Gen ngens) : ngens(ngens) { } void add_row() { - data.resize(data.size() + ngens, -1); + data.resize(data.size() + ngens, UNSET); path.add_row(); } - void put(int coset, int gen, int target) { + void put(Coset coset, Gen gen, Coset target) { data[coset * ngens + gen] = target; data[target * ngens + gen] = coset; - if (path.get(target).from_idx == -1) { + if (path.get(target).from_idx == UNSET) { path.put(coset, gen, target); } } - void put(int idx, int target) { - int coset = idx / ngens; - int gen = idx % ngens; + void put(size_t idx, Coset target) { + Coset coset = idx / ngens; + Gen gen = idx % ngens; + data[idx] = target; data[target * ngens + gen] = coset; - if (path.get(target).from_idx == -1) { + if (path.get(target).from_idx == UNSET) { path.put(coset, gen, target); } } - [[nodiscard]] int get(int coset, int gen) const { + [[nodiscard]] Coset get(Coset coset, Gen gen) const { return data[coset * ngens + gen]; } - [[nodiscard]] int get(int idx) const { + [[nodiscard]] Coset get(size_t idx) const { return data[idx]; } + [[nodiscard]] bool isset(Coset coset, Gen gen) const { + return get(coset, gen) != UNSET; + } + + [[nodiscard]] bool isset(size_t idx) const { + return get(idx) != UNSET; + } + + [[nodiscard]] size_t size() const { return path.size(); } diff --git a/tc/src/core.cpp b/tc/src/core.cpp index cf159d9..79943fa 100644 --- a/tc/src/core.cpp +++ b/tc/src/core.cpp @@ -40,7 +40,7 @@ namespace tc { } }; - Cosets solve(const Group &group, const std::vector &sub_gens) { + Cosets solve(const Group &group, const std::vector &sub_gens) { auto ngens = group.ngens; // region Initialize Cosets Table @@ -75,7 +75,7 @@ namespace tc { const auto &[i, j, m] = rel_tables.rels[table_idx]; Row &row = rel_tables.rows[0][table_idx]; - if (cosets.get(i) + cosets.get(j) == -2) { + if (!cosets.isset(0, i) && !cosets.isset(0, j)) { row.lst_idx = lst_vals.size(); lst_vals.push_back(0); row.free = false; @@ -94,7 +94,7 @@ namespace tc { while (true) { // find next unknown product - while (idx < cosets.data.size() and cosets.get(idx) >= 0) + while (idx < cosets.data.size() and cosets.isset(idx)) idx++; // if there are none, then return diff --git a/tc/test/test_solve.cpp b/tc/test/test_solve.cpp index 019c4e2..c6edbe7 100644 --- a/tc/test/test_solve.cpp +++ b/tc/test/test_solve.cpp @@ -8,7 +8,12 @@ int main(int argc, char *argv[]) { std::string key = argv[1]; - std::vector, size_t>> groups; + std::vector, + size_t + >> groups; // See the group orders here https://en.wikipedia.org/wiki/Coxeter_group#Properties if (key == "A") { diff --git a/tc/test/test_solve_speed.cpp b/tc/test/test_solve_speed.cpp index 5144c86..80319a6 100644 --- a/tc/test/test_solve_speed.cpp +++ b/tc/test/test_solve_speed.cpp @@ -9,7 +9,12 @@ int main(int argc, char *argv[]) { std::string key = argv[1]; std::cerr << "Min. cos/s: " << MINIMUM_COS_PER_SEC << std::endl; - std::vector, size_t>> groups; + std::vector, + size_t + >> groups; // See the group orders here https://en.wikipedia.org/wiki/Coxeter_group#Properties if (key == "B") {