use unordered_set for stat_pool to speed up
This commit is contained in:
1 parent
d441982dad
commit
8f0cc306b5
2 files changed
+24
-14
No files matched your search
+12
-12
@@ -9,6 +9,7 @@
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#define CELL_SIZE 8
|
||||
@@ -35,8 +36,6 @@ using ins_body = std::bitset<INS_SIZE>;
|
||||
using ins_bytecode = std::bitset<INS_BYTECODE_SIZE>;
|
||||
*/
|
||||
|
||||
static std::set<stat> stat_pool;
|
||||
|
||||
enum ins_opcode {
|
||||
SET1 = 0,
|
||||
FLIP = 1,
|
||||
@@ -77,18 +76,18 @@ static const std::set<r8veritas::ins> 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<r8veritas::stat> {
|
||||
size_t operator()(const r8veritas::stat &s) const {
|
||||
size_t h=0;
|
||||
for(auto i:s){
|
||||
h ^= hash<r8veritas::cell>{}(i) + 0x9e3779b9 + (h<<6) + (h>>2);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
};
|
||||
|
||||
// Overload hash to make some unordered_maps work.
|
||||
template <> struct hash<pair<r8veritas::stat_ref, r8veritas::ins_bytecode>> {
|
||||
// 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<r8veritas::stat> stat_pool;
|
||||
#endif
|
||||
+12
-2
@@ -7,9 +7,18 @@
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
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]++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user