diff --git a/src/fast_cal/cal_core.cc b/src/fast_cal/cal_core.cc index 039c10c..2388c4d 100644 --- a/src/fast_cal/cal_core.cc +++ b/src/fast_cal/cal_core.cc @@ -2,13 +2,11 @@ #include "fast_cal.h" Core FastCal::init(uint64_t code) { // initialize process - /// clear working data + /// reset working data cases.clear(); + cases.reserve(FC_MAP_RESERVE); // hashmap pre-reserve std::queue{}.swap(cache); - // TODO: test the speed without hashmap reserve - cases.reserve(65536); - /// insert root node cache.emplace(&cases.emplace(code, fast_cal_t { .code = code, @@ -39,7 +37,7 @@ void FastCal::new_case(uint64_t code, uint64_t mask) { } /// found first matched target -RawCode FastCal::target(RawCode code, const check_t &match) { +RawCode FastCal::target(RawCode code, const match_t &match) { auto core = init((uint64_t)code); /// start bfs search while (!cache.empty()) { @@ -53,7 +51,7 @@ RawCode FastCal::target(RawCode code, const check_t &match) { } /// found multi-targets matched in first same layer -std::vector FastCal::target_multi(RawCode code, const check_t &match) { +std::vector FastCal::target_multi(RawCode code, const match_t &match) { auto core = init((uint64_t)code); auto layer_end = cache.back(); std::vector matched; // matched list diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index 46b3f2f..50e72e7 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -6,27 +6,25 @@ #include #include "raw_code.h" +const uint32_t FC_MAP_RESERVE = 65536; + /// FastCal not found -> return invalid raw code const RawCode FC_NOT_FOUND = RawCode::unsafe_create(0); class FastCal { public: - const static auto NOT_FOUND = (uint64_t)0; - typedef std::function check_t; - -// const static RawCode *test = (RawCode*)nullptr; + typedef std::function match_t; /// xxx_multi only search until same layer - // TODO: shall we use RawCode instead of uint64_t? - + /// BFS search functions RawCode solve(RawCode code); - RawCode target(RawCode code, const check_t &match); - std::vector furthest(RawCode code); - std::vector solve_multi(RawCode code); - std::vector target_multi(RawCode code, const check_t &match); + RawCode target(RawCode code, const match_t &match); + std::vector target_multi(RawCode code, const match_t &match); + + // TODO: search / search_multi / resolve / resolve_multi // TODO: static furthest function diff --git a/src/main.cc b/src/main.cc index 2759ee3..0b1dad2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -15,20 +15,20 @@ int main() { -// BasicRanges::build(); + BasicRanges::build(); // std::cout << "wait 3s" << std::endl; // sleep(3); -// std::cout << "start benchmark" << std::endl; + std::cout << "start benchmark" << std::endl; auto start_time = clock(); // AllCases::build(); auto f = FastCal(); // auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); -// auto ret = f.solve(RawCode::from_common_code("1a9bf0c")); - auto ret = f.solve(RawCode::from_common_code("1aaef0c")); + auto ret = f.solve(RawCode::from_common_code("1a9bf0c")); +// auto ret = f.solve(RawCode::from_common_code("1aaef0c")); if (ret == FC_NOT_FOUND) { std::cout << "not found" << std::endl;