From 483b9f62c045c797d94ef4e962d8c0acdb3fe25e Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 21 Apr 2023 23:47:23 +0800 Subject: [PATCH] feat: demo of fast group case info --- src/klotski_core/ffi/tmain.cc | 2 ++ src/klotski_core/group/group.h | 2 ++ src/klotski_core/group/group_info.cc | 54 ++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 221b982..e4150a7 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -37,6 +37,8 @@ void tmain() { // auto start = clock(); + GroupCase::demo(); + // auto ret = GroupCase::encode(CommonCode(0x1A9BF0C00)); // auto ret = GroupCase::encode(CommonCode(0x4FEA13400)); // diff --git a/src/klotski_core/group/group.h b/src/klotski_core/group/group.h index e1b1ea9..3787331 100644 --- a/src/klotski_core/group/group.h +++ b/src/klotski_core/group/group.h @@ -162,6 +162,8 @@ public: uint32_t group_index; }; + static void demo(); + /// Get the CommonCode using the group info. static CommonCode parse(const info_t &info); diff --git a/src/klotski_core/group/group_info.cc b/src/klotski_core/group/group_info.cc index bc57661..36390c6 100644 --- a/src/klotski_core/group/group_info.cc +++ b/src/klotski_core/group/group_info.cc @@ -2,6 +2,8 @@ #include "group.h" #include "type_id.h" +#include + namespace klotski { /// --------------------------------------- Group Type ---------------------------------------- @@ -66,4 +68,56 @@ GroupCase::info_t GroupCase::encode(const CommonCode &common_code) noexcept { }; } +/// ------------------------------------- Group Case Fast ------------------------------------- + +void GroupCase::demo() { + std::cout << "ok" << std::endl; + + // short code -> group_id + group_index + + std::vector group_info(SHORT_CODE_LIMIT); + std::vector> group_data[TYPE_ID_LIMIT]; + + ShortCode::speed_up(ShortCode::FAST); + + auto convert = [](const std::vector &raw_codes) -> std::vector { + return {raw_codes.begin(), raw_codes.end()}; + }; + + for (uint32_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) { + auto tid = GroupType(type_id); + + group_data[type_id].resize(tid.group_num()); + + for (uint32_t group_id = 0; group_id < tid.group_num(); ++group_id) { + auto group = Group(tid, group_id); + + auto cases = convert(group.cases()); + std::sort(cases.begin(), cases.end()); + + for (uint32_t group_index = 0; group_index < cases.size(); ++group_index) { + auto short_code = cases[group_index].to_short_code(); + group_info[short_code.unwrap()] = (group_id << 20) | group_index; + group_data[type_id][group_id].emplace_back(short_code); + } + } + std::cerr << type_id << std::endl; + } + + + std::cout << group_data[169][1][7472].to_common_code() << std::endl; + std::cout << group_data[164][0][30833].to_common_code() << std::endl; + + auto src_1 = CommonCode(0x1A9BF0C00); + auto tmp_1 = group_info[src_1.to_short_code().unwrap()]; + std::cout << GroupType(src_1).unwrap() << "-" + << (tmp_1 >> 20) << "-" << (tmp_1 & 0xFFFFF) << std::endl; + + auto src_2 = CommonCode(0x4FEA13400); + auto tmp_2 = group_info[src_2.to_short_code().unwrap()]; + std::cout << GroupType(src_2).unwrap() << "-" + << (tmp_2 >> 20) << "-" << (tmp_2 & 0xFFFFF) << std::endl; + +} + } // namespace klotski