From 4f3fcb6c0f70455a6c9df739bf739808ebdc1640 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Mon, 1 Nov 2021 17:10:25 -0400 Subject: [PATCH] Group related classes Flattens the header structure and group related classes together. --- example/bench.cpp | 6 +- example/path.cpp | 8 ++- include/tc/core.hpp | 4 -- include/tc/cosets.hpp | 96 ++++++++++++++++++++++++++++ include/tc/{core => }/group.hpp | 5 -- include/tc/groups.hpp | 16 ++--- include/tc/{core => }/solver.hpp | 104 +++---------------------------- 7 files changed, 121 insertions(+), 118 deletions(-) delete mode 100644 include/tc/core.hpp create mode 100644 include/tc/cosets.hpp rename include/tc/{core => }/group.hpp (95%) rename include/tc/{core => }/solver.hpp (71%) diff --git a/example/bench.cpp b/example/bench.cpp index 5b83d36..ee952a2 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -1,10 +1,10 @@ -#include "tc/core.hpp" -#include "tc/groups.hpp" - #include #include #include +#include +#include + template void test(const G &group) { auto s = std::clock(); diff --git a/example/path.cpp b/example/path.cpp index cbdd16f..f3aca5f 100644 --- a/example/path.cpp +++ b/example/path.cpp @@ -1,8 +1,10 @@ -#include "tc/core.hpp" -#include "tc/groups.hpp" - +#include +#include #include +#include +#include + int main() { auto cube = tc::group::B<3>(); auto vars = tc::solve(cube); diff --git a/include/tc/core.hpp b/include/tc/core.hpp deleted file mode 100644 index 7505211..0000000 --- a/include/tc/core.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#include "tc/core/group.hpp" -#include "tc/core/solver.hpp" diff --git a/include/tc/cosets.hpp b/include/tc/cosets.hpp new file mode 100644 index 0000000..4f50b32 --- /dev/null +++ b/include/tc/cosets.hpp @@ -0,0 +1,96 @@ +#pragma once + +#include + +namespace tc { + template + class Path; + + template + class Cosets { + private: + std::vector data; + + public: + Cosets(const Cosets &) = default; + + Cosets() = default; + + void add_row() { + data.resize(data.size() + Rank, -1); + } + + void put(int coset, int gen, int target) { + data[coset * Rank + gen] = target; + data[target * Rank + gen] = coset; + } + + [[nodiscard]] int get(int coset, int gen) const { + return data[coset * Rank + gen]; + } + + [[nodiscard]] size_t order() const { + return data.size() / Rank; + } + + Path path() const; + }; + + template + class Path { + private: + friend class Cosets; + + std::vector source; + std::vector gen; + size_t _order; + + explicit Path(size_t order) : _order(order), source(order), gen(order) {} + + public: + size_t order() const { + return _order; + } + + template + std::vector walk(const T &start, const F &op) { + std::vector res; + res.reserve(order()); + res.push_back(start); + + for (size_t i = 1; i < order(); ++i) { + auto val = op(res[source[i]], gen[i]); + res.push_back(val); + } + + return res; + } + + template + std::vector walk(const T &start, const E &gens, const F &op) { + return walk(start, [&](const T &s, const int g) { + return op(s, gens[g]); + }); + } + }; + + template + Path Cosets::path() const { + Path res(order()); + std::vector set(order()); + + for (int coset = 0; coset < order(); ++coset) { + for (int gen = 0; gen < Rank; ++gen) { + int target = get(coset, gen); + + if (!set[target]) { + res.source[target] = coset; + res.gen[target] = gen; + set[target] = true; + } + } + } + + return res; + } +} diff --git a/include/tc/core/group.hpp b/include/tc/group.hpp similarity index 95% rename from include/tc/core/group.hpp rename to include/tc/group.hpp index 7f6f296..f37d10e 100644 --- a/include/tc/core/group.hpp +++ b/include/tc/group.hpp @@ -1,14 +1,9 @@ #pragma once -#include #include #include -#include -#include -#include #include -#include namespace { template diff --git a/include/tc/groups.hpp b/include/tc/groups.hpp index e01a091..81a2c54 100644 --- a/include/tc/groups.hpp +++ b/include/tc/groups.hpp @@ -1,13 +1,13 @@ #pragma once -#include "core.hpp" +#include "group.hpp" namespace tc::group { /** * Universal Coxeter Group */ template - Group U() { + Group U() { std::stringstream ss; ss << "U(" << Rank << ")"; @@ -21,7 +21,7 @@ namespace tc::group { * Simplex */ template - Group A() { + Group A() { std::stringstream ss; ss << "A(" << Rank << ")"; @@ -31,7 +31,7 @@ namespace tc::group { return res; } - std::array mults; + tc::Symbol mults; mults.fill(3); return schlafli(mults, ss.str()); @@ -41,7 +41,7 @@ namespace tc::group { * Cube, Orthoplex */ template - Group B() { + Group B() { std::stringstream ss; ss << "B(" << Rank << ")"; @@ -56,7 +56,7 @@ namespace tc::group { * Demicube, Orthoplex */ template - Group D() { + Group D() { std::stringstream ss; ss << "D(" << Rank << ")"; @@ -75,7 +75,7 @@ namespace tc::group { * E groups */ template - Group E() { + Group E() { std::stringstream ss; ss << "E(" << Rank << ")"; @@ -108,7 +108,7 @@ namespace tc::group { * Icosahedron */ template - Group H() { + Group H() { std::stringstream ss; ss << "H(" << Rank << ")"; diff --git a/include/tc/core/solver.hpp b/include/tc/solver.hpp similarity index 71% rename from include/tc/core/solver.hpp rename to include/tc/solver.hpp index e80f138..50b3e65 100644 --- a/include/tc/core/solver.hpp +++ b/include/tc/solver.hpp @@ -1,100 +1,13 @@ #pragma once +#include +#include #include #include +#include -namespace tc { - template - class Path; - - template - class Cosets { - private: - std::vector data; - - public: - Cosets(const Cosets &) = default; - - Cosets() = default; - - void add_row() { - data.resize(data.size() + Rank, -1); - } - - void put(int coset, int gen, int target) { - data[coset * Rank + gen] = target; - data[target * Rank + gen] = coset; - } - - [[nodiscard]] int get(int coset, int gen) const { - return data[coset * Rank + gen]; - } - - [[nodiscard]] size_t order() const { - return data.size() / Rank; - } - - Path path() const; - }; - - template - class Path { - private: - friend class Cosets; - - std::vector source; - std::vector gen; - size_t _order; - - explicit Path(size_t order) : _order(order), source(order), gen(order) {} - - public: - size_t order() const { - return _order; - } - - template - std::vector walk(const T &start, const F &op) { - std::vector res; - res.reserve(order()); - res.push_back(start); - - for (size_t i = 1; i < order(); ++i) { - auto val = op(res[source[i]], gen[i]); - res.push_back(val); - } - - return res; - } - - template - std::vector walk(const T &start, const E &gens, const F &op) { - return walk(start, [&](const T &s, const int g) { - return op(s, gens[g]); - }); - } - }; - - template - Path Cosets::path() const { - Path res(order()); - std::vector set(order()); - - for (int coset = 0; coset < order(); ++coset) { - for (int gen = 0; gen < Rank; ++gen) { - int target = get(coset, gen); - - if (!set[target]) { - res.source[target] = coset; - res.gen[target] = gen; - set[target] = true; - } - } - } - - return res; - } -} +#include "group.hpp" +#include "cosets.hpp" namespace { struct Row { @@ -107,7 +20,7 @@ namespace { public: int i, j, mult; - std::vector rows; + std::vector rows; public: explicit Table(int i, int j, int mult) : @@ -156,8 +69,9 @@ namespace { int *null_lst_ptr = new int; BlockAllocator alloc; - std::array, Rels> tables; - std::array>, Rank> deps; + std::array , Rels> tables; + std::array >, Rank> + deps; public: explicit Tables(const tc::Group &group) {