diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index dd29134..a0567fc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -18,7 +18,7 @@ set(KLOTSKI_CORE_SRC short_code/internal/convert.cc short_code/internal/serialize.cc - core/internal/core.cc + mover/internal/mover.cc fast_cal/internal/cal_core.cc fast_cal/internal/fast_cal.cc diff --git a/src/core/fast_cal/fast_cal.h b/src/core/fast_cal/fast_cal.h index e8384da..73de499 100644 --- a/src/core/fast_cal/fast_cal.h +++ b/src/core/fast_cal/fast_cal.h @@ -10,11 +10,11 @@ #include #include -#include "core/core.h" +#include "mover/mover.h" #include "raw_code/raw_code.h" -using klotski::core::Core; using klotski::codec::RawCode; +using klotski::mover::MaskMover; // TODO: using prime number const uint32_t FC_MAP_RESERVE = 65536 * 8; @@ -60,6 +60,6 @@ private: std::queue cache; std::unordered_map cases; - inline Core init(uint64_t code); + inline MaskMover init(uint64_t code); void new_case(uint64_t code, uint64_t mask); }; diff --git a/src/core/fast_cal/internal/cal_core.cc b/src/core/fast_cal/internal/cal_core.cc index 6eed096..e37fd06 100644 --- a/src/core/fast_cal/internal/cal_core.cc +++ b/src/core/fast_cal/internal/cal_core.cc @@ -1,6 +1,6 @@ #include "fast_cal/fast_cal.h" -Core FastCal::init(uint64_t code) { // initialize process +MaskMover FastCal::init(uint64_t code) { // initialize process /// reset working data cases.clear(); cases.reserve(FC_MAP_RESERVE); // hashmap pre-reserve @@ -13,8 +13,8 @@ Core FastCal::init(uint64_t code) { // initialize process .last = nullptr, // without parent node }).first->second); - /// import klotski core - return Core( + /// import klotski mover + return MaskMover( [this](auto &&code, auto &&mask) { // lambda as function pointer new_case(std::forward(code), std::forward(mask)); } diff --git a/src/core/group/internal/group.cc b/src/core/group/internal/group.cc index 76d21fb..c5ea6a6 100644 --- a/src/core/group/internal/group.cc +++ b/src/core/group/internal/group.cc @@ -1,14 +1,15 @@ #include -#include "core/core.h" +#include "mover/mover.h" #include "group/group.h" -using klotski::core::Core; using klotski::cases::Group; using klotski::codec::RawCode; using klotski::codec::CommonCode; using klotski::cases::RangesUnion; +using klotski::mover::MaskMover; + std::vector Group::extend(RawCode raw_code, uint32_t reserve) { std::vector codes; absl::flat_hash_map cases; // @@ -16,7 +17,7 @@ std::vector Group::extend(RawCode raw_code, uint32_t reserve) { codes.reserve(reserve); cases.reserve(reserve); - auto core = Core([&codes, &cases](uint64_t code, uint64_t mask) { + auto core = MaskMover([&codes, &cases](uint64_t code, uint64_t mask) { if (const auto match = cases.find(code); match != cases.end()) { match->second |= mask; // update mask return; diff --git a/src/core/group/internal/group_union.cc b/src/core/group/internal/group_union.cc index c203bdd..6d807ea 100644 --- a/src/core/group/internal/group_union.cc +++ b/src/core/group/internal/group_union.cc @@ -1,4 +1,4 @@ -#include "core/core.h" +#include "mover/mover.h" #include "group/group.h" #include "constant/group_union.h" diff --git a/src/core/main.cc b/src/core/main.cc index 5b9137e..4ab1b40 100644 --- a/src/core/main.cc +++ b/src/core/main.cc @@ -6,8 +6,8 @@ #include #include -#include "core/core.h" #include "group/group.h" +#include "mover/mover.h" #include "raw_code/raw_code.h" #include "fast_cal/fast_cal.h" #include "all_cases/all_cases.h" @@ -16,7 +16,7 @@ #include "../../third_party/thread-pool/include/BS_thread_pool.hpp" -using klotski::core::Core; +using klotski::mover::MaskMover; using klotski::cases::AllCases; using klotski::cases::BasicRanges; diff --git a/src/core/core/internal/core.cc b/src/core/mover/internal/mover.cc similarity index 91% rename from src/core/core/internal/core.cc rename to src/core/mover/internal/mover.cc index 5be9af3..4ce4906 100644 --- a/src/core/core/internal/core.cc +++ b/src/core/mover/internal/mover.cc @@ -1,4 +1,4 @@ -#include "core/core.h" +#include "mover/mover.h" #include "utils/common.h" /// block move direction @@ -73,9 +73,9 @@ /////////////////////////////////////////////// -using klotski::core::Core; +using klotski::mover::MaskMover; -inline void Core::cache_insert(cache_t next_case) { // try to insert into cache +inline void MaskMover::cache_insert(cache_t next_case) { // try to insert into cache auto *cache_ptr = cache_; for (; cache_ptr < cache_ + cache_size_; ++cache_ptr) { if (cache_ptr->code == next_case.code) { @@ -86,7 +86,7 @@ inline void Core::cache_insert(cache_t next_case) { // try to insert into cache ++cache_size_; } -void Core::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block +void MaskMover::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block BFS_INIT while (!BFS_STOP) { // bfs search process BFS_LOAD @@ -105,7 +105,7 @@ void Core::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block } } -void Core::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block +void MaskMover::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block BFS_INIT while (!BFS_STOP) { // bfs search process BFS_LOAD @@ -124,7 +124,7 @@ void Core::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block } } -void Core::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block +void MaskMover::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block BFS_INIT while (!BFS_STOP) { // bfs search process BFS_LOAD @@ -143,7 +143,7 @@ void Core::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block } } -void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block +void MaskMover::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block BFS_INIT while (!BFS_STOP) { // bfs search process BFS_LOAD @@ -162,7 +162,7 @@ void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block } } -void Core::next_cases(uint64_t code, uint64_t mask) { // search next step cases +void MaskMover::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; diff --git a/src/core/core/core.h b/src/core/mover/mover.h similarity index 94% rename from src/core/core/core.h rename to src/core/mover/mover.h index 5b00299..b2b3d3b 100644 --- a/src/core/core/core.h +++ b/src/core/mover/mover.h @@ -52,7 +52,7 @@ /// be obtained at the same time, which marks the moved block as `111`, which /// will speed up subsequent calculations. The generated layout will be /// inserted into the cache, and after the BFS search for each block is -/// completed, the core will use the callback function to output these +/// completed, the mover will use the callback function to output these /// results. #pragma once @@ -61,20 +61,20 @@ #include #include -namespace klotski::core { +namespace klotski::mover { // TODO: new version without mask // TODO: allow wrap as a function directly -class Core { +class MaskMover { public: /// Release with code and mask typedef std::function release_t; /// Core interface void next_cases(uint64_t code, uint64_t mask); - explicit Core(release_t release_func) : release_(std::move(release_func)) {} + explicit MaskMover(release_t release_func) : release_(std::move(release_func)) {} private: struct cache_t { @@ -95,4 +95,4 @@ private: inline void cache_insert(cache_t next_case); }; -} // namespace klotski::core +} // namespace klotski::mover diff --git a/src/core_test/CMakeLists.txt b/src/core_test/CMakeLists.txt index 04c6a34..98e2ee6 100644 --- a/src/core_test/CMakeLists.txt +++ b/src/core_test/CMakeLists.txt @@ -62,12 +62,12 @@ add_test(NAME klotski_codec COMMAND test_klotski_codec) # ------------------------------------------------------------------------------------ # -set(KLSK_TEST_CORE_SRC - core/core.cc +set(KLSK_TEST_MOVER_SRC + mover/mover.cc ) -add_executable(test_klotski_core ${KLSK_TEST_CORE_SRC}) -target_link_libraries(test_klotski_core PRIVATE ${KLSK_TEST_DEPS}) -add_test(NAME klotski_core COMMAND test_klotski_core) +add_executable(test_klotski_mover ${KLSK_TEST_MOVER_SRC}) +target_link_libraries(test_klotski_mover PRIVATE ${KLSK_TEST_DEPS} test_helper) +add_test(NAME klotski_mover COMMAND test_klotski_mover) # ------------------------------------------------------------------------------------ # diff --git a/src/core_test/cases/helper/group_impl.cc b/src/core_test/cases/helper/group_impl.cc index 325557c..f5aa338 100644 --- a/src/core_test/cases/helper/group_impl.cc +++ b/src/core_test/cases/helper/group_impl.cc @@ -6,7 +6,7 @@ /// Extend ordered Group from the specified CommonCode seed. static std::vector extend_cases(CommonCode seed) { - // TODO: using inner build process -> only allow calling klotski::core + // TODO: using inner build process -> only allow calling klotski::mover auto raw_codes = klotski::cases::Group::extend(seed.to_raw_code()); std::vector common_codes {raw_codes.begin(), raw_codes.end()}; std::ranges::sort(common_codes.begin(), common_codes.end()); diff --git a/src/core_test/helper/internal/group.cc b/src/core_test/helper/internal/group.cc index f15d20a..987f12b 100644 --- a/src/core_test/helper/internal/group.cc +++ b/src/core_test/helper/internal/group.cc @@ -52,7 +52,7 @@ const std::vector& helper::group_union_cases(const uint32_t type_id) /// Extend ordered Group from the specified CommonCode seed. static std::vector extend_cases(CommonCode seed) { - // TODO: using inner build process -> only allow calling klotski::core + // TODO: using inner build process -> only allow calling klotski::mover auto raw_codes = klotski::cases::Group::extend(seed.to_raw_code()); std::vector common_codes {raw_codes.begin(), raw_codes.end()}; std::ranges::sort(common_codes.begin(), common_codes.end()); diff --git a/src/core_test/core/core.cc b/src/core_test/mover/mover.cc similarity index 94% rename from src/core_test/core/core.cc rename to src/core_test/mover/mover.cc index 33b06d8..fdaab64 100644 --- a/src/core_test/core/core.cc +++ b/src/core_test/mover/mover.cc @@ -5,7 +5,7 @@ #include #include -#include "core/core.h" +#include "mover/mover.h" #include "utils/common.h" #include "all_cases/all_cases.h" #include "common_code/common_code.h" @@ -19,7 +19,7 @@ constexpr auto NEXT_CASES_XXH3 = std::to_array({ 0x4a7599e1bdbffbb3, 0xb3cf1fdea988466a, 0x21226a4f692e1892, 0x2d06800538d394c2, }); -using klotski::core::Core; +using klotski::mover::MaskMover; using klotski::cases::AllCases; using klotski::codec::CommonCode; @@ -54,7 +54,7 @@ TEST(Core, core) { std::vector codes; codes.reserve(402258220); - auto core = Core([&codes](uint64_t ret, uint64_t) { + auto core = MaskMover([&codes](uint64_t ret, uint64_t) { codes.emplace_back(klotski::codec::RawCode::unsafe_create(ret).to_common_code().unwrap()); }); @@ -82,7 +82,7 @@ TEST(Core, mask) { uint64_t src; - auto core = Core([&src](uint64_t ret, uint64_t mask) { + auto core = MaskMover([&src](uint64_t ret, uint64_t mask) { EXPECT_EQ(std::popcount(mask), 3); @@ -184,7 +184,7 @@ TEST(Core, next_cases) { std::vector result {}; std::vector tmp; - auto core = Core([&tmp](uint64_t ret, uint64_t mask) { + auto core = MaskMover([&tmp](uint64_t ret, uint64_t mask) { tmp.emplace_back(CommonCode::from_raw_code(ret).value()); }); @@ -212,6 +212,6 @@ TEST(Core, next_cases) { // std::cout << std::hex << hash::xxh3(result) << std::endl; - EXPECT_EQ(hash::xxh3(result), NEXT_CASES_XXH3[0]); + EXPECT_EQ(helper::xxh3(result), NEXT_CASES_XXH3[0]); }