Browse Source

feat: demo of analyse backtrack

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

10
src/analyse/analyse.h

@ -16,17 +16,27 @@ public:
int step;
// bool highlight;
// std::vector<analyse_t*> src;
std::list<analyse_t*> src;
// std::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::unordered_map<uint64_t, analyse_t> cases;
inline Core new_core();
// TODO: backtrack for multi-codes
void backtrack(uint64_t code);
void start_analyse(uint64_t code);
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();
while (solution != nullptr) {
// printf("%016lX\n", solution->code);
// std::cout << RawCode(solution->code).dump_case() << std::endl;
solution = solution->last;
}

1
src/main.cc

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

Loading…
Cancel
Save