From e4069422f8e1930c12ef350b71e9e14203bb6f13 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 18 Jan 2023 15:17:33 +0800 Subject: [PATCH] update: fix several warnings --- src/CMakeLists.txt | 4 ++-- src/all_cases/all_cases.cc | 2 +- src/common_code/common_code.cc | 28 +++++++++++++++------------- src/core/core.cc | 4 ++-- src/core/core.h | 7 ++++--- src/fast_cal/fast_cal.cc | 2 +- src/main.cc | 14 +++++++++----- 7 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1b014f..d8772ac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,7 +23,7 @@ add_subdirectory(short_code) add_subdirectory(common_code) add_subdirectory(core) -add_subdirectory(analyse) +#add_subdirectory(analyse) add_subdirectory(fast_cal) ################################################ @@ -40,7 +40,7 @@ target_link_libraries(klotski short_code) target_link_libraries(klotski common_code) target_link_libraries(klotski core) -target_link_libraries(klotski analyse) +#target_link_libraries(klotski analyse) target_link_libraries(klotski fast_cal) target_link_libraries(klotski pthread) diff --git a/src/all_cases/all_cases.cc b/src/all_cases/all_cases.cc index d5fa6d1..ab9adf7 100644 --- a/src/all_cases/all_cases.cc +++ b/src/all_cases/all_cases.cc @@ -44,7 +44,7 @@ void AllCases::build_data() { // find all cases /// head -> 0/1/2 / 4/5/6 / 8/9/10 / 12/13/14 data[head].reserve(ALL_CASES_SIZE[head]); // memory pre-allocated /// head(4-bits) + basic ranges(32-bits) ==check==> release valid cases - for (auto index = 0; index < basic_ranges.size(); ++index) { + for (uint32_t index = 0; index < basic_ranges.size(); ++index) { auto broken_offset = Common::check_range(head, basic_ranges[index]); if (broken_offset) { // case invalid auto delta = (uint32_t)1 << (32 - broken_offset * 2); // delta to next possible range diff --git a/src/common_code/common_code.cc b/src/common_code/common_code.cc index 7dfb297..7a8d646 100644 --- a/src/common_code/common_code.cc +++ b/src/common_code/common_code.cc @@ -51,30 +51,32 @@ bool CommonCode::check(uint64_t common_code) { // whether common code is valid uint32_t mask = M_2x2 << head; // fill 2x2 block auto range = Common::range_reverse((uint32_t)common_code); for (int addr = 0;; range >>= 2) { // traverse every 2-bits - while (mask >> addr & 0b1) { + while ((mask >> addr) & 0b1) { ++addr; // search next unfilled block } if (addr >= 20) { return !range && space_num > 1; // empty range and >= 2 space } switch (range & 0b11) { - case 0b00: // space + case 0b00: /// space + mask |= M_1x1 << addr; // fill space ++space_num; - case 0b11: // 1x1 block - mask |= M_1x1 << addr; // fill space or 1x1 block - break; - case 0b10: // 2x1 block - if (addr > 15 || mask >> (addr + 4) & 0b1) { // invalid address - return false; + continue; + case 0b11: /// 1x1 block + mask |= M_1x1 << addr; // fill 1x1 block + continue; + case 0b10: /// 2x1 block + if (addr > 15 || mask >> (addr + 4) & 0b1) { + return false; // invalid address } mask |= M_2x1 << addr; // fill 2x1 block - break; - case 0b01: // 1x2 block - if ((addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) { // invalid address - return false; + continue; + case 0b01: /// 1x2 block + if ((addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) { + return false; // invalid address } mask |= M_1x2 << addr; // fill 1x2 block - break; + continue; } } } diff --git a/src/core/core.cc b/src/core/core.cc index 24d0a25..1720751 100644 --- a/src/core/core.cc +++ b/src/core/core.cc @@ -147,7 +147,7 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block } } -void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases +void Core::next_cases(uint64_t code, uint64_t mask) { // search next step cases cache[0].filter = 0; // without filter cache[0].code = code; // bfs root code auto range = code | mask; @@ -171,7 +171,7 @@ void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases } if (cache_size != 1) { // found one or more next cases for (int i = 1; i < cache_size; ++i) { - release(cache[i].code, cache[i].mask); // release next cases + Core::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 0649626..f6da2a9 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -11,9 +11,11 @@ class Core { public: + /// Release with code and mask typedef std::function release_t; - void next_step(uint64_t code, uint64_t mask); + /// Core interface + void next_cases(uint64_t code, uint64_t mask); explicit Core(release_t release_func) : release(std::move(release_func)) {} private: @@ -26,12 +28,11 @@ private: int cache_size = 1; cache_t cache[16]{}; - release_t release; // release code and mask + release_t release; // release function void move_1x1(uint64_t code, int addr); void move_1x2(uint64_t code, int addr); void move_2x1(uint64_t code, int addr); void move_2x2(uint64_t code, int addr); - inline void cache_insert(Core::cache_t &next_case); }; diff --git a/src/fast_cal/fast_cal.cc b/src/fast_cal/fast_cal.cc index 0d6250c..8a6c3e9 100644 --- a/src/fast_cal/fast_cal.cc +++ b/src/fast_cal/fast_cal.cc @@ -79,7 +79,7 @@ void FastCal::fast_cal(uint64_t code) { break; } - core.next_step(cache.front()->code, cache.front()->mask); + core.next_cases(cache.front()->code, cache.front()->mask); cache.pop(); } diff --git a/src/main.cc b/src/main.cc index 69d3bd5..5a0566f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -23,7 +23,11 @@ int main() { // std::cout << "start benchmark" << std::endl; auto start_time = clock(); - AllCases::build(); + for (uint32_t common_code = 0x10000000; common_code < 0x20000000; ++common_code) { + CommonCode::check(common_code); + } + +// AllCases::build(); // auto raw_code = CommonCode("1a9bf0c").to_raw_code().unwrap(); @@ -75,10 +79,10 @@ int main() { // std::cout << ShortCode("EP4HZ") << std::endl; // std::cout << ShortCode(14323231) << std::endl; - std::cout << RawCode::from_common_code("4fea134") << std::endl; - std::cout << CommonCode::from_raw_code(0xE58FC85FFEBC4DB) << std::endl; - std::cout << ShortCode::from_common_code("4fea134") << std::endl; - std::cout << CommonCode::from_short_code("AXCZN") << std::endl; +// std::cout << RawCode::from_common_code("4fea134") << std::endl; +// std::cout << CommonCode::from_raw_code(0xE58FC85FFEBC4DB) << std::endl; +// std::cout << ShortCode::from_common_code("4fea134") << std::endl; +// std::cout << CommonCode::from_short_code("AXCZN") << std::endl; // std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl;