mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
wip - add Path<> stub; remove old.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
add_library(tc
|
||||
include/tc/core.hpp
|
||||
include/tc/groups.hpp
|
||||
include/tc/util.hpp
|
||||
|
||||
src/cosets.cpp
|
||||
src/group.cpp
|
||||
|
||||
@@ -44,6 +44,13 @@ namespace tc {
|
||||
template<typename Gen_=void>
|
||||
struct Group;
|
||||
|
||||
/**
|
||||
* @brief Support generating values given a Cosets and transformation callback.
|
||||
* @tparam Gen_
|
||||
*/
|
||||
template<typename Gen_=void>
|
||||
struct Path; // todo not yet implemented
|
||||
|
||||
template<>
|
||||
struct Index<> {
|
||||
size_t operator()(size_t const &idx) const {
|
||||
@@ -57,7 +64,7 @@ namespace tc {
|
||||
|
||||
std::vector<Gen> _gens{};
|
||||
|
||||
explicit Index(std::vector<Gen> gens) : _gens(gens) {}
|
||||
// explicit Index(std::vector<Gen> gens) : _gens(gens) {}
|
||||
|
||||
size_t operator()(Gen const &gen) const {
|
||||
auto it = std::find(_gens.begin(), _gens.end(), gen);
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
namespace tc {
|
||||
// using Mult = uint16_t;
|
||||
// constexpr Mult FREE = 0;
|
||||
|
||||
struct Action {
|
||||
int from_idx = -1;
|
||||
int gen = -1;
|
||||
|
||||
Action() = default;
|
||||
|
||||
Action(const Action &) = default;
|
||||
|
||||
Action(int from_idx, int gen)
|
||||
: from_idx(from_idx), gen(gen) {
|
||||
}
|
||||
};
|
||||
|
||||
struct Path {
|
||||
std::vector<Action> path;
|
||||
|
||||
Path() = default;
|
||||
|
||||
Path(const Path &) = default;
|
||||
|
||||
void add_row() {
|
||||
path.resize(path.size() + 1);
|
||||
}
|
||||
|
||||
[[nodiscard]] Action get(int to_idx) const {
|
||||
return path[to_idx];
|
||||
}
|
||||
|
||||
void put(int from_idx, int gen, int to_idx) {
|
||||
path[to_idx] = Action(from_idx, gen);
|
||||
}
|
||||
|
||||
template<class C, class T, class E>
|
||||
void walk(
|
||||
C &res,
|
||||
T start,
|
||||
std::vector<E> gens,
|
||||
std::function<T(const T &, const E &)> op
|
||||
) const {
|
||||
size_t s = size();
|
||||
res.reserve(s);
|
||||
res.push_back(start);
|
||||
|
||||
for (int i = 1; i < s; ++i) {
|
||||
auto &action = path[i];
|
||||
auto &from = res.get(action.from_idx);
|
||||
auto &val = gens[action.gen];
|
||||
res.push_back(op(from, val));
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class E>
|
||||
[[nodiscard]] std::vector<T> walk(
|
||||
T start,
|
||||
std::vector<E> gens,
|
||||
std::function<T(const T &, const E &)> op
|
||||
) const {
|
||||
std::vector<T> res;
|
||||
res.reserve(size());
|
||||
res.push_back(start);
|
||||
|
||||
for (int i = 1; i < size(); ++i) {
|
||||
auto &action = path[i];
|
||||
auto &from = res[action.from_idx];
|
||||
auto &val = gens[action.gen];
|
||||
res.push_back(op(from, val));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
[[nodiscard]] std::vector<T> walk(
|
||||
T start,
|
||||
std::function<T(const T &, const int &)> op
|
||||
) const {
|
||||
std::vector<T> res;
|
||||
res.reserve(size());
|
||||
res.push_back(start);
|
||||
|
||||
for (int i = 1; i < size(); ++i) {
|
||||
auto &action = path[i];
|
||||
auto &from = res[action.from_idx];
|
||||
auto &val = action.gen;
|
||||
res[i] = op(from, val);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t size() const {
|
||||
return path.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
#include <tc/util.hpp>
|
||||
#include <tc/core.hpp>
|
||||
#include <tc/groups.hpp>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user