From c6bedb95943ee4006791bce531446cebd0fa8446 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Jan 2023 13:32:35 +0800 Subject: [PATCH] remove: legacy fast_cal demo --- src/fast_cal.cc | 178 ------------------------------------------------ 1 file changed, 178 deletions(-) delete mode 100644 src/fast_cal.cc diff --git a/src/fast_cal.cc b/src/fast_cal.cc deleted file mode 100644 index ff65b47..0000000 --- a/src/fast_cal.cc +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include -#include -#include -#include "core.h" -#include "fast_cal.h" -#include "raw_code.h" -#include "common.h" - -struct fast_cal_t { - uint64_t code; - uint64_t mask; -// uint32_t step; - fast_cal_t *last; -}; - -std::queue cache; - -std::unordered_map cases; - - -class FastCal; -class GlobalCal; - -//template -class CoreDemo { -public: -// typedef void (T::*release_t)(uint64_t); - - std::function release; - -// void next(uint64_t code, T *f, release_t release_func) { - void next(uint64_t code) { - - std::cout << "Core get code = " << code << std::endl; - std::cout << "Core callback first time" << std::endl; -// (f->*release_func)(++code); - release(++code); - std::cout << "Core callback second time" << std::endl; -// (f->*release_func)(++code); - release(++code); - std::cout << "Core function exit" << std::endl; - - } - -}; - -class FastCal { -public: - uint64_t data; - - explicit FastCal(uint64_t dat) : data(dat) {} - - void callback(uint64_t code) { - std::cout << "FastCal get callback " << code << std::endl; - data = code; - std::cout << "FastCal set data " << data << std::endl; - } - - void run() { -// auto cd = CoreDemo(); - auto cd = CoreDemo(); - cd.release = std::bind(&FastCal::callback, this, std::placeholders::_1); - - std::cout << "FastCal data = " << data << std::endl; - -// cd.next(data, this, &FastCal::callback); - cd.next(data); - } - -}; - -class GlobalCal { -public: - uint64_t data; - - explicit GlobalCal(uint64_t dat) : data(dat) {} - - void callback(uint64_t code) { - std::cout << "GlobalCal get callback " << code << std::endl; - data = code; - std::cout << "GlobalCal set data " << data << std::endl; - } - - void run() { -// auto cd = CoreDemo(); - auto cd = CoreDemo(); - cd.release = std::bind(&GlobalCal::callback, this, std::placeholders::_1); - - std::cout << "GlobalCal data = " << data << std::endl; - -// cd.next(data, this, &GlobalCal::callback); - cd.next(data); - } - -}; - - -void add_new_case(uint64_t code, uint64_t mask) { - - auto exist_case = cases.find(code); - if (exist_case != cases.end()) { // find existed case - - exist_case->second.mask |= mask; // mask update - return; - - } - - cases[code] = fast_cal_t { - .code = code, - .mask = mask, - .last = cache.front(), - };; - cache.emplace(&cases[code]); - - // TODO: try to check head address = 0xD at here - -// if (((code >> (3 * 0xD)) & 0b111) == B_2x2) { -// std::cout << "Resolved" << std::endl; -// std::cout << RawCode(cache.front()->code).dump_case() << std::endl; -// stop_flag = true; -// } - -} - -uint32_t fast_cal(uint64_t code) { - - auto f1 = FastCal(1000); - auto f2 = FastCal(2000); - auto g = GlobalCal(3000); - - f2.run(); - f1.run(); - f1.run(); - g.run(); - -// auto g = GlobalCal(); -// g.run(); - - return 0; - - - auto core = Core(add_new_case); - - cases.empty(); - - cache.empty(); - - cases[code] = fast_cal_t { - .code = code, - .mask = 0, - .last = nullptr, - }; - cache.emplace(&cases[code]); - - while (!cache.empty()) { - - // break check point - if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) { - std::cout << "Resolved" << std::endl; -// std::cout << RawCode(cache.front()->code).dump_case() << std::endl; - break; - } - -// core.next_step(cache.front()->code, cache.front()->mask); - cache.pop(); - } - - auto solution = cache.front(); - - while (solution != nullptr) { - std::cout << RawCode(solution->code).dump_case() << std::endl; - solution = solution->last; - } - - return cases.size(); - -}