Browse Source

feat: build total search tree for FastCal

legacy
Dnomd343 2 years ago
parent
commit
91225ce0ce
  1. 16
      src/fast_cal/cal_core.cc
  2. 2
      src/fast_cal/fast_cal.h
  3. 7
      src/main.cc

16
src/fast_cal/cal_core.cc

@ -36,10 +36,20 @@ void FastCal::new_case(uint64_t code, uint64_t mask) {
}).first->second); }).first->second);
} }
/// build total search tree
void FastCal::build(const RawCode &code) {
auto core = init((uint64_t)code);
/// start BFS search
while (!cache.empty()) {
core.next_cases(cache.front()->code, cache.front()->mask);
cache.pop();
}
}
/// found first matched target /// found first matched target
RawCode FastCal::target(const RawCode &code, const match_t &match) { RawCode FastCal::target(const RawCode &code, const match_t &match) {
auto core = init((uint64_t)code); auto core = init((uint64_t)code);
/// start bfs search /// start BFS search
while (!cache.empty()) { while (!cache.empty()) {
if (match(cache.front()->code)) { if (match(cache.front()->code)) {
return RawCode::unsafe_create(cache.front()->code); // match target return RawCode::unsafe_create(cache.front()->code); // match target
@ -55,7 +65,7 @@ std::vector<RawCode> FastCal::target_multi(const RawCode &code, const match_t &m
auto core = init((uint64_t)code); auto core = init((uint64_t)code);
auto layer_end = cache.back(); auto layer_end = cache.back();
std::vector<RawCode> matched; // matched list std::vector<RawCode> matched; // matched list
/// start bfs search /// start BFS search
while (!cache.empty()) { while (!cache.empty()) {
if (match(cache.front()->code)) { // match target if (match(cache.front()->code)) { // match target
matched.emplace_back(cache.front()->code); matched.emplace_back(cache.front()->code);
@ -77,7 +87,7 @@ std::vector<RawCode> FastCal::furthest(const RawCode &code) {
auto core = init((uint64_t)code); auto core = init((uint64_t)code);
auto layer_end = cache.back(); auto layer_end = cache.back();
std::vector<RawCode> layer_cases; std::vector<RawCode> layer_cases;
/// start bfs search /// start BFS search
while (!cache.empty()) { while (!cache.empty()) {
core.next_cases(cache.front()->code, cache.front()->mask); core.next_cases(cache.front()->code, cache.front()->mask);
layer_cases.emplace_back( layer_cases.emplace_back(

2
src/fast_cal/fast_cal.h

@ -20,7 +20,7 @@ public:
std::vector<RawCode> backtrack(const RawCode &code); std::vector<RawCode> backtrack(const RawCode &code);
/// BFS search functions /// BFS search functions
// TODO: build function with void return -> build total tree void build(const RawCode &code);
RawCode solve(const RawCode &code); RawCode solve(const RawCode &code);
std::vector<RawCode> furthest(const RawCode &code); std::vector<RawCode> furthest(const RawCode &code);
std::vector<RawCode> solve_multi(const RawCode &code); std::vector<RawCode> solve_multi(const RawCode &code);

7
src/main.cc

@ -25,7 +25,8 @@ int main() {
// AllCases::build(); // AllCases::build();
// auto f = FastCal(); auto f = FastCal();
f.build(RawCode::from_common_code("1a9bf0c"));
// auto ret = f.solve(RawCode::from_common_code("1a9bf0c")); // auto ret = f.solve(RawCode::from_common_code("1a9bf0c"));
// auto ret = f.target(RawCode::from_common_code("1a9bf0c"), [](uint64_t code) { // auto ret = f.target(RawCode::from_common_code("1a9bf0c"), [](uint64_t code) {
@ -44,9 +45,9 @@ 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::to_furthest(RawCode::from_common_code("1a9bf0c"))) { // for (const auto &s : FastCal::to_furthest(RawCode::from_common_code("1a9bf0c"))) {
// for (const auto &c : s) { // for (const auto &c : s) {

Loading…
Cancel
Save