From 46d1ec2a64c218c6266fa1c26ac1c1f92b318ef6 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 12 Jan 2023 15:21:22 +0800 Subject: [PATCH] update: Core and FastCal module --- src/core/core.cc | 10 +++------- src/core/core.h | 13 +++++-------- src/fast_cal/fast_cal.cc | 35 +++++------------------------------ src/fast_cal/fast_cal.h | 1 - 4 files changed, 13 insertions(+), 46 deletions(-) diff --git a/src/core/core.cc b/src/core/core.cc index 6f2709b..1c54c1b 100644 --- a/src/core/core.cc +++ b/src/core/core.cc @@ -170,13 +170,9 @@ void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases continue; // B_space or B_fill } if (cache_size != 1) { // found one or more next cases - - // TODO: try to send multi-items data -// for (int i = 1; i < cache_size; ++i) { -// release(cache[i].code, cache[i].mask); // release next cases -// } - release(cache, cache_size); - + for (int i = 1; i < cache_size; ++i) { + release(cache[i].code, cache[i].mask); // release next cases + } cache_size = 1; // reset cache size } } diff --git a/src/core/core.h b/src/core/core.h index f84c73a..d6e1f82 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -11,7 +11,12 @@ class Core { public: + typedef std::function release_t; + void next_step(uint64_t code, uint64_t mask); + explicit Core(release_t release_func) : release(std::move(release_func)) {} + +private: struct cache_t { uint64_t code; // case raw code uint64_t mask; // only 000 or 111 @@ -19,14 +24,6 @@ public: int addr; // (0 ~ 19) * 3 }; -// typedef std::function release_t; - typedef std::function release_t; - - void next_step(uint64_t code, uint64_t mask); - explicit Core(release_t release_func) : release(std::move(release_func)) {} - -private: - int cache_size = 1; cache_t cache[16] = {0}; release_t release; // release code and mask diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 682a8e8..5842549 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -8,12 +8,11 @@ void FastCal::fast_cal(uint64_t code) { - std::cout << RawCode(code).dump_case() << std::endl; +// std::cout << RawCode(code).dump_case() << std::endl; auto core = Core( - [this](auto &&p1, auto &&p2) { -// add_new_case(std::forward(p1), std::forward(p2)); - add_new_case_demo(std::forward(p1), std::forward(p2)); + [this](auto &&code, auto &&mask) { // lambda as function pointer + add_new_case(std::forward(code), std::forward(mask)); } ); @@ -29,10 +28,10 @@ void FastCal::fast_cal(uint64_t code) { while (!cache.empty()) { - // break check point + /// 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; } @@ -67,27 +66,3 @@ void FastCal::add_new_case(uint64_t code, uint64_t mask) { cache.emplace(&cases[code]); } - -void FastCal::add_new_case_demo(Core::cache_t *cache_dat, int cache_size) { - - for (int i = 1; i < cache_size; ++i) { - uint64_t code = cache_dat[i].code; - uint64_t mask = cache_dat[i].mask; - - auto exist_case = cases.find(code); - if (exist_case != cases.end()) { - exist_case->second.mask |= mask; - continue; - } - - cases[code] = fast_cal_t { - .code = code, - .mask = mask, - .last = cache.front(), - }; - cache.emplace(&cases[code]); - - } - - -} diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index aa2bf73..f8dbc68 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -18,6 +18,5 @@ public: void fast_cal(uint64_t code); void add_new_case(uint64_t code, uint64_t mask); - void add_new_case_demo(Core::cache_t *cache_dat, int cache_size); };