Browse Source

feat: all cases export as common code

master
Dnomd343 2 years ago
parent
commit
3ec9836d6a
  1. 2
      src/klotski/CMakeLists.txt
  2. 19
      src/klotski/ffi/all_cases.cc
  3. 4
      src/klotski/ffi/codec.cc
  4. 10
      src/klotski/ffi/klotski.h
  5. 0
      src/klotski/ffi/metadata.cc
  6. 4
      src/main.c

2
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})

19
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;
}
}

4
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)) {

10
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);

0
src/klotski/ffi/version.cc → src/klotski/ffi/metadata.cc

4
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 {

Loading…
Cancel
Save