diff --git a/include/r8veritas.hh b/include/r8veritas.hh index 01467d2..669c526 100644 --- a/include/r8veritas.hh +++ b/include/r8veritas.hh @@ -9,6 +9,7 @@ #include #include #include +#include #include #define CELL_SIZE 8 @@ -35,8 +36,6 @@ using ins_body = std::bitset; using ins_bytecode = std::bitset; */ -static std::set stat_pool; - enum ins_opcode { SET1 = 0, FLIP = 1, @@ -77,18 +76,18 @@ static const std::set all_ins = }(); } // namespace r8veritas - -inline r8veritas::stat_ref generate_empty_stat() { - r8veritas::stat arr; - for (r8veritas::index i = 0; i < (1 << CELL_SIZE); i++) { - arr[i] = 0; - } - auto tmp_ptr = r8veritas::stat_pool.insert(std::move(arr)).first; - return &(*tmp_ptr); -} - namespace std { +template <> struct hash { + size_t operator()(const r8veritas::stat &s) const { + size_t h=0; + for(auto i:s){ + h ^= hash{}(i) + 0x9e3779b9 + (h<<6) + (h>>2); + } + return h; + } +}; + // Overload hash to make some unordered_maps work. template <> struct hash> { // Yep,magic again. @@ -133,4 +132,5 @@ r8veritas::path track_path(const r8veritas::truthtable &truthtable); std::ostream &operator<<(std::ostream &os, const r8veritas::stat_ref &s); std::ostream &operator<<(std::ostream &os, const r8veritas::ins &s); +static std::unordered_set stat_pool; #endif \ No newline at end of file diff --git a/src/r8veritas.cc b/src/r8veritas.cc index 8a15055..0fab780 100644 --- a/src/r8veritas.cc +++ b/src/r8veritas.cc @@ -7,9 +7,18 @@ #include #include +r8veritas::stat_ref generate_empty_stat() { + r8veritas::stat arr; + for (r8veritas::index i = 0; i < (1 << CELL_SIZE); i++) { + arr[i] = 0; + } + auto tmp_ptr = stat_pool.insert(std::move(arr)).first; + return &(*tmp_ptr); +} + // WARNING:ST WILL BE DESTROYED r8veritas::stat_ref save_stat(r8veritas::stat &&st) { - return &(*r8veritas::stat_pool.insert(std::move(st)).first); + return &(*stat_pool.insert(std::move(st)).first); } r8veritas::truthtable generate_truthtable(const r8veritas::op &operation) { @@ -86,7 +95,8 @@ compress_stat_space(const r8veritas::truthtable &raw_truthtable) { for (r8veritas::index i = 0; i < CELL_SIZE; i++) { influences[i] = 0; for (r8veritas::index j = 0; j < (1 << CELL_SIZE); j++) { - if ((*(raw_truthtable.second))[j] != (*(raw_truthtable.second))[j ^ (1 << i)]) { + if ((*(raw_truthtable.second))[j] != + (*(raw_truthtable.second))[j ^ (1 << i)]) { influences[i]++; } }