mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 03:52:48 -05:00
WIP: Oversimplify reltables
This commit is contained in:
@@ -2,68 +2,34 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace tc {
|
namespace {
|
||||||
struct RelTablesRow {
|
using namespace tc;
|
||||||
int *gnrs;
|
|
||||||
int **lst_ptrs;
|
|
||||||
|
|
||||||
RelTablesRow(int N, int *gnrs, int **lst_ptrs) : gnrs(gnrs), lst_ptrs(lst_ptrs) {
|
struct Row {
|
||||||
for (int i = 0; i < N; i++) {
|
std::vector<int> gnrs;
|
||||||
lst_ptrs[i] = nullptr;
|
std::vector<int *> lst_ptrs;
|
||||||
}
|
|
||||||
|
Row(int num_tables)
|
||||||
|
: gnrs(num_tables, 0), lst_ptrs(num_tables, nullptr) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RelTables {
|
struct Tables {
|
||||||
static const int ROW_BLOCK_SIZE = 64;
|
|
||||||
std::vector<Rel> rels;
|
std::vector<Rel> rels;
|
||||||
std::vector<RelTablesRow *> rows;
|
std::vector<Row> rows;
|
||||||
int start = 0;
|
|
||||||
int num_tables;
|
int num_tables;
|
||||||
int buffer_rows = 0;
|
|
||||||
|
|
||||||
explicit RelTables(const std::vector<Rel> &rels)
|
explicit Tables(const std::vector<Rel> &rels)
|
||||||
: num_tables(rels.size()), rels(rels) {
|
: num_tables(rels.size()), rels(rels) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_row() {
|
void add_row() {
|
||||||
if (buffer_rows == 0) {
|
rows.emplace_back(num_tables);
|
||||||
int *gnrs_alloc = new int[num_tables * RelTables::ROW_BLOCK_SIZE];
|
|
||||||
int **lst_ptrs_alloc = new int *[num_tables * RelTables::ROW_BLOCK_SIZE];
|
|
||||||
for (int i = 0; i < RelTables::ROW_BLOCK_SIZE; i++) {
|
|
||||||
rows.push_back(
|
|
||||||
new RelTablesRow(num_tables, &gnrs_alloc[i * num_tables], &lst_ptrs_alloc[i * num_tables]));
|
|
||||||
}
|
|
||||||
buffer_rows = RelTables::ROW_BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer_rows--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void del_rows_to(int idx) {
|
|
||||||
const int del_to = (idx / RelTables::ROW_BLOCK_SIZE) * RelTables::ROW_BLOCK_SIZE;
|
|
||||||
for (int i = start; i < del_to; i += RelTables::ROW_BLOCK_SIZE) {
|
|
||||||
delete[] rows[i]->gnrs;
|
|
||||||
delete[] rows[i]->lst_ptrs;
|
|
||||||
for (int j = 0; j < RelTables::ROW_BLOCK_SIZE; j++) {
|
|
||||||
delete rows[i + j];
|
|
||||||
}
|
|
||||||
start += RelTables::ROW_BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~RelTables() {
|
|
||||||
while (start < rows.size()) {
|
|
||||||
delete[] rows[start]->gnrs;
|
|
||||||
delete[] rows[start]->lst_ptrs;
|
|
||||||
for (int j = 0; j < RelTables::ROW_BLOCK_SIZE; j++) {
|
|
||||||
delete rows[start + j];
|
|
||||||
}
|
|
||||||
start += RelTables::ROW_BLOCK_SIZE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace tc {
|
||||||
Cosets Group::solve(const std::vector<int> &sub_gens) const {
|
Cosets Group::solve(const std::vector<int> &sub_gens) const {
|
||||||
Cosets cosets(ngens);
|
Cosets cosets(ngens);
|
||||||
cosets.add_row();
|
cosets.add_row();
|
||||||
@@ -77,7 +43,7 @@ namespace tc {
|
|||||||
cosets.put(0, g, 0);
|
cosets.put(0, g, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
RelTables rel_tables(rels());
|
Tables rel_tables(rels());
|
||||||
std::vector<std::vector<int>> gen_map(ngens);
|
std::vector<std::vector<int>> gen_map(ngens);
|
||||||
int rel_idx = 0;
|
int rel_idx = 0;
|
||||||
for (Rel m: rels()) {
|
for (Rel m: rels()) {
|
||||||
@@ -88,7 +54,7 @@ namespace tc {
|
|||||||
|
|
||||||
int null_lst_ptr;
|
int null_lst_ptr;
|
||||||
rel_tables.add_row();
|
rel_tables.add_row();
|
||||||
RelTablesRow &row = *(rel_tables.rows[0]);
|
Row &row = rel_tables.rows[0];
|
||||||
for (int table_idx = 0; table_idx < rel_tables.num_tables; table_idx++) {
|
for (int table_idx = 0; table_idx < rel_tables.num_tables; table_idx++) {
|
||||||
Rel &ti = rel_tables.rels[table_idx];
|
Rel &ti = rel_tables.rels[table_idx];
|
||||||
|
|
||||||
@@ -108,7 +74,7 @@ namespace tc {
|
|||||||
idx++;
|
idx++;
|
||||||
|
|
||||||
if (idx == cosets.data.size()) {
|
if (idx == cosets.data.size()) {
|
||||||
rel_tables.del_rows_to(idx / ngens);
|
// rel_tables.del_rows_to(idx / ngens);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,9 +88,9 @@ namespace tc {
|
|||||||
coset = idx / ngens;
|
coset = idx / ngens;
|
||||||
gen = idx % ngens;
|
gen = idx % ngens;
|
||||||
|
|
||||||
rel_tables.del_rows_to(coset);
|
// rel_tables.del_rows_to(coset);
|
||||||
|
|
||||||
RelTablesRow &target_row = *(rel_tables.rows[target]);
|
Row &target_row = rel_tables.rows[target];
|
||||||
while (!facts.empty()) {
|
while (!facts.empty()) {
|
||||||
fact_idx = facts.back();
|
fact_idx = facts.back();
|
||||||
facts.pop_back();
|
facts.pop_back();
|
||||||
@@ -142,7 +108,7 @@ namespace tc {
|
|||||||
if (target_row.lst_ptrs[table_idx] == nullptr)
|
if (target_row.lst_ptrs[table_idx] == nullptr)
|
||||||
target_row.gnrs[table_idx] = -1;
|
target_row.gnrs[table_idx] = -1;
|
||||||
|
|
||||||
RelTablesRow &coset_row = *(rel_tables.rows[coset]);
|
Row &coset_row = rel_tables.rows[coset];
|
||||||
for (int table_idx: gen_map[gen]) {
|
for (int table_idx: gen_map[gen]) {
|
||||||
if (target_row.lst_ptrs[table_idx] == nullptr) {
|
if (target_row.lst_ptrs[table_idx] == nullptr) {
|
||||||
Rel &ti = rel_tables.rels[table_idx];
|
Rel &ti = rel_tables.rels[table_idx];
|
||||||
@@ -174,7 +140,7 @@ namespace tc {
|
|||||||
if (target_row.lst_ptrs[table_idx] == nullptr) {
|
if (target_row.lst_ptrs[table_idx] == nullptr) {
|
||||||
if ((cosets.get(target, ti.gens[0]) != target) and
|
if ((cosets.get(target, ti.gens[0]) != target) and
|
||||||
(cosets.get(target, ti.gens[1]) != target)) {
|
(cosets.get(target, ti.gens[1]) != target)) {
|
||||||
target_row.lst_ptrs[table_idx] = new int;
|
target_row.lst_ptrs[table_idx] = new int; // todo slow; memory leak.
|
||||||
target_row.gnrs[table_idx] = 0;
|
target_row.gnrs[table_idx] = 0;
|
||||||
} else {
|
} else {
|
||||||
target_row.lst_ptrs[table_idx] = &null_lst_ptr;
|
target_row.lst_ptrs[table_idx] = &null_lst_ptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user