Browse Source

feat: demo of fast group case info

master
Dnomd343 1 year ago
parent
commit
483b9f62c0
  1. 2
      src/klotski_core/ffi/tmain.cc
  2. 2
      src/klotski_core/group/group.h
  3. 54
      src/klotski_core/group/group_info.cc

2
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));
//

2
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);

54
src/klotski_core/group/group_info.cc

@ -2,6 +2,8 @@
#include "group.h"
#include "type_id.h"
#include <iostream>
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<uint32_t> group_info(SHORT_CODE_LIMIT);
std::vector<std::vector<ShortCode>> group_data[TYPE_ID_LIMIT];
ShortCode::speed_up(ShortCode::FAST);
auto convert = [](const std::vector<RawCode> &raw_codes) -> std::vector<CommonCode> {
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

Loading…
Cancel
Save