Browse Source

feat: try unordered_map emplace return pointer

legacy
Dnomd343 2 years ago
parent
commit
a4be65c4d9
  1. 43
      src/fast_cal/fast_cal.cc

43
src/fast_cal/fast_cal.cc

@ -12,12 +12,33 @@ void FastCal::new_case(uint64_t code, uint64_t mask) { // callback function for
current->second.mask |= mask; // update mask info current->second.mask |= mask; // update mask info
return; return;
} }
cases[code] = fast_cal_t { // insert into cases map
cache.emplace(&cases.emplace(code, fast_cal_t {
.code = code, .code = code,
.mask = mask, .mask = mask,
.last = cache.front(), // parent case .last = cache.front(),
}; }).first->second);
cache.emplace(&cases[code]); // add in working queue
// auto insert_ret = cases.emplace(code, fast_cal_t {
// .code = code,
// .mask = mask,
// .last = cache.front(),
// });
//
// if (insert_ret.second) { // insert success
// cache.emplace(&insert_ret.first->second);
// } else {
// insert_ret.first->second.mask |= mask;
// }
// cases[code] = fast_cal_t { // insert into cases map
// .code = code,
// .mask = mask,
// .last = cache.front(), // parent case
// };
// cache.emplace(&cases[code]); // add in working queue
} }
void FastCal::fast_cal(uint64_t code) { void FastCal::fast_cal(uint64_t code) {
@ -31,12 +52,18 @@ void FastCal::fast_cal(uint64_t code) {
cases.empty(); cases.empty();
cache.empty(); cache.empty();
cases[code] = fast_cal_t { // cases[code] = fast_cal_t {
// .code = code,
// .mask = 0,
// .last = nullptr,
// };
// cache.emplace(&cases[code]);
cache.emplace(&cases.emplace(code, fast_cal_t {
.code = code, .code = code,
.mask = 0, .mask = 0,
.last = nullptr, .last = nullptr,
}; }).first->second);
cache.emplace(&cases[code]);
while (!cache.empty()) { while (!cache.empty()) {
@ -51,6 +78,8 @@ void FastCal::fast_cal(uint64_t code) {
cache.pop(); cache.pop();
} }
std::cout << "size: " << cases.size() << std::endl;
auto solution = cache.front(); auto solution = cache.front();
while (solution != nullptr) { while (solution != nullptr) {

Loading…
Cancel
Save