Browse Source

feat: hash support of klotski code

master
Dnomd343 4 weeks ago
parent
commit
0bc80d89e5
  1. 15
      src/core/common_code/internal/common_code.inl
  2. 18
      src/core/main.cc
  3. 15
      src/core/raw_code/internal/raw_code.inl
  4. 15
      src/core/short_code/internal/short_code.inl

15
src/core/common_code/internal/common_code.inl

@ -138,3 +138,18 @@ constexpr auto operator<=>(const CommonCode &lhs, const CommonCode &rhs) {
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
} // namespace klotski::codec } // namespace klotski::codec
// ----------------------------------------------------------------------------------------- //
namespace std {
template <>
struct std::hash<klotski::codec::CommonCode> {
constexpr std::size_t operator()(const klotski::codec::CommonCode &c) const noexcept {
return std::hash<uint64_t>{}(c.unwrap());
}
};
} // namespace std
// ----------------------------------------------------------------------------------------- //

18
src/core/main.cc

@ -32,6 +32,7 @@ using klotski::cases::GroupCases;
using klotski::cases::GroupUnion; using klotski::cases::GroupUnion;
using klotski::cases::TYPE_ID_LIMIT; using klotski::cases::TYPE_ID_LIMIT;
using klotski::cases::ALL_CASES_NUM_;
using klotski::codec::SHORT_CODE_LIMIT; using klotski::codec::SHORT_CODE_LIMIT;
int main() { int main() {
@ -42,6 +43,23 @@ int main() {
const auto start = std::chrono::system_clock::now(); const auto start = std::chrono::system_clock::now();
ShortCode::speed_up(true);
std::unordered_set<RawCode> data_r;
std::unordered_set<ShortCode> data_s;
std::unordered_set<CommonCode> data_c;
data_r.reserve(ALL_CASES_NUM_);
data_s.reserve(ALL_CASES_NUM_);
data_c.reserve(ALL_CASES_NUM_);
for (auto code : AllCases::instance().fetch().codes()) {
data_c.emplace(code);
data_r.emplace(code.to_raw_code());
data_s.emplace(code.to_short_code());
}
std::cout << data_r.size() << std::endl;
std::cout << data_s.size() << std::endl;
std::cout << data_c.size() << std::endl;
// const auto common_code = CommonCode::unsafe_create(0x1A9BF0C00); // const auto common_code = CommonCode::unsafe_create(0x1A9BF0C00);
// const auto group = Group::from_common_code(common_code); // const auto group = Group::from_common_code(common_code);

15
src/core/raw_code/internal/raw_code.inl

@ -94,3 +94,18 @@ constexpr auto operator<=>(const RawCode &lhs, const RawCode &rhs) {
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
} // namespace klotski::codec } // namespace klotski::codec
// ----------------------------------------------------------------------------------------- //
namespace std {
template <>
struct std::hash<klotski::codec::RawCode> {
constexpr std::size_t operator()(const klotski::codec::RawCode &r) const noexcept {
return std::hash<uint64_t>{}(r.unwrap());
}
};
} // namespace std
// ----------------------------------------------------------------------------------------- //

15
src/core/short_code/internal/short_code.inl

@ -116,3 +116,18 @@ constexpr auto operator<=>(const ShortCode &lhs, const ShortCode &rhs) {
// ----------------------------------------------------------------------------------------- // // ----------------------------------------------------------------------------------------- //
} // namespace klotski::codec } // namespace klotski::codec
// ----------------------------------------------------------------------------------------- //
namespace std {
template <>
struct std::hash<klotski::codec::ShortCode> {
constexpr std::size_t operator()(const klotski::codec::ShortCode &s) const noexcept {
return std::hash<uint32_t>{}(s.unwrap());
}
};
} // namespace std
// ----------------------------------------------------------------------------------------- //

Loading…
Cancel
Save