Browse Source

perf: callback function in FastCal

master
Dnomd343 2 years ago
parent
commit
c3423764b2
  1. 37
      src/fast_cal/fast_cal.cc
  2. 2
      src/fast_cal/fast_cal.h
  3. 15
      src/main.cc

37
src/fast_cal/fast_cal.cc

@ -6,13 +6,25 @@
#include <iostream>
void FastCal::fast_cal(uint64_t code) {
void FastCal::new_case(uint64_t code, uint64_t mask) { // callback function for new case
auto current = cases.find(code);
if (current != cases.end()) { // find existed case
current->second.mask |= mask; // update mask info
return;
}
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
}
// std::cout << RawCode(code).dump_case() << std::endl;
void FastCal::fast_cal(uint64_t code) {
auto core = Core(
[this](auto &&code, auto &&mask) { // lambda as function pointer
add_new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask));
new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask));
}
);
@ -47,22 +59,3 @@ void FastCal::fast_cal(uint64_t code) {
}
}
void FastCal::add_new_case(uint64_t code, uint64_t mask) {
auto exist_case = cases.find(code);
if (exist_case != cases.end()) { // find existed case
exist_case->second.mask |= mask; // mask update
return;
}
cases[code] = fast_cal_t {
.code = code,
.mask = mask,
.last = cache.front(),
};
cache.emplace(&cases[code]);
}

2
src/fast_cal/fast_cal.h

@ -17,6 +17,6 @@ public:
void fast_cal(uint64_t code);
void add_new_case(uint64_t code, uint64_t mask);
void new_case(uint64_t code, uint64_t mask);
};

15
src/main.cc

@ -211,24 +211,9 @@ int main() {
// }
// BasicRanges::build();
// for (auto const &range : *BasicRanges::fetch()) {
// printf("%08X\n", range);
// }
// AllCases::build();
// for (uint32_t head = 0; head < 16; ++head) {
// uint64_t prefix = (uint64_t)head << 32;
// for (auto const &range : (*AllCases::fetch())[head]) {
// printf("%09lX\n", prefix | range);
// }
// }
// std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl;
std::cout << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl;
// std::cout << "complete benchmark" << std::endl;
// while(1);
return 0;
}

Loading…
Cancel
Save