From 1b4f543aaaeab73d131ac6b0106e31ae5060ea6f Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 11 Jan 2023 11:40:07 +0800 Subject: [PATCH] feat: release function pointer --- src/core/core.cc | 25 +++--------------------- src/core/core.h | 2 +- src/main.cc | 51 ++++++++++++++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/core/core.cc b/src/core/core.cc index 4c8b5d4..7ed56b8 100644 --- a/src/core/core.cc +++ b/src/core/core.cc @@ -126,12 +126,7 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block } } -#include - -uint32_t Core::next_step(uint64_t raw_code) { - - uint32_t sum = 0; - +void Core::next_step(uint64_t raw_code, void (*release)(uint64_t, uint64_t)) { // search next step cases auto code = raw_code; for (int addr = 0; code; addr += 3, code >>= 3) { // traverse every 3-bits switch (code & 0b111) { // match low 3-bits @@ -153,24 +148,10 @@ uint32_t Core::next_step(uint64_t raw_code) { if (cache_size != 1) { // found one or more next cases for (int i = 1; i < cache_size; ++i) { - // TODO: release next cases (code and mask) - -// std::cout << RawCode(cache[i].code).dump_case(); -// std::cout << "~~~~~~~" << std::endl; -// auto mask = cache[i].mask; -// for (int n = 0; n < 20; ++n, mask >>= 3) { -// std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)]; -// } -// std::cout << std::endl; + // TODO: try to send multi-items data + release(cache[i].code, cache[i].mask); // release next cases } - - sum += cache_size - 1; - } } - -// std::cout << "sum = " << sum << std::endl; - return sum; - } diff --git a/src/core/core.h b/src/core/core.h index afb8545..8015d5c 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -20,7 +20,7 @@ class Core { public: // void next_step(uint64_t raw_code); - uint32_t next_step(uint64_t raw_code); + void next_step(uint64_t raw_code, void (*release)(uint64_t code, uint64_t mask)); private: struct cache_t { diff --git a/src/main.cc b/src/main.cc index d7d5851..4551eeb 100644 --- a/src/main.cc +++ b/src/main.cc @@ -37,6 +37,15 @@ // } //} +void release(uint64_t code, uint64_t mask) { + std::cout << RawCode(code).dump_case(); + std::cout << "~~~~~~~" << std::endl; + for (int n = 0; n < 20; ++n, mask >>= 3) { + std::cout << "+."[!(mask & 0b111)] << " \n"[!(~n & 0b11)]; + } + std::cout << std::endl; +} + int main() { // printf("%p\n", BasicRanges::build); @@ -146,15 +155,19 @@ int main() { auto c = Core(); - std::vector all_cases_raw; - for (int head = 0; head < 16; ++head) { - uint64_t prefix = (uint64_t)head << 32; - for (auto const &range : (*AllCases::fetch())[head]) { - all_cases_raw.emplace_back( - RawCode(CommonCode::unsafe_create(prefix | range)).unwrap() - ); - } - } +// auto raw_code = RawCode(CommonCode("4fea134")).unwrap(); + auto raw_code = RawCode(CommonCode("1A9bf0c")).unwrap(); + c.next_step(raw_code, release); + +// std::vector all_cases_raw; +// for (int head = 0; head < 16; ++head) { +// uint64_t prefix = (uint64_t)head << 32; +// for (auto const &range : (*AllCases::fetch())[head]) { +// all_cases_raw.emplace_back( +// RawCode(CommonCode::unsafe_create(prefix | range)).unwrap() +// ); +// } +// } // std::cout << "start benchmark" << std::endl; // auto start_time = clock(); @@ -164,20 +177,20 @@ int main() { // c.next_step(raw_code); // } - std::vector steps; - for (auto const &raw_code : all_cases_raw) { - steps.emplace_back(c.next_step(raw_code)); - } +// std::vector steps; +// for (auto const &raw_code : all_cases_raw) { +// steps.emplace_back(c.next_step(raw_code)); +// } // std::sort(steps.begin(), steps.end()); // std::cout << steps[0] << std::endl; // std::cout << steps[steps.size() - 1] << std::endl; - for (int i = 0; i < all_cases_raw.size(); ++i) { +// for (int i = 0; i < all_cases_raw.size(); ++i) { // if (steps[i] == 0) { - if (steps[i] == 68) { // max next steps - std::cout << RawCode(all_cases_raw[i]).dump_case(); - std::cout << CommonCode(RawCode(all_cases_raw[i])).to_string() << std::endl << std::endl; - } - } +// if (steps[i] == 68) { // max next steps +// std::cout << RawCode(all_cases_raw[i]).dump_case(); +// std::cout << CommonCode(RawCode(all_cases_raw[i])).to_string() << std::endl << std::endl; +// } +// } // std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; // std::cout << "complete benchmark" << std::endl;