Browse Source

update: header file of Group

master
Dnomd343 4 months ago
parent
commit
3e939267a7
  1. 171
      src/core/group/group.h
  2. 1
      src/core/group/internal/group_cases.cc

171
src/core/group/group.h

@ -83,150 +83,153 @@ class Group;
// TODO: add constexpr // TODO: add constexpr
class GroupUnion { class GroupUnion {
public: public:
GroupUnion() = delete; GroupUnion() = delete;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get the original type id. /// Get the original type id.
[[nodiscard]] constexpr uint32_t unwrap() const; [[nodiscard]] constexpr uint32_t unwrap() const;
/// Create GroupUnion without any check. /// Create GroupUnion without any check.
static constexpr GroupUnion unsafe_create(uint32_t type_id); static constexpr GroupUnion unsafe_create(uint32_t type_id);
/// Create GroupUnion with validity check. /// Create GroupUnion with validity check.
static constexpr std::optional<GroupUnion> create(uint32_t type_id); static constexpr std::optional<GroupUnion> create(uint32_t type_id);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get the number of cases contained. /// Get the number of cases contained.
[[nodiscard]] constexpr uint32_t size() const; [[nodiscard]] constexpr uint32_t size() const;
/// 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 upper limit of the group size.
[[nodiscard]] constexpr uint32_t max_group_size() const; [[nodiscard]] constexpr uint32_t max_group_size() const;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get all cases under the current type id. /// Get all cases under the current type id.
[[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]] std::vector<Group> groups() const;
/// Get the group instance with the specified group id. /// Get the group instance with the specified group id.
[[nodiscard]] std::optional<Group> group(uint32_t group_id) const; [[nodiscard]] std::optional<Group> group(uint32_t group_id) const;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Create GroupUnion from RawCode. /// Create GroupUnion from RawCode.
static GroupUnion from_raw_code(codec::RawCode raw_code); static 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 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 GroupUnion from_common_code(codec::CommonCode common_code);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
private: private:
uint32_t type_id_; uint32_t type_id_;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get the type id of RawCode. /// Get the type id of RawCode.
static KLSK_INLINE uint32_t type_id(codec::RawCode raw_code); static KLSK_INLINE uint32_t type_id(codec::RawCode raw_code);
/// Get the type id of CommonCode. /// Get the type id of CommonCode.
static KLSK_INLINE uint32_t type_id(codec::CommonCode common_code); static KLSK_INLINE uint32_t type_id(codec::CommonCode common_code);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
}; };
class Group { class Group {
public: public:
Group() = delete; Group() = delete;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get the original type id. /// Get the original type id.
[[nodiscard]] uint32_t type_id() const; [[nodiscard]] uint32_t type_id() const;
/// Get the original group id. /// Get the original group id.
[[nodiscard]] uint32_t group_id() const; [[nodiscard]] uint32_t group_id() const;
/// Create Group without any check. /// Create Group without any check.
static Group unsafe_create(uint32_t type_id, uint32_t group_id); static Group unsafe_create(uint32_t type_id, uint32_t group_id);
/// Create Group with validity check. /// Create Group with validity check.
static std::optional<Group> create(uint32_t type_id, uint32_t group_id); static std::optional<Group> create(uint32_t type_id, uint32_t group_id);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Get the number of cases contained. /// Get the number of cases contained.
[[nodiscard]] uint32_t size() const; [[nodiscard]] uint32_t size() const;
/// Get all cases under the current group. /// Get all cases under the current group.
[[nodiscard]] RangesUnion cases() const; [[nodiscard]] RangesUnion cases() const;
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Create Group from RawCode. /// Create Group from RawCode.
static Group from_raw_code(codec::RawCode raw_code); static Group from_raw_code(codec::RawCode raw_code);
/// Create Group from ShortCode. /// Create Group from ShortCode.
static Group from_short_code(codec::ShortCode short_code); static Group from_short_code(codec::ShortCode short_code);
/// Create Group from CommonCode. /// Create Group from CommonCode.
static Group from_common_code(codec::CommonCode common_code); static Group from_common_code(codec::CommonCode common_code);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
private: private:
uint32_t type_id_; uint32_t type_id_;
uint32_t group_id_; uint32_t group_id_;
[[nodiscard]] uint32_t flat_id() const; [[nodiscard]] uint32_t flat_id() const;
public: public:
static std::vector<codec::RawCode> extend(codec::RawCode raw_code, uint32_t reserve = 0); /// Spawn all the unsorted codes of the current group.
static std::vector<codec::RawCode> extend(codec::RawCode raw_code, uint32_t reserve = 0);
}; };
class GroupCases { class GroupCases {
public: public:
struct info_t { struct info_t {
uint16_t type_id; uint16_t type_id;
uint16_t group_id; uint16_t group_id;
uint32_t case_id; uint32_t case_id;
// TODO: should we keep it valid? (convert without check) // TODO: should we keep it valid? (convert without check)
}; };
void build(); /// Execute the build process.
void build();
void build_async(Executor &&executor, Notifier &&notifier); /// Execute the build process without blocking.
void build_async(Executor &&executor, Notifier &&callback);
/// Get the CommonCode using the group info. static info_t to_info_t(codec::ShortCode short_code);
// static codec::CommonCode parse(const info_t &info);
/// Get group info according to specified case. static codec::CommonCode from_info_t(info_t info);
// static info_t encode(const codec::RawCode &raw_code);
// static info_t encode(const codec::CommonCode &common_code);
static info_t to_info_t(codec::ShortCode short_code); /// Get the CommonCode using the group info.
// static codec::CommonCode parse(const info_t &info);
static codec::CommonCode from_info_t(info_t info); /// Get group info according to specified case.
// static info_t encode(const codec::RawCode &raw_code);
// static info_t encode(const codec::CommonCode &common_code);
private: private:
bool available_ = false; bool available_ = false;
std::mutex building_ {}; std::mutex building_ {};
// static codec::CommonCode fast_decode(const info_t &info); // static codec::CommonCode fast_decode(const info_t &info);
// static info_t fast_encode(const codec::CommonCode &common_code); // static info_t fast_encode(const codec::CommonCode &common_code);
KLSK_INSTANCE(GroupCases) KLSK_INSTANCE(GroupCases)
}; };
} // namespace klotski::cases } // namespace klotski::cases

1
src/core/group/internal/group_cases.cc

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <algorithm>
#include "group/group.h" #include "group/group.h"

Loading…
Cancel
Save