Browse Source

feat: backtrack graph build

legacy
Dnomd343 2 years ago
parent
commit
addce4668d
  1. 65
      src/analyse/analyse.cc
  2. 10
      src/analyse/analyse.h

65
src/analyse/analyse.cc

@ -1,6 +1,8 @@
#include <queue>
#include "core.h"
#include "analyse.h"
#include <list>
#include <iostream>
#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<backtrack_t*> track_data;
std::queue<analyse_t*> 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<backtrack_t*>{}, // 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<backtrack_t*>{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;
}

10
src/analyse/analyse.h

@ -4,9 +4,9 @@
#include <cstdint>
#include <unordered_map>
#include <set>
//#include <set>
#include <list>
#include <unordered_set>
//#include <unordered_set>
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<backtrack_t*> next;
};

Loading…
Cancel
Save