diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index ecec5af..e981b7b 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -31,7 +31,7 @@ int FastCal::step_num(RawCode code) { return num; } -std::vector FastCal::backtrack(RawCode code) { +std::vector FastCal::backtrack(const RawCode &code) { auto tmp = cases.find((uint64_t)code); if (tmp == cases.end()) { return std::vector{}; // code not exist @@ -50,7 +50,11 @@ std::vector FastCal::resolve(RawCode start) { return FastCal::search(start, resolved); } -std::vector FastCal::search(RawCode start, const FastCal::match_t &match) { +std::vector> FastCal::resolve_multi(RawCode start) { + return FastCal::search_multi(start, resolved); +} + +std::vector FastCal::search(RawCode start, const match_t &match) { auto fc = FastCal(); auto result = fc.target(start, match); if (result == FC_NOT_FOUND) { @@ -58,3 +62,12 @@ std::vector FastCal::search(RawCode start, const FastCal::match_t &matc } return fc.backtrack(result); // backtrack target path } + +std::vector> FastCal::search_multi(RawCode start, const match_t &match) { + auto fc = FastCal(); + std::vector> result; + for (const auto &c : fc.target_multi(start, match)) { + result.emplace_back(fc.backtrack(c)); // backtrack every target + } + return result; +} diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index d5af9c7..22e2b2d 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -17,7 +17,7 @@ public: /// backtrack functions int step_num(RawCode code); - std::vector backtrack(RawCode code); + std::vector backtrack(const RawCode &code); /// BFS search functions // TODO: build function with void return -> build total tree @@ -28,13 +28,14 @@ public: std::vector target_multi(RawCode code, const match_t &match); /// static BFS search functions + // TODO: (RawCode code) -> (const RawCode &code) // static std::vector get_furthest(RawCode start); static std::vector resolve(RawCode start); static std::vector search(RawCode start, const match_t &match); -// static std::vector> resolve_multi(RawCode start); -// static std::vector> search_multi(RawCode start, const match_t &match); + static std::vector> resolve_multi(RawCode start); + static std::vector> search_multi(RawCode start, const match_t &match); private: struct fast_cal_t { diff --git a/src/main.cc b/src/main.cc index 416f42a..8d03fc6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -45,10 +45,16 @@ int main() { // std::cout << "step number: " << f.step_num(ret) << std::endl; // } - for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) { - std::cout << c << std::endl; - } +// for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) { +// std::cout << c << std::endl; +// } + for (const auto &s : FastCal::resolve_multi(RawCode::from_common_code("1a9bf0c"))) { +// for (const auto &c : s) { +// std::cout << c << std::endl; +// } +// std::cout << "--------------------------------------------" << std::endl; + } // std::cout << f.step_num(ret) << std::endl;