diff --git a/src/core/group/group.h b/src/core/group/group.h index 2b2fe74..8e076b4 100644 --- a/src/core/group/group.h +++ b/src/core/group/group.h @@ -394,8 +394,10 @@ private: #include "internal/type_id.inl" #include "internal/group_union.inl" -#include "internal/group_cases.inl" + #include "internal/group.inl" -#include "internal/case_info.inl" #include "internal/group_mirror.inl" + +#include "internal/group_cases.inl" +#include "internal/case_info.inl" #include "internal/hash.inl" diff --git a/src/core/group/internal/case_info.inl b/src/core/group/internal/case_info.inl index aa2102e..baf668f 100644 --- a/src/core/group/internal/case_info.inl +++ b/src/core/group/internal/case_info.inl @@ -9,6 +9,10 @@ inline std::ostream& operator<<(std::ostream &out, CaseInfo self) { return out; } +constexpr auto operator==(const CaseInfo &lhs, const CaseInfo &rhs) { + return lhs.group_ == rhs.group_ && lhs.case_id_ == rhs.case_id_; +} + inline std::string CaseInfo::to_string() const { return std::format("{}-{}", group_.to_string(), case_id_); } @@ -21,17 +25,17 @@ constexpr uint32_t CaseInfo::case_id() const { return case_id_; } -constexpr std::optional CaseInfo::create(Group group, uint32_t case_id) { +constexpr std::optional CaseInfo::create(const Group group, const uint32_t case_id) { if (case_id >= group.size()) { return std::nullopt; } return unsafe_create(group, case_id); } -constexpr CaseInfo CaseInfo::unsafe_create(Group group, uint32_t case_id) { +constexpr CaseInfo CaseInfo::unsafe_create(const Group group, const uint32_t case_id) { return {group, case_id}; } -constexpr CaseInfo::CaseInfo(Group group, uint32_t case_id) : group_(group), case_id_(case_id) {} +constexpr CaseInfo::CaseInfo(const Group group, const uint32_t case_id) : group_(group), case_id_(case_id) {} } // namespace klotski::group diff --git a/src/core/group/internal/group.inl b/src/core/group/internal/group.inl index a1f3171..a7e0d9f 100644 --- a/src/core/group/internal/group.inl +++ b/src/core/group/internal/group.inl @@ -26,20 +26,22 @@ constexpr char Group::toward_char() const { case MirrorType::Horizontal: return (toward_ == Toward::A) ? 'n' : 'u'; case MirrorType::Centro: - return (toward_ == Toward::A) ? '?' : '!'; // TODO: select chars for centro + return (toward_ == Toward::A) ? 'h' : 's'; case MirrorType::Vertical: return (toward_ == Toward::A) ? 'p' : 'q'; case MirrorType::Ordinary: if (toward_ == Toward::A) { return 'a'; - } else if (toward_ == Toward::B) { + } + if (toward_ == Toward::B) { return 'b'; - } else if (toward_ == Toward::C) { + } + if (toward_ == Toward::C) { return 'c'; - } else if (toward_ == Toward::D) { + } + if (toward_ == Toward::D) { return 'd'; } - return '\0'; // TODO: never reach } return '\0'; // TODO: never reach } @@ -47,7 +49,7 @@ constexpr char Group::toward_char() const { // ----------------------------------------------------------------------------------------- // #ifndef KLSK_NDEBUG -inline std::ostream& operator<<(std::ostream &out, Group self) { +inline std::ostream& operator<<(std::ostream &out, const Group self) { out << self.to_string(); return out; } @@ -62,16 +64,16 @@ inline std::string Group::to_string() const { } constexpr auto operator==(const Group &lhs, const Group &rhs) { - return lhs.type_id_ == rhs.type_id_ - && lhs.pattern_id_ == rhs.pattern_id_ - && lhs.toward_ == rhs.toward_; + return lhs.toward_ == rhs.toward_ + && lhs.type_id_ == rhs.type_id_ + && lhs.pattern_id_ == rhs.pattern_id_; } -constexpr Group Group::unsafe_create(uint_fast8_t type_id, uint_fast16_t pattern_id, Toward toward) { +constexpr Group Group::unsafe_create(const uint_fast8_t type_id, const uint_fast16_t pattern_id, const Toward toward) { return {toward, type_id, pattern_id}; } -constexpr std::optional Group::create(uint_fast8_t type_id, uint_fast16_t pattern_id, Toward toward) { +constexpr std::optional Group::create(const uint_fast8_t type_id, const uint_fast16_t pattern_id, const Toward toward) { if (type_id >= TYPE_ID_LIMIT) { return std::nullopt; } @@ -90,11 +92,11 @@ constexpr uint32_t Group::size() const { return (PATTERN_DATA[flat_id()] >> 3) & 0xFFFFF; } -inline Group Group::from_short_code(codec::ShortCode short_code) { +inline Group Group::from_short_code(const codec::ShortCode short_code) { return from_common_code(short_code.to_common_code()); } -inline Group Group::from_common_code(codec::CommonCode common_code) { +inline Group Group::from_common_code(const codec::CommonCode common_code) { return from_raw_code(common_code.to_raw_code()); } diff --git a/src/core/group/internal/group_cases.cc b/src/core/group/internal/group_cases.cc index 89d03b2..6499986 100644 --- a/src/core/group/internal/group_cases.cc +++ b/src/core/group/internal/group_cases.cc @@ -131,7 +131,7 @@ CommonCode GroupCases::fast_obtain_code(CaseInfo info) { return CommonCode::unsafe_create(head << 32 | range); } -CaseInfo GroupCases::fast_obtain_info(ShortCode short_code) { +CaseInfo GroupCases::fast_obtain_info(const ShortCode short_code) { uint16_t type_id = GroupUnion::from_short_code(short_code).unwrap(); // NOTE: need to convert as CommonCode uint16_t pattern_id = (*rev_data)[short_code.unwrap()].pattern_id; uint16_t toward_id = (*rev_data)[short_code.unwrap()].toward_id; @@ -141,7 +141,7 @@ CaseInfo GroupCases::fast_obtain_info(ShortCode short_code) { return CaseInfo::unsafe_create(group, case_id); } -CaseInfo GroupCases::fast_obtain_info(CommonCode common_code) { +CaseInfo GroupCases::fast_obtain_info(const CommonCode common_code) { auto short_code = common_code.to_short_code(); uint16_t type_id = GroupUnion::from_common_code(common_code).unwrap(); uint16_t pattern_id = (*rev_data)[short_code.unwrap()].pattern_id; @@ -152,14 +152,14 @@ CaseInfo GroupCases::fast_obtain_info(CommonCode common_code) { return CaseInfo::unsafe_create(group, case_id); } -Group GroupCases::fast_obtain_group(codec::ShortCode short_code) { +Group GroupCases::fast_obtain_group(const ShortCode short_code) { uint16_t type_id = GroupUnion::from_short_code(short_code).unwrap(); uint16_t pattern_id = (*rev_data)[short_code.unwrap()].pattern_id; uint16_t toward_id = (*rev_data)[short_code.unwrap()].toward_id; return Group::unsafe_create(type_id, pattern_id, (Group::Toward)toward_id); } -Group GroupCases::fast_obtain_group(codec::CommonCode common_code) { +Group GroupCases::fast_obtain_group(const CommonCode common_code) { auto short_code = common_code.to_short_code(); uint16_t type_id = GroupUnion::from_common_code(common_code).unwrap(); uint16_t pattern_id = (*rev_data)[short_code.unwrap()].pattern_id; @@ -227,7 +227,7 @@ static std::vector Group_extend_for_obtain_info(RawCode raw_code) { return codes; } -CaseInfo GroupCases::tiny_obtain_info(CommonCode common_code) { +CaseInfo GroupCases::tiny_obtain_info(const CommonCode common_code) { auto raw_codes = Group_extend_for_obtain_info(common_code.to_raw_code()); std::vector common_codes; common_codes.reserve(raw_codes.size()); diff --git a/src/core/group/internal/group_cases.inl b/src/core/group/internal/group_cases.inl index a6b1535..c243d8a 100644 --- a/src/core/group/internal/group_cases.inl +++ b/src/core/group/internal/group_cases.inl @@ -9,28 +9,28 @@ inline codec::CommonCode GroupCases::obtain_code(CaseInfo info) { return tiny_obtain_code(info); } -inline CaseInfo GroupCases::obtain_info(codec::CommonCode common_code) { +inline CaseInfo GroupCases::obtain_info(const codec::CommonCode common_code) { if (fast_) { return fast_obtain_info(common_code); } return tiny_obtain_info(common_code); } -inline Group GroupCases::obtain_group(codec::CommonCode common_code) { +inline Group GroupCases::obtain_group(const codec::CommonCode common_code) { if (fast_) { return fast_obtain_group(common_code); } return Group::from_common_code(common_code); } -inline Group GroupCases::obtain_group(codec::ShortCode short_code) { +inline Group GroupCases::obtain_group(const codec::ShortCode short_code) { if (fast_) { return fast_obtain_group(short_code); } return Group::from_short_code(short_code); } -inline CaseInfo GroupCases::obtain_info(codec::ShortCode short_code) { +inline CaseInfo GroupCases::obtain_info(const codec::ShortCode short_code) { if (fast_) { return fast_obtain_info(short_code); }