From e9d71046743c325fc04f9b3339c5865575c7e050 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 17 Nov 2024 16:08:26 +0800 Subject: [PATCH] update: fix compile errors --- src/core/benchmark/codec.cc | 2 +- src/core/benchmark/group.cc | 10 +++++----- src/core_ffi/CMakeLists.txt | 8 ++++---- src/core_ffi/c_ffi/all_cases.cc | 2 +- src/core_test/helper/internal/parallel.cc | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/benchmark/codec.cc b/src/core/benchmark/codec.cc index c769783..847acb6 100644 --- a/src/core/benchmark/codec.cc +++ b/src/core/benchmark/codec.cc @@ -18,7 +18,7 @@ using klotski::codec::CommonCode; static std::vector all_common_codes() { std::vector codes; for (uint64_t head = 0; head < 16; ++head) { - for (const auto range : AllCases::instance().fetch()[head]) { + for (const auto range : AllCases::instance().fetch().ranges(head)) { codes.emplace_back(head << 32 | range); } } diff --git a/src/core/benchmark/group.cc b/src/core/benchmark/group.cc index a7529e0..28f48d1 100644 --- a/src/core/benchmark/group.cc +++ b/src/core/benchmark/group.cc @@ -26,7 +26,7 @@ using klotski::codec::CommonCode; static std::vector all_common_codes() { std::vector codes; for (uint64_t head = 0; head < 16; ++head) { - for (const auto range : AllCases::instance().fetch()[head]) { + for (const auto range : AllCases::instance().fetch().ranges(head)) { codes.emplace_back(head << 32 | range); } } @@ -342,7 +342,7 @@ static void FastObtainCode(benchmark::State &state) { size_t offset = 0; for (int i = 0; i < 16; ++i) { sizes[i] = offset; - offset += data[i].size(); + offset += data.ranges(i).size(); } std::vector infos { @@ -376,14 +376,14 @@ static void FastObtainCode(benchmark::State &state) { uint64_t head = 0; auto case_id = info.case_id(); for (;;) { - if (case_id >= cases[head].size()) { - case_id -= cases[head].size(); + if (case_id >= cases.ranges(head).size()) { + case_id -= cases.ranges(head).size(); ++head; } else { break; } } - auto range = cases[head][case_id]; + auto range = cases.ranges(head)[case_id]; volatile auto kk = CommonCode::unsafe_create(head << 32 | range); /// about 117ns diff --git a/src/core_ffi/CMakeLists.txt b/src/core_ffi/CMakeLists.txt index 36cdeab..3583740 100644 --- a/src/core_ffi/CMakeLists.txt +++ b/src/core_ffi/CMakeLists.txt @@ -19,13 +19,13 @@ if (KLSK_RUST_FFI) install(TARGETS klotski_core DESTINATION .) else() # just for IDE highlight - add_library(klotski_rust + add_library(klotski_rs rust_ffi/adapter/short_code.cc rust_ffi/adapter/common_code.cc rust_ffi/target/cxxbridge/rust_ffi/src/bridge.rs.cc ) - target_include_directories(klotski_rust PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - target_include_directories(klotski_rust PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rust_ffi/target/cxxbridge) - target_link_libraries(klotski_rust PRIVATE klotski_core) + target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + target_include_directories(klotski_rs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/rust_ffi/target/cxxbridge) + target_link_libraries(klotski_rs PRIVATE klotski_core) endif() endif() diff --git a/src/core_ffi/c_ffi/all_cases.cc b/src/core_ffi/c_ffi/all_cases.cc index c9ded49..b338b18 100644 --- a/src/core_ffi/c_ffi/all_cases.cc +++ b/src/core_ffi/c_ffi/all_cases.cc @@ -64,7 +64,7 @@ const uint32_t* all_cases_export(const int head) { if (all_cases_num(head) < 0) { return nullptr; } - return AllCases::instance().fetch()[head].data(); + return AllCases::instance().fetch().ranges(head).data(); } // ------------------------------------------------------------------------------------- // diff --git a/src/core_test/helper/internal/parallel.cc b/src/core_test/helper/internal/parallel.cc index 6e56731..665c398 100644 --- a/src/core_test/helper/internal/parallel.cc +++ b/src/core_test/helper/internal/parallel.cc @@ -44,7 +44,7 @@ void helper::common_code_parallel(std::function)> &&f // TODO: enhance performance - pool.detach_blocks((uint64_t)0, codes.size(), [&func](auto start, auto end) { + pool.detach_blocks((size_t)0, codes.size(), [&func](auto start, auto end) { func(std::span {codes.data() + start, end - start}); @@ -60,7 +60,7 @@ void helper::raw_code_parallel(std::function)> &&func) { static auto codes = std::vector {common_codes.begin(), common_codes.end()}; BS::thread_pool pool; - pool.detach_blocks((uint64_t)0, codes.size(), [&func](auto start, auto end) { + pool.detach_blocks((size_t)0, codes.size(), [&func](auto start, auto end) { func(std::span {codes.data() + start, end - start}); @@ -78,7 +78,7 @@ void helper::short_code_parallel(std::function)> &&fun }(); BS::thread_pool pool; - pool.detach_blocks((uint64_t)0, codes.size(), [&func](auto start, auto end) { + pool.detach_blocks((size_t)0, codes.size(), [&func](auto start, auto end) { auto span = std::span {codes.data() + start, end - start}; func(std::bit_cast>(span));