From c3423764b281446c13c36bfe3d66fcbd7b468bb7 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Jan 2023 15:40:10 +0800 Subject: [PATCH] perf: callback function in FastCal --- src/fast_cal/fast_cal.cc | 37 +++++++++++++++---------------------- src/fast_cal/fast_cal.h | 2 +- src/main.cc | 15 --------------- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 5842549..71d7cbb 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -6,13 +6,25 @@ #include -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(code), std::forward(mask)); + new_case(std::forward(code), std::forward(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]); - -} diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index f8dbc68..5d8108f 100644 --- a/src/fast_cal/fast_cal.h +++ b/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); }; diff --git a/src/main.cc b/src/main.cc index 5154e46..f077aec 100644 --- a/src/main.cc +++ b/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; }