diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index 32fe0b1..a7a2401 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -63,7 +63,7 @@ add_subdirectory(benchmark) ################################################################################ -set(FFI_SRC codec.cc all_cases.cc tmain.cc version.cc) +set(FFI_SRC codec.cc all_cases.cc tmain.cc metadata.cc) list(TRANSFORM FFI_SRC PREPEND "ffi/") add_library(klotski-ffi OBJECT ${FFI_SRC}) diff --git a/src/klotski/ffi/all_cases.cc b/src/klotski/ffi/all_cases.cc index 6f7b728..4bba079 100644 --- a/src/klotski/ffi/all_cases.cc +++ b/src/klotski/ffi/all_cases.cc @@ -3,8 +3,9 @@ using klotski::AllCases; using klotski::BasicRanges; -using klotski::BASIC_RANGES_SIZE; -using klotski::ALL_CASES_SIZE_SUM; + +const uint32_t ALL_CASES_SIZE = klotski::ALL_CASES_SIZE_SUM; +const uint32_t BASIC_RANGES_SIZE = klotski::BASIC_RANGES_SIZE; void all_cases_build() { AllCases::build(); @@ -21,3 +22,17 @@ bool is_all_cases_available() { bool is_basic_ranges_available() { return BasicRanges::status() == BasicRanges::AVAILABLE; } + +void export_all_cases(uint64_t *buffer) { + for (uint64_t head = 0; head < 16; ++head) { + for (const auto &range : AllCases::fetch()[head]) { + *(buffer++) = head << 32 | range; + } + } +} + +void export_basic_ranges(uint32_t *buffer) { + for (const auto &range : BasicRanges::fetch()) { + *(buffer++) = range; + } +} diff --git a/src/klotski/ffi/codec.cc b/src/klotski/ffi/codec.cc index 8606ef2..9a4a33e 100644 --- a/src/klotski/ffi/codec.cc +++ b/src/klotski/ffi/codec.cc @@ -106,7 +106,7 @@ bool common_code_to_short_code(uint64_t common_code, uint32_t *short_code) { //////////////////////////////////////////////////////////////////////////////// -const uint32_t short_code_string_size = 6; +const uint32_t SHORT_CODE_STR_SIZE = 6; bool short_code_to_string(uint32_t short_code, char short_code_str[]) { if (!ShortCode::check(short_code)) { @@ -128,7 +128,7 @@ bool short_code_from_string(const char short_code_str[], uint32_t *short_code) { //////////////////////////////////////////////////////////////////////////////// -const uint32_t common_code_string_size = 10; +const uint32_t COMMON_CODE_STR_SIZE = 10; bool common_code_to_string(uint64_t common_code, char common_code_str[]) { if (!CommonCode::check(common_code)) { diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h index 00a6058..72bec22 100644 --- a/src/klotski/ffi/klotski.h +++ b/src/klotski/ffi/klotski.h @@ -17,7 +17,7 @@ extern "C" { } #endif -/// --------------------------------- klotski version info ---------------------------------- +/// -------------------------------- klotski metadata info ---------------------------------- #ifdef __cplusplus extern "C" { @@ -48,10 +48,10 @@ extern "C" { extern bool is_all_cases_available(); extern bool is_basic_ranges_available(); - extern const uint32_t all_cases_size; + extern const uint32_t ALL_CASES_SIZE; extern void export_all_cases(uint64_t *buffer); - extern const uint32_t basic_ranges_size; + extern const uint32_t BASIC_RANGES_SIZE; extern void export_basic_ranges(uint32_t *buffer); #ifdef __cplusplus } @@ -80,12 +80,12 @@ extern "C" { extern bool common_code_to_short_code(uint64_t common_code, uint32_t *short_code); /// output char[] buffer at least 6-bytes - extern const uint32_t short_code_string_size; + extern const uint32_t SHORT_CODE_STR_SIZE; extern bool short_code_to_string(uint32_t short_code, char short_code_str[]); extern bool short_code_from_string(const char short_code_str[], uint32_t *short_code); /// output char[] buffer at least 10-bytes - extern const uint32_t common_code_string_size; + extern const uint32_t COMMON_CODE_STR_SIZE; extern bool common_code_to_string(uint64_t common_code, char common_code_str[]); extern bool common_code_to_string_shorten(uint64_t common_code, char common_code_str[]); extern bool common_code_from_string(const char common_code_str[], uint64_t *common_code); diff --git a/src/klotski/ffi/version.cc b/src/klotski/ffi/metadata.cc similarity index 100% rename from src/klotski/ffi/version.cc rename to src/klotski/ffi/metadata.cc diff --git a/src/main.c b/src/main.c index 19d4f6e..2fdcb46 100644 --- a/src/main.c +++ b/src/main.c @@ -29,7 +29,7 @@ int main() { printf("short code -> %d\n", short_code); } - char common_code_str[common_code_string_size]; + char common_code_str[COMMON_CODE_STR_SIZE]; if (!common_code_to_string(common_code, common_code_str)) { printf("error\n"); } else { @@ -46,7 +46,7 @@ int main() { printf("common code -> %09lX\n", common_code); } - char short_code_str[short_code_string_size]; + char short_code_str[SHORT_CODE_STR_SIZE]; if (!short_code_to_string(short_code, short_code_str)) { printf("error\n"); } else {