Browse Source

update: move serialize logic into `.inl` file

legacy
Dnomd343 2 weeks ago
parent
commit
920a2d6d02
  1. 2
      src/core/CMakeLists.txt
  2. 12
      src/core/benchmark/common_code.cc
  3. 1
      src/core/common_code/common_code.h
  4. 8
      src/core/common_code/internal/serialize.inl

2
src/core/CMakeLists.txt

@ -11,7 +11,7 @@ set(KLSK_CORE_SRC
all_cases/internal/all_cases.cc
# common_code/internal/common_code.cc
common_code/internal/serialize.cc
# common_code/internal/serialize.cc
# common_code/internal/mirror.cc
# raw_code/internal/raw_code.cc

12
src/core/benchmark/common_code.cc

@ -138,14 +138,14 @@ static void CommonCodeHorizontalMirror(benchmark::State &state) {
// BENCHMARK(CommonCodeCheck)->Range(8, 256);
// BENCHMARK(CommonCodeSerialize)->Range(8, 256);
// BENCHMARK(CommonCodeDeserialize)->Range(8, 256);
// BENCHMARK(CommonCodeSerializeShorten)->Range(8, 256);
// BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256);
BENCHMARK(CommonCodeSerialize)->Range(16, 1024);
BENCHMARK(CommonCodeDeserialize)->Range(16, 1024);
BENCHMARK(CommonCodeSerializeShorten)->Range(16, 1024);
BENCHMARK(CommonCodeDeserializeShorten)->Range(16, 1024);
// BENCHMARK(CommonCodeCheckMirror)->Range(64, 1024);
BENCHMARK(CommonCodeVerticalMirror)->Range(8, 256);
BENCHMARK(CommonCodeHorizontalMirror)->Range(8, 256);
// BENCHMARK(CommonCodeVerticalMirror)->Range(8, 256);
// BENCHMARK(CommonCodeHorizontalMirror)->Range(8, 256);
BENCHMARK_MAIN();

1
src/core/common_code/common_code.h

@ -199,6 +199,7 @@ static_assert(std::is_trivially_copyable_v<CommonCode>);
} // namespace klotski::codec
#include "internal/common_code.inl"
#include "internal/serialize.inl"
#include "internal/mirror.inl"
#include "internal/check.inl"

8
src/core/common_code/internal/serialize.cc → src/core/common_code/internal/serialize.inl

@ -1,4 +1,4 @@
#include "common_code/common_code.h"
#pragma once
namespace klotski::codec {
@ -53,7 +53,7 @@ constexpr auto CONVERT_TABLE = std::to_array<char>({
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
});
std::string CommonCode::string_encode(uint64_t common_code) {
inline std::string CommonCode::string_encode(uint64_t common_code) {
char code_str[9];
for (int i = 0; i < 9; ++i) {
code_str[8 - i] = to_hex_char(common_code & 0b1111);
@ -62,7 +62,7 @@ std::string CommonCode::string_encode(uint64_t common_code) {
return std::string{code_str, code_str + 9};
}
std::string CommonCode::string_encode_shorten(const uint64_t common_code) {
inline std::string CommonCode::string_encode_shorten(const uint64_t common_code) {
if (common_code == 0) {
return "0"; // special case
}
@ -71,7 +71,7 @@ std::string CommonCode::string_encode_shorten(const uint64_t common_code) {
return code;
}
std::optional<uint64_t> CommonCode::string_decode(const std::string_view common_code) {
inline std::optional<uint64_t> CommonCode::string_decode(const std::string_view common_code) {
if (common_code.length() > 9 || common_code.empty()) {
return std::nullopt; // invalid string length
}
Loading…
Cancel
Save