Browse Source

update: fast_cal process

legacy
Dnomd343 2 years ago
parent
commit
1a66213589
  1. 82
      src/fast_cal.cc
  2. 2
      src/fast_cal.h

82
src/fast_cal.cc

@ -12,91 +12,51 @@ struct fast_cal_t {
// uint32_t step; // uint32_t step;
}; };
std::unordered_map<uint64_t, fast_cal_t> cal_data; std::queue<fast_cal_t*> cache;
//std::unordered_map<uint64_t, fast_cal_t*> cal_data;
std::queue<fast_cal_t*> cal_temp;
void add_new_case(uint64_t code, uint64_t mask) { std::unordered_map<uint64_t, fast_cal_t> cases;
// std::cout << RawCode(code).dump_case(); void add_new_case(uint64_t code, uint64_t mask) {
// std::cout << "~~~~~~~" << std::endl;
// auto temp_mask = mask;
// for (int n = 0; n < 20; ++n, temp_mask >>= 3) {
// std::cout << "+."[!(temp_mask & 0b111)] << " \n"[!(~n & 0b11)];
// }
// std::cout << std::endl;
auto exist_case = cal_data.find(code); auto exist_case = cases.find(code);
if (exist_case != cal_data.end()) { // find it if (exist_case != cases.end()) { // find existed case
exist_case->second.mask |= mask; // mask update exist_case->second.mask |= mask; // mask update
// exist_case->second->mask |= mask; // mask update
return; return;
}
// std::cout << RawCode(code).dump_case(); }
// std::cout << "~~~~~~~" << std::endl;
// auto temp_mask = mask;
// for (int n = 0; n < 20; ++n, temp_mask >>= 3) {
// std::cout << "+."[!(temp_mask & 0b111)] << " \n"[!(~n & 0b11)];
// }
// std::cout << std::endl;
auto new_case = fast_cal_t { cases[code] = fast_cal_t {
// auto new_case = new fast_cal_t {
.code = code, .code = code,
.mask = mask, .mask = mask,
}; };;
cache.emplace(&cases[code]);
cal_data[code] = new_case;
// TODO: avoid redundancy map search
cal_temp.emplace(&cal_data[code]);
// cal_temp.emplace(new_case);
} }
uint32_t fast_cal(uint64_t start_raw_code) { uint32_t fast_cal(uint64_t code) {
// std::cout << RawCode(start_raw_code).dump_case() << std::endl;
auto core = Core(add_new_case); auto core = Core(add_new_case);
cal_data.empty(); cases.empty();
auto setup = fast_cal_t { cases[code] = fast_cal_t {
.code = start_raw_code, .code = code,
.mask = 0, .mask = 0,
}; };
cache.emplace(&cases[code]);
cal_data[start_raw_code] = setup; while (!cache.empty()) {
cal_temp.emplace(&cal_data[start_raw_code]);
// TODO: setup should not be stack var
// cal_data[start_raw_code] = &setup;
// cal_temp.emplace(&setup);
while (!cal_temp.empty()) { if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) {
std::cout << "Resolve" << std::endl;
if (((cal_temp.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) { std::cout << RawCode(cache.front()->code).dump_case() << std::endl;
std::cout << "get resolve" << std::endl;
std::cout << RawCode(cal_temp.front()->code).dump_case() << std::endl;
break; break;
} }
core.next_step(cal_temp.front()->code, cal_temp.front()->mask); core.next_step(cache.front()->code, cache.front()->mask);
cal_temp.pop(); cache.pop();
} }
// core.next_step(cal_temp.front()->code, cal_temp.front()->mask); return cases.size();
// cal_temp.pop();
//
// core.next_step(cal_temp.front()->code, cal_temp.front()->mask);
// cal_temp.pop();
// std::cout << "size = " << cal_data.size() << std::endl;
// std::cout << "queue size = " << cal_temp.size() << std::endl;
return cal_data.size();
} }

2
src/fast_cal.h

@ -2,4 +2,4 @@
#include <cstdint> #include <cstdint>
uint32_t fast_cal(uint64_t start_raw_code); uint32_t fast_cal(uint64_t start_code);

Loading…
Cancel
Save