From 4ea1570d43b1a4874910e40e71cd924f415cc8fa Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 29 Apr 2023 20:29:30 +0800 Subject: [PATCH] update: codec function inlining --- src/klotski_core/all_cases/basic_ranges.cc | 2 +- src/klotski_core/all_cases/basic_ranges.h | 2 +- src/klotski_core/common_code/common_code.cc | 10 ---------- src/klotski_core/common_code/common_code.h | 12 ++++++++++++ src/klotski_core/raw_code/raw_code.cc | 10 ---------- src/klotski_core/raw_code/raw_code.h | 12 ++++++++++++ src/klotski_core/short_code/short_code.cc | 10 ---------- src/klotski_core/short_code/short_code.h | 12 ++++++++++++ 8 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/klotski_core/all_cases/basic_ranges.cc b/src/klotski_core/all_cases/basic_ranges.cc index 8a3bae5..0930e1c 100644 --- a/src/klotski_core/all_cases/basic_ranges.cc +++ b/src/klotski_core/all_cases/basic_ranges.cc @@ -70,7 +70,7 @@ void BasicRanges::generate(basic_ranges_t &release, generate_t info) { constexpr auto MASK_10 = (uint32_t)0b10 << 30; constexpr auto MASK_11 = (uint32_t)0b11 << 30; - /// nx: n4 n3 n2 n1 + /// nx: n4 n3 n2 n1 /// 00000000 00000000 00000000 00000000 (32-bit) struct build_t { uint32_t nx; // (n4, n3, n2, n1) diff --git a/src/klotski_core/all_cases/basic_ranges.h b/src/klotski_core/all_cases/basic_ranges.h index 7ce4118..d059fdc 100644 --- a/src/klotski_core/all_cases/basic_ranges.h +++ b/src/klotski_core/all_cases/basic_ranges.h @@ -38,7 +38,7 @@ const uint32_t BASIC_RANGES_SIZE = 7311921; class BasicRanges { public: /// Three basic states, one-way transition. - /// {NO_INIT} -> {BUILDING} -> {AVAILABLE} + /// {NOT_INIT} -> {BUILDING} -> {AVAILABLE} enum Status { NOT_INIT, BUILDING, diff --git a/src/klotski_core/common_code/common_code.cc b/src/klotski_core/common_code/common_code.cc index 05a1cbc..6b4bd89 100644 --- a/src/klotski_core/common_code/common_code.cc +++ b/src/klotski_core/common_code/common_code.cc @@ -5,16 +5,6 @@ namespace klotski { using Common::range_reverse; -CommonCode CommonCode::create(uint64_t common_code) { - return CommonCode(common_code); // create from uint64_t -} - -CommonCode CommonCode::unsafe_create(uint64_t common_code) noexcept { // create without check - auto tmp = CommonCode(); // init directly - tmp.code_ = common_code; - return tmp; -} - CommonCode::CommonCode(uint64_t common_code) { if (!CommonCode::check(common_code)) { // check input common code throw klotski::CommonCodeExp("common code invalid"); diff --git a/src/klotski_core/common_code/common_code.h b/src/klotski_core/common_code/common_code.h index aa2f0f4..03af9c1 100644 --- a/src/klotski_core/common_code/common_code.h +++ b/src/klotski_core/common_code/common_code.h @@ -130,6 +130,18 @@ public: static CommonCodes convert(const ShortCodes &short_codes) noexcept; }; +/// CommonCode create +inline CommonCode CommonCode::create(uint64_t common_code) { + return CommonCode(common_code); // create from uint64_t +} + +/// CommonCode create without check +inline CommonCode CommonCode::unsafe_create(uint64_t common_code) noexcept { + auto tmp = CommonCode(); // init directly + tmp.code_ = common_code; + return tmp; +} + /// Compare implements inline bool operator==(uint64_t c1, const CommonCode &c2) noexcept { return c1 == c2.unwrap(); } inline bool operator==(const CommonCode &c1, uint64_t c2) noexcept { return c1.unwrap() == c2; } diff --git a/src/klotski_core/raw_code/raw_code.cc b/src/klotski_core/raw_code/raw_code.cc index 47991b0..dd7ccf1 100644 --- a/src/klotski_core/raw_code/raw_code.cc +++ b/src/klotski_core/raw_code/raw_code.cc @@ -3,16 +3,6 @@ namespace klotski { -RawCode RawCode::create(uint64_t raw_code) { - return RawCode(raw_code); -} - -RawCode RawCode::unsafe_create(uint64_t raw_code) noexcept { // create without check - auto tmp = RawCode(); // init directly - tmp.code_ = raw_code; - return tmp; -} - RawCode::RawCode(uint64_t raw_code) { if (!RawCode::check(raw_code)) { // check input raw code throw klotski::RawCodeExp("raw code invalid"); diff --git a/src/klotski_core/raw_code/raw_code.h b/src/klotski_core/raw_code/raw_code.h index 9df594f..7c28cd2 100644 --- a/src/klotski_core/raw_code/raw_code.h +++ b/src/klotski_core/raw_code/raw_code.h @@ -116,6 +116,18 @@ public: bool is_horizontal_mirror(const RawCode &raw_code) const noexcept; }; +/// RawCode create +inline RawCode RawCode::create(uint64_t raw_code) { + return RawCode(raw_code); +} + +/// RawCode create without check +inline RawCode RawCode::unsafe_create(uint64_t raw_code) noexcept { + auto tmp = RawCode(); // init directly + tmp.code_ = raw_code; + return tmp; +} + /// Compare implements inline bool operator==(uint64_t r1, const RawCode &r2) noexcept { return r1 == r2.unwrap(); } inline bool operator==(const RawCode &r1, uint64_t r2) noexcept { return r1.unwrap() == r2; } diff --git a/src/klotski_core/short_code/short_code.cc b/src/klotski_core/short_code/short_code.cc index ee68fdf..c89326f 100644 --- a/src/klotski_core/short_code/short_code.cc +++ b/src/klotski_core/short_code/short_code.cc @@ -6,16 +6,6 @@ namespace klotski { bool ShortCode::fast_mode_available_ = false; bool ShortCode::normal_mode_available_ = false; -ShortCode ShortCode::create(uint32_t short_code) { - return ShortCode(short_code); -} - -ShortCode ShortCode::unsafe_create(uint32_t short_code) noexcept { // create without check - auto tmp = ShortCode(); // init directly - tmp.code_ = short_code; - return tmp; -} - ShortCode::ShortCode(uint32_t short_code) { if (!ShortCode::check(short_code)) { // check input short code throw klotski::ShortCodeExp("short code invalid"); diff --git a/src/klotski_core/short_code/short_code.h b/src/klotski_core/short_code/short_code.h index 159fd3f..0856d27 100644 --- a/src/klotski_core/short_code/short_code.h +++ b/src/klotski_core/short_code/short_code.h @@ -141,6 +141,18 @@ public: static ShortCodes convert(const CommonCodes &common_codes) noexcept; }; +/// ShortCode create +inline ShortCode ShortCode::create(uint32_t short_code) { + return ShortCode(short_code); +} + +/// ShortCode create without check +inline ShortCode ShortCode::unsafe_create(uint32_t short_code) noexcept { + auto tmp = ShortCode(); // init directly + tmp.code_ = short_code; + return tmp; +} + /// Compare implements inline bool operator==(uint32_t s1, const ShortCode &s2) noexcept { return s1 == s2.unwrap(); } inline bool operator==(const ShortCode &s1, uint32_t s2) noexcept { return s1.unwrap() == s2; }