Browse Source

feat: support furthest cases search

master
Dnomd343 2 years ago
parent
commit
02b671954f
  1. 50
      src/fast_cal/fast_cal.cc
  2. 8
      src/fast_cal/fast_cal.h
  3. 2
      src/main.cc

50
src/fast_cal/fast_cal.cc

@ -135,6 +135,56 @@ std::vector<uint64_t> FastCal::target_multi(uint64_t code, const FastCal::check_
}
std::vector<uint64_t> 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<uint64_t> 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;
}

8
src/fast_cal/fast_cal.h

@ -11,6 +11,8 @@ public:
typedef std::function<bool(uint64_t)> 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<uint64_t> solve_multi(uint64_t code);
std::vector<uint64_t> target_multi(uint64_t code, const check_t &match);
std::vector<uint64_t> furthest(uint64_t code);
std::vector<uint64_t> backtrack(uint64_t code);
// TODO: static search functions
const static auto NOT_FOUND = (uint64_t)0;
private:
struct fast_cal_t {

2
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();

Loading…
Cancel
Save