Browse Source

feat: static multi resolve function for FastCal

legacy
Dnomd343 2 years ago
parent
commit
6fd09be214
  1. 17
      src/fast_cal/fast_cal.cc
  2. 7
      src/fast_cal/fast_cal.h
  3. 12
      src/main.cc

17
src/fast_cal/fast_cal.cc

@ -31,7 +31,7 @@ int FastCal::step_num(RawCode code) {
return num; return num;
} }
std::vector<RawCode> FastCal::backtrack(RawCode code) { std::vector<RawCode> FastCal::backtrack(const RawCode &code) {
auto tmp = cases.find((uint64_t)code); auto tmp = cases.find((uint64_t)code);
if (tmp == cases.end()) { if (tmp == cases.end()) {
return std::vector<RawCode>{}; // code not exist return std::vector<RawCode>{}; // code not exist
@ -50,7 +50,11 @@ std::vector<RawCode> FastCal::resolve(RawCode start) {
return FastCal::search(start, resolved); return FastCal::search(start, resolved);
} }
std::vector<RawCode> FastCal::search(RawCode start, const FastCal::match_t &match) { std::vector<std::vector<RawCode>> FastCal::resolve_multi(RawCode start) {
return FastCal::search_multi(start, resolved);
}
std::vector<RawCode> FastCal::search(RawCode start, const match_t &match) {
auto fc = FastCal(); auto fc = FastCal();
auto result = fc.target(start, match); auto result = fc.target(start, match);
if (result == FC_NOT_FOUND) { if (result == FC_NOT_FOUND) {
@ -58,3 +62,12 @@ std::vector<RawCode> FastCal::search(RawCode start, const FastCal::match_t &matc
} }
return fc.backtrack(result); // backtrack target path return fc.backtrack(result); // backtrack target path
} }
std::vector<std::vector<RawCode>> FastCal::search_multi(RawCode start, const match_t &match) {
auto fc = FastCal();
std::vector<std::vector<RawCode>> result;
for (const auto &c : fc.target_multi(start, match)) {
result.emplace_back(fc.backtrack(c)); // backtrack every target
}
return result;
}

7
src/fast_cal/fast_cal.h

@ -17,7 +17,7 @@ public:
/// backtrack functions /// backtrack functions
int step_num(RawCode code); int step_num(RawCode code);
std::vector<RawCode> backtrack(RawCode code); std::vector<RawCode> backtrack(const RawCode &code);
/// BFS search functions /// BFS search functions
// TODO: build function with void return -> build total tree // TODO: build function with void return -> build total tree
@ -28,13 +28,14 @@ public:
std::vector<RawCode> target_multi(RawCode code, const match_t &match); std::vector<RawCode> target_multi(RawCode code, const match_t &match);
/// static BFS search functions /// static BFS search functions
// TODO: (RawCode code) -> (const RawCode &code)
// static std::vector<RawCode> get_furthest(RawCode start); // static std::vector<RawCode> get_furthest(RawCode start);
static std::vector<RawCode> resolve(RawCode start); static std::vector<RawCode> resolve(RawCode start);
static std::vector<RawCode> search(RawCode start, const match_t &match); static std::vector<RawCode> search(RawCode start, const match_t &match);
// static std::vector<std::vector<RawCode>> resolve_multi(RawCode start); static std::vector<std::vector<RawCode>> resolve_multi(RawCode start);
// static std::vector<std::vector<RawCode>> search_multi(RawCode start, const match_t &match); static std::vector<std::vector<RawCode>> search_multi(RawCode start, const match_t &match);
private: private:
struct fast_cal_t { struct fast_cal_t {

12
src/main.cc

@ -45,10 +45,16 @@ int main() {
// std::cout << "step number: " << f.step_num(ret) << std::endl; // std::cout << "step number: " << f.step_num(ret) << std::endl;
// } // }
for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) { // for (const auto &c : FastCal::resolve(RawCode::from_common_code("1a9bf0c"))) {
std::cout << c << std::endl; // 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; // std::cout << f.step_num(ret) << std::endl;

Loading…
Cancel
Save