Browse Source

feat: demo of analyse backtrack

legacy
Dnomd343 2 years ago
parent
commit
79b3345c78
  1. 76
      src/analyse/analyse.cc
  2. 10
      src/analyse/analyse.h
  3. 1
      src/fast_cal/fast_cal.cc
  4. 1
      src/main.cc

76
src/analyse/analyse.cc

@ -2,6 +2,7 @@
#include "analyse.h" #include "analyse.h"
#include <iostream> #include <iostream>
#include "raw_code.h"
Core Analyse::new_core() { Core Analyse::new_core() {
return Core( return Core(
@ -11,6 +12,20 @@ Core Analyse::new_core() {
); );
} }
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;
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;
}
void Analyse::start_analyse(uint64_t code) { void Analyse::start_analyse(uint64_t code) {
auto core = new_core(); auto core = new_core();
@ -24,6 +39,7 @@ void Analyse::start_analyse(uint64_t code) {
.code = code, .code = code,
.mask = 0, .mask = 0,
.step = 0, .step = 0,
// .highlight = false,
// .src = std::move(std::list<analyse_t*>{}), // .src = std::move(std::list<analyse_t*>{}),
}).first->second); }).first->second);
@ -40,39 +56,41 @@ void Analyse::start_analyse(uint64_t code) {
void Analyse::new_case(uint64_t code, uint64_t mask) { void Analyse::new_case(uint64_t code, uint64_t mask) {
auto temp = cases.emplace(code, analyse_t { // auto temp = cases.emplace(code, analyse_t {
.code = code, // .code = code,
.mask = mask, // .mask = mask,
.step = cache.front()->step + 1, // .step = cache.front()->step + 1,
.src = std::move(std::list<analyse_t*>{cache.front()}) // .src = std::move(std::list<analyse_t*>{cache.front()})
}); // });
//
// if (temp.second) {
// cache.emplace(&temp.first->second);
// } else {
// temp.first->second.mask |= mask;
//
// if (temp.first->second.step != cache.front()->step) {
// temp.first->second.src.push_back(cache.front());
// }
//
// }
if (temp.second) { auto current = cases.find(code);
cache.emplace(&temp.first->second); if (current != cases.end()) { // find existed case
} else { current->second.mask |= mask; // update mask info
temp.first->second.mask |= mask;
if (temp.first->second.step != cache.front()->step) { if (current->second.step != cache.front()->step) {
temp.first->second.src.push_back(cache.front()); current->second.src.push_back(cache.front());
} }
return;
} }
// auto current = cases.find(code); cache.emplace(&cases.emplace(code, analyse_t {
// if (current != cases.end()) { // find existed case .code = code,
// current->second.mask |= mask; // update mask info .mask = mask,
// .step = cache.front()->step + 1,
// if (current->second.step != cache.front()->step) { // .highlight = false,
// current->second.src.push_back(cache.front()); .src = std::move(std::list<analyse_t*>{cache.front()}),
// } }).first->second);
//
// return;
// }
//
// cache.emplace(&cases.emplace(code, analyse_t {
// .code = code,
// .mask = mask,
// .step = cache.front()->step + 1,
// .src = std::move(std::list<analyse_t*>{cache.front()}),
// }).first->second);
} }

10
src/analyse/analyse.h

@ -16,17 +16,27 @@ public:
int step; int step;
// bool highlight;
// std::vector<analyse_t*> src; // std::vector<analyse_t*> src;
std::list<analyse_t*> src; std::list<analyse_t*> src;
// std::set<analyse_t*> src; // std::set<analyse_t*> src;
// std::unordered_set<analyse_t*> src; // std::unordered_set<analyse_t*> src;
}; };
struct backtrack_t {
uint64_t code;
std::list<backtrack_t*> next;
};
std::queue<analyse_t*> cache; std::queue<analyse_t*> cache;
std::unordered_map<uint64_t, analyse_t> cases; std::unordered_map<uint64_t, analyse_t> cases;
inline Core new_core(); inline Core new_core();
// TODO: backtrack for multi-codes
void backtrack(uint64_t code);
void start_analyse(uint64_t code); void start_analyse(uint64_t code);
void new_case(uint64_t code, uint64_t mask); void new_case(uint64_t code, uint64_t mask);

1
src/fast_cal/fast_cal.cc

@ -88,6 +88,7 @@ void FastCal::fast_cal(uint64_t code) {
auto solution = cache.front(); auto solution = cache.front();
while (solution != nullptr) { while (solution != nullptr) {
// printf("%016lX\n", solution->code);
// std::cout << RawCode(solution->code).dump_case() << std::endl; // std::cout << RawCode(solution->code).dump_case() << std::endl;
solution = solution->last; solution = solution->last;
} }

1
src/main.cc

@ -202,6 +202,7 @@ int main() {
auto a = Analyse(); auto a = Analyse();
a.start_analyse(raw_code); a.start_analyse(raw_code);
a.backtrack(0x07F87E0E5BFFF492);
// int sum = 0; // int sum = 0;
// for (auto const &raw_code : all_cases_raw) { // for (auto const &raw_code : all_cases_raw) {

Loading…
Cancel
Save