From e5427a8ffe874496ee4dc619ae8967a03e83f4a0 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 19 Jan 2023 21:09:53 +0800 Subject: [PATCH] feat: layer data export --- src/analyse/analyse.cc | 23 +++++++++++++++++++++++ src/analyse/analyse.h | 4 ++++ src/main.cc | 20 +++++++++----------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/analyse/analyse.cc b/src/analyse/analyse.cc index 46e4969..2dbbb68 100644 --- a/src/analyse/analyse.cc +++ b/src/analyse/analyse.cc @@ -8,6 +8,29 @@ void Analyse::set_root(const RawCode &code) { this->root = (uint64_t)code; } +std::vector Analyse::layer_export(uint32_t layer_num) { + std::vector layer_cases; + for (const auto &tmp : cases) { // traverse every cases + if (tmp.second.step == layer_num) { + layer_cases.emplace_back(RawCode::unsafe_create(tmp.first)); + } + } + return layer_cases; +} + +std::vector> Analyse::layer_export() { + std::vector> layer_cases; + for (const auto &tmp : cases) { // traverse every cases + if (tmp.second.step >= layer_cases.size()) { + layer_cases.resize(tmp.second.step + 1); + } + layer_cases[tmp.second.step].emplace_back( + RawCode::unsafe_create(tmp.first) // insert at target layer + ); + } + return layer_cases; +} + /// memory initialize and return klotski core Core Analyse::init(uint64_t code) { /// reset working data diff --git a/src/analyse/analyse.h b/src/analyse/analyse.h index 474ad52..883e1c0 100644 --- a/src/analyse/analyse.h +++ b/src/analyse/analyse.h @@ -22,6 +22,10 @@ public: void build(); std::vector build_until(const match_t &match); + /// analysed layer export + std::vector> layer_export(); + std::vector layer_export(uint32_t layer_num); + private: struct analyse_t { uint64_t code; diff --git a/src/main.cc b/src/main.cc index d061092..24f97ad 100644 --- a/src/main.cc +++ b/src/main.cc @@ -41,7 +41,7 @@ int main() { // sleep(3); // std::cout << "start benchmark" << std::endl; - auto start_time = clock(); +// auto start_time = clock(); // { @@ -54,21 +54,19 @@ int main() { auto a = Analyse(RawCode::from_common_code("1a9bf0c")); -// a.build(); - auto ret = a.build_until([](uint64_t code) { - return ((code >> (3 * 0xD)) & 0b111) == B_2x2; - }); - for (const auto &r : ret) { - std::cout << r << std::endl; - } - -// auto ret = a.build_until((uint64_t)RawCode::from_common_code("1a9bf0c"), [](uint64_t code) { + a.build(); +// auto ret = a.build_until([](uint64_t code) { // return ((code >> (3 * 0xD)) & 0b111) == B_2x2; // }); // for (const auto &r : ret) { -// std::cout << RawCode(r) << std::endl; +// std::cout << r << std::endl; // } + auto start_time = clock(); + + std::cout << a.layer_export(81).size() << std::endl; + std::cout << a.layer_export()[81].size() << std::endl; + // auto raw_code = CommonCode("A5D3AF0").to_raw_code().unwrap(); // auto a = Analyse();