From addce4668dd3f2873184e37a32acf03d937e85e0 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 13 Jan 2023 15:04:09 +0800 Subject: [PATCH] feat: backtrack graph build --- src/analyse/analyse.cc | 65 ++++++++++++++++++++++++++++++++++++++---- src/analyse/analyse.h | 10 +++++-- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/analyse/analyse.cc b/src/analyse/analyse.cc index 2a51ad9..5fa80b7 100644 --- a/src/analyse/analyse.cc +++ b/src/analyse/analyse.cc @@ -1,6 +1,8 @@ +#include #include "core.h" #include "analyse.h" +#include #include #include "raw_code.h" @@ -17,12 +19,65 @@ void Analyse::backtrack(uint64_t code) { // backtrack start at code std::cout << "start backtrack" << std::endl; - std::cout << RawCode(code).dump_case() << std::endl; - std::cout << "src size: " << cases[code].src.size() << std::endl; +// std::cout << RawCode(code).dump_case() << std::endl; +// std::cout << "src size: " << cases[code].src.size() << std::endl; +// +// auto last_1 = cases[code].src.front(); +// std::cout << RawCode(last_1->code).dump_case() << std::endl; +// std::cout << "src size: " << last_1->src.size() << std::endl; + + + std::vector track_data; + + std::queue track_cache; + + // TODO: confirm that code exist + + track_cache.emplace(&cases[code]); + track_data.emplace_back(new backtrack_t { + .code = code, +// .next = nullptr, + .next = std::list{}, // without next cases + }); + + auto me = 0; + + for (;;) { + + if (track_cache.front()->src.empty()) { + break; + } + + for (auto t : track_cache.front()->src) { + track_cache.emplace(t); + track_data.emplace_back(new backtrack_t { + .code = t->code, + .layer_num = track_cache.front()->step - 1, + .next = std::list{track_data[me]}, + }); + } + track_cache.pop(); + ++me; + + } + + std::cout << "size: " << track_data.size() << std::endl; + + auto root = track_data.back(); + + std::cout << "layer " << root->layer_num << std::endl; + std::cout << RawCode(root->code).dump_case() << std::endl; + + for (auto t : root->next) { + std::cout << "layer " << t->layer_num << std::endl; + std::cout << RawCode(t->code).dump_case() << std::endl; + } + + for (auto t : root->next.front()->next) { + std::cout << "layer " << t->layer_num << std::endl; + std::cout << RawCode(t->code).dump_case() << std::endl; + } - auto last_1 = cases[code].src.front(); - std::cout << RawCode(last_1->code).dump_case() << std::endl; - std::cout << "src size: " << last_1->src.size() << std::endl; } diff --git a/src/analyse/analyse.h b/src/analyse/analyse.h index 92adc3d..23a3927 100644 --- a/src/analyse/analyse.h +++ b/src/analyse/analyse.h @@ -4,9 +4,9 @@ #include #include -#include +//#include #include -#include +//#include class Analyse { public: @@ -14,7 +14,7 @@ public: uint64_t code; uint64_t mask; - int step; + uint32_t step; // bool highlight; @@ -26,6 +26,10 @@ public: struct backtrack_t { uint64_t code; + + uint32_t layer_num; +// uint32_t layer_index; + std::list next; };