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;
};
std::unordered_map<uint64_t, fast_cal_t> cal_data;
//std::unordered_map<uint64_t, fast_cal_t*> cal_data;
std::queue<fast_cal_t*> cal_temp;
std::queue<fast_cal_t*> cache;
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();
// 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;
void add_new_case(uint64_t code, uint64_t mask) {
auto exist_case = cal_data.find(code);
if (exist_case != cal_data.end()) { // find it
auto exist_case = cases.find(code);
if (exist_case != cases.end()) { // find existed case
exist_case->second.mask |= mask; // mask update
// exist_case->second->mask |= mask; // mask update
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 {
// auto new_case = new fast_cal_t {
cases[code] = fast_cal_t {
.code = code,
.mask = mask,
};
cal_data[code] = new_case;
// TODO: avoid redundancy map search
cal_temp.emplace(&cal_data[code]);
// cal_temp.emplace(new_case);
};;
cache.emplace(&cases[code]);
}
uint32_t fast_cal(uint64_t start_raw_code) {
// std::cout << RawCode(start_raw_code).dump_case() << std::endl;
uint32_t fast_cal(uint64_t code) {
auto core = Core(add_new_case);
cal_data.empty();
cases.empty();
auto setup = fast_cal_t {
.code = start_raw_code,
cases[code] = fast_cal_t {
.code = code,
.mask = 0,
};
cache.emplace(&cases[code]);
cal_data[start_raw_code] = setup;
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 (!cache.empty()) {
while (!cal_temp.empty()) {
if (((cal_temp.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) {
std::cout << "get resolve" << std::endl;
std::cout << RawCode(cal_temp.front()->code).dump_case() << std::endl;
if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) {
std::cout << "Resolve" << std::endl;
std::cout << RawCode(cache.front()->code).dump_case() << std::endl;
break;
}
core.next_step(cal_temp.front()->code, cal_temp.front()->mask);
cal_temp.pop();
core.next_step(cache.front()->code, cache.front()->mask);
cache.pop();
}
// core.next_step(cal_temp.front()->code, cal_temp.front()->mask);
// 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();
return cases.size();
}

2
src/fast_cal.h

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

Loading…
Cancel
Save