|
@ -81,11 +81,12 @@ typedef std::vector<codec::CommonCode> CommonCodes; |
|
|
|
|
|
|
|
|
class Group; |
|
|
class Group; |
|
|
|
|
|
|
|
|
// TODO: add constexpr
|
|
|
|
|
|
class GroupUnion { |
|
|
class GroupUnion { |
|
|
public: |
|
|
public: |
|
|
GroupUnion() = delete; |
|
|
GroupUnion() = delete; |
|
|
|
|
|
|
|
|
|
|
|
using Groups = std::vector<Group>; |
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
/// Get the original type id.
|
|
|
/// Get the original type id.
|
|
@ -105,17 +106,11 @@ public: |
|
|
/// Get the number of groups contained.
|
|
|
/// Get the number of groups contained.
|
|
|
[[nodiscard]] constexpr uint32_t group_num() const; |
|
|
[[nodiscard]] constexpr uint32_t group_num() const; |
|
|
|
|
|
|
|
|
/// Get the upper limit of the group size.
|
|
|
/// Get the number of patterns contained.
|
|
|
[[nodiscard]] constexpr uint32_t max_group_size() const; |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
/// TODO: new interface
|
|
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr uint32_t pattern_num() const; |
|
|
[[nodiscard]] constexpr uint32_t pattern_num() const; |
|
|
|
|
|
|
|
|
[[nodiscard]] std::vector<Group> groups_pro() const; |
|
|
/// Get the upper limit of the group size.
|
|
|
|
|
|
[[nodiscard]] constexpr uint32_t max_group_size() const; |
|
|
// TODO: get target pattern_id
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
@ -123,21 +118,26 @@ public: |
|
|
[[nodiscard]] RangesUnion cases() const; |
|
|
[[nodiscard]] RangesUnion cases() const; |
|
|
|
|
|
|
|
|
/// Get all groups under the current type id.
|
|
|
/// Get all groups under the current type id.
|
|
|
// [[nodiscard]] std::vector<Group> groups() const;
|
|
|
[[nodiscard]] constexpr Groups groups() const; |
|
|
|
|
|
|
|
|
/// Get the group instance with the specified group id.
|
|
|
/// Get the group instance with the specified pattern id.
|
|
|
// [[nodiscard]] std::optional<Group> group(uint32_t group_id) const;
|
|
|
[[nodiscard]] constexpr std::optional<Groups> groups(uint32_t pattern_id) const; |
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
/// Create GroupUnion from RawCode.
|
|
|
/// Create GroupUnion from RawCode.
|
|
|
static GroupUnion from_raw_code(codec::RawCode raw_code); |
|
|
static constexpr GroupUnion from_raw_code(codec::RawCode raw_code); |
|
|
|
|
|
|
|
|
/// Create GroupUnion from ShortCode.
|
|
|
/// Create GroupUnion from ShortCode.
|
|
|
static GroupUnion from_short_code(codec::ShortCode short_code); |
|
|
static constexpr GroupUnion from_short_code(codec::ShortCode short_code); |
|
|
|
|
|
|
|
|
/// Create GroupUnion from CommonCode.
|
|
|
/// Create GroupUnion from CommonCode.
|
|
|
static GroupUnion from_common_code(codec::CommonCode common_code); |
|
|
static constexpr GroupUnion from_common_code(codec::CommonCode common_code); |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
|
|
|
/// Compare the type_id values of two GroupUnion.
|
|
|
|
|
|
friend constexpr auto operator==(const GroupUnion &lhs, const GroupUnion &rhs); |
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
@ -155,8 +155,6 @@ private: |
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// TODO: add `==` and `std::hash`
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: add debug output
|
|
|
// TODO: add debug output
|
|
|
|
|
|
|
|
|
class Group { |
|
|
class Group { |
|
@ -239,6 +237,11 @@ public: |
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
|
|
|
/// Compare the internal values of two Group.
|
|
|
|
|
|
friend constexpr auto operator==(const Group &lhs, const Group &rhs); |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
uint32_t type_id_; |
|
|
uint32_t type_id_; |
|
|
Toward toward_; |
|
|
Toward toward_; |
|
@ -351,3 +354,26 @@ public: |
|
|
#include "internal/group_union.inl" |
|
|
#include "internal/group_union.inl" |
|
|
#include "internal/group_cases.inl" |
|
|
#include "internal/group_cases.inl" |
|
|
#include "internal/group.inl" |
|
|
#include "internal/group.inl" |
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
|
|
|
|
namespace std { |
|
|
|
|
|
|
|
|
|
|
|
template <> |
|
|
|
|
|
struct std::hash<klotski::cases::Group> { |
|
|
|
|
|
constexpr std::size_t operator()(const klotski::cases::Group &g) const noexcept { |
|
|
|
|
|
// TODO: perf hash alg
|
|
|
|
|
|
return std::hash<uint64_t>{}(g.type_id() ^ g.pattern_id() ^ (int)g.toward()); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
template <> |
|
|
|
|
|
struct std::hash<klotski::cases::GroupUnion> { |
|
|
|
|
|
constexpr std::size_t operator()(const klotski::cases::GroupUnion &gu) const noexcept { |
|
|
|
|
|
return std::hash<uint32_t>{}(gu.unwrap()); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------------------- //
|
|
|