diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 866dd14..6a01d04 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -135,6 +135,56 @@ std::vector FastCal::target_multi(uint64_t code, const FastCal::check_ } +std::vector FastCal::furthest(uint64_t code) { + + auto core = init(); + + cache.emplace(&cases.emplace(code, fast_cal_t { + .code = code, + .mask = 0, + .last = nullptr, // without parent node + }).first->second); + + auto layer_end = cache.back(); + + int layer_num = 0; + + std::vector layer_cases; + + while (!cache.empty()) { + + core.next_cases(cache.front()->code, cache.front()->mask); + + layer_cases.emplace_back(cache.front()->code); + + if (cache.front() == layer_end) { + + std::cout << "layer size -> " << layer_cases.size() << std::endl; + std::cout << "reach layer " << layer_num << " ending -> " << cache.size() << std::endl; + + if (cache.size() == 1) { // almost exit -> last layer + break; +// return layer_cases; + + } + + layer_cases.clear(); + + ++layer_num; + + layer_end = cache.back(); + + } + + cache.pop(); + + } + + + return layer_cases; + +} + diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index a04ac0c..2f2a027 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -11,6 +11,8 @@ public: typedef std::function check_t; + const static auto NOT_FOUND = (uint64_t)0; + // explicit FastCal(uint64_t code) : root(code) {} // search resolve @@ -23,18 +25,22 @@ public: // solve_multi + // TODO: shall we using RawCode instead of uint64_t? + uint64_t solve(uint64_t code); uint64_t target(uint64_t code, const check_t &match); std::vector solve_multi(uint64_t code); + std::vector target_multi(uint64_t code, const check_t &match); + std::vector furthest(uint64_t code); + std::vector backtrack(uint64_t code); // TODO: static search functions - const static auto NOT_FOUND = (uint64_t)0; private: struct fast_cal_t { diff --git a/src/main.cc b/src/main.cc index 01daf99..08f4b81 100644 --- a/src/main.cc +++ b/src/main.cc @@ -27,7 +27,7 @@ int main() { auto f = FastCal(); // auto ret = f.solve((uint64_t)RawCode::from_common_code("1a9bf0c")); - auto ret = f.solve_multi((uint64_t)RawCode::from_common_code("1a9bf0c")); + auto ret = f.furthest((uint64_t)RawCode::from_common_code("1a9bf0c")); // auto f = FastCal(RawCode::from_common_code("1a9bf0c").unwrap()); // auto ret = f.solve();