From 97209ee3f2ced054b4c03a7c4fb26378d5e1a028 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 11 Apr 2023 15:26:53 +0800 Subject: [PATCH] update: verify group_id and group_index --- src/klotski_core/ffi/tmain.cc | 70 ++++++++++++++++++++++++++++++--- src/klotski_core/group/group.cc | 2 +- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 63a4fa5..499569e 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -4,6 +4,7 @@ #include #include +#include #include "klotski.h" #include "core.h" @@ -20,23 +21,80 @@ using klotski::Group; using klotski::AllCases; using klotski::RawCode; +using klotski::ShortCode; using klotski::CommonCode; using klotski::Benchmark; using klotski::BasicRanges; + void tmain() { // printf("tmain start\n"); -// auto ret = Group::build_groups(0); -// std::cout << ret[0].size() << std::endl; +// auto c = CommonCode(0x1A9BF0C00); + +// auto groups = Group::build_groups(Group::type_id(c)); +// for (uint32_t i = 0; i < groups.size(); ++i) { +// std::cout << g.size() << std::endl; +// if (std::find(groups[i].begin(), groups[i].end(), c) != groups[i].end()) { +// std::cout << i << " -> " << groups[i].size() << std::endl; +// } else { +// std::cout << "not found" << std::endl; +// } +// +// } + + struct group_info_t { + uint16_t type_id; + uint16_t group_id; + uint32_t group_index; + }; + +// std::unordered_map data; + + std::vector data; + + data.resize(klotski::SHORT_CODE_LIMIT); + + ShortCode::speed_up(ShortCode::FAST); + +// uint16_t type_id = 123; + + for (uint16_t type_id = 0; type_id < klotski::TYPE_ID_LIMIT; ++type_id) { + auto groups = Group::build_groups(type_id); + for (uint32_t id = 0; id < groups.size(); ++id) { -// auto g = Group::build_groups(123); -// std::cout << g.size() << std::endl; + std::sort(groups[id].begin(), groups[id].end()); - for (uint32_t type_id = 0; type_id < 204; ++type_id) { - std::cout << Group::build_groups(type_id).size() << std::endl; + for (uint32_t index = 0; index < groups[id].size(); ++index) { + data[groups[id][index].to_short_code().unwrap()] = { + .type_id = type_id, + .group_id = static_cast(id), + .group_index = index, + }; + } + } +// std::cout << type_id << std::endl; + std::cerr << type_id << std::endl; } +// std::cout << data.size() << std::endl; + + for (auto &&tmp : data) { + std::cout << tmp.group_index << std::endl; + } + + +// for (auto &&g : Group::build_groups(123)) { + +// std::cout << *std::min_element(g.begin(), g.end()) << std::endl; + +// std::cout << g.size() << std::endl; +// } + +// for (uint32_t type_id = 0; type_id < 204; ++type_id) { +// std::cout << Group::build_groups(type_id).size() << std::endl; +// } + // printf("tmain exit\n"); } diff --git a/src/klotski_core/group/group.cc b/src/klotski_core/group/group.cc index b72c504..b6178fb 100644 --- a/src/klotski_core/group/group.cc +++ b/src/klotski_core/group/group.cc @@ -107,7 +107,7 @@ std::vector> Group::build_groups(uint32_t type_id) { } auto compare_func = [](const std::vector &v1, const std::vector &v2) { - return v1.size() < v2.size(); // sort by vector size + return v1.size() > v2.size(); // sort by vector size }; std::stable_sort(groups.begin(), groups.end(), compare_func); // using stable sort for ordered index return groups;