Browse Source

perf: optimize of full mirror group cases

master
Dnomd343 1 week ago
parent
commit
0f30300eb1
  1. 29
      src/core/benchmark/group.cc
  2. 37
      src/core/group/internal/group.cc
  3. 66
      src/core/main.cc

29
src/core/benchmark/group.cc

@ -134,18 +134,23 @@ static void GroupExtend(benchmark::State &state) {
for (auto _ : state) {
for (int type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
for (auto group : GroupUnion::unsafe_create(type_id).groups()) {
// if (group.mirror_type() == Group::MirrorType::Full) {
// if (group.mirror_type() == Group::MirrorType::Horizontal) {
// if (group.mirror_type() == Group::MirrorType::Centro) {
// if (group.mirror_type() == Group::MirrorType::Vertical) {
if (group.mirror_type() == Group::MirrorType::Ordinary) {
// std::println("{} ({})", group.to_string(), group.size());
volatile auto kk = group.cases();
}
}
}
// for (int type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
// for (auto group : GroupUnion::unsafe_create(type_id).groups()) {
// // if (group.mirror_type() == Group::MirrorType::Full) {
// // if (group.mirror_type() == Group::MirrorType::Horizontal) {
// // if (group.mirror_type() == Group::MirrorType::Centro) {
// // if (group.mirror_type() == Group::MirrorType::Vertical) {
// if (group.mirror_type() == Group::MirrorType::Ordinary) {
// // std::println("{} ({})", group.to_string(), group.size());
// volatile auto kk = group.cases();
// }
// }
// }
constexpr auto group = Group::unsafe_create(89, 0, Group::Toward::A);
// constexpr auto group = Group::unsafe_create(51, 0, Group::Toward::A);
volatile auto kk = group.cases();
// for (auto group : groups) {
// volatile auto tmp = group.cases();

37
src/core/group/internal/group.cc

@ -106,12 +106,47 @@ static RangesUnion extend_type_x(RawCode seed, size_t reserve) {
});
}
KLSK_NOINLINE static RangesUnion extend_pro(uint8_t type_id) {
// std::cout << (int)type_id << std::endl;
auto groups = GroupUnion::unsafe_create(type_id).groups();
RangesUnion others {};
for (size_t index = 1; index < groups.size(); ++index) {
others += groups[index].cases();
}
// std::cout << others.size() << std::endl;
auto all = GroupUnion::unsafe_create(type_id).cases();
// std::cout << all.size() << std::endl;
RangesUnion result {};
for (auto head : RangesUnion::Heads) {
std::stable_sort(others.ranges(head).begin(), others.ranges(head).end());
std::set_difference(all.ranges(head).begin(), all.ranges(head).end(),
others.ranges(head).begin(), others.ranges(head).end(),
std::back_inserter(result.ranges(head)));
}
// std::cout << result.size() << std::endl;
return result;
}
RangesUnion Group::cases() const {
if (const auto gu = GroupUnion::unsafe_create(type_id()); gu.group_num() == 1) {
if (const auto gu = GroupUnion::unsafe_create(type_id_); gu.group_num() == 1) {
// std::cout << "[]" << std::endl;
return gu.cases();
}
// if (type_id_ == 89 && pattern_id_ == 0) { // for group `89-0x`
// return extend_pro(89);
// }
if (pattern_id_ == 0 && mirror_type() == MirrorType::Full) { // TODO: black-list filter
return extend_pro(type_id_);
}
auto seed = CommonCode::unsafe_create(PATTERN_DATA[flat_id()] >> 23).to_raw_code();
if (toward_ == Toward::B) {
seed = seed.to_horizontal_mirror();

66
src/core/main.cc

@ -70,10 +70,64 @@ int main() {
// std::println("{}: {}", kk.to_string(), kk.size());
// }
for (int type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
for (auto group : GroupUnion::unsafe_create(type_id).groups()) {
// if (group.mirror_type() == Group::MirrorType::Full) {
if (group.mirror_type() == Group::MirrorType::Horizontal) {
// 0.960 27-0x
// 0.992 40-0x
// 0.999 50-0x
// 0.890 51-0x
// 0.996 61-0x
// 0.955 62-0x
// 0.982 73-0x
// 0.992 81-0x
// 0.786 82-0x
// 0.999 89-0x
// 0.989 90-0x
// 0.892 91-0x
// 0.998 98-0x
// 0.993 99-0x
// 0.942 100-0x
// 0.999 108-0x
// 0.968 109-0x
// 0.973 115-0x
// 0.641 116-0x
// 0.998 121-0x
// 0.969 122-0x
// 0.801 123-0x
// 0.998 127-0x
// 0.994 128-0x
// 0.976 129-0x
// 0.865 130-0x
// 0.999 134-0x
// 0.997 135-0x
// 0.990 136-0x
// 0.909 137-0x
// 0.998 143-0x
// 0.956 144-0x
// 0.933 148-0x
// 0.554 149-0x
// 0.988 152-0x
// 0.888 153-0x
// 0.558 154-0x
// 0.989 155-0x
// 0.989 156-0x
// 0.978 157-0x
// 0.930 158-0x
// 0.762 159-0x
// 0.977 161-0x
// 0.960 162-0x
// 0.928 163-0x
// 0.744 164-0x
// 0.997 167-0x
// 0.990 168-0x
// 0.584 181-0x
// 0.350 184-0x
// 0.313 185-0x
// 0.933 187-0x
// 0.342 188-0x
for (uint8_t type_id = 0; type_id < TYPE_ID_LIMIT; ++type_id) {
for (auto group: GroupUnion::unsafe_create(type_id).groups()) {
if (group.mirror_type() == Group::MirrorType::Full) {
// if (group.mirror_type() == Group::MirrorType::Horizontal) {
// if (group.mirror_type() == Group::MirrorType::Centro) {
// if (group.mirror_type() == Group::MirrorType::Vertical) {
// if (group.mirror_type() == Group::MirrorType::Ordinary) {
@ -83,6 +137,10 @@ int main() {
}
}
// constexpr auto group = Group::unsafe_create(89, 0, Group::Toward::A);
// std::cout << group.to_string() << std::endl;
// volatile auto kk = group.cases();
// const auto code = CommonCode::unsafe_create(0x1A9BF0C00).to_raw_code();
// const auto solve_1 = CommonCode::unsafe_create(0xDAAF4CC00).to_raw_code();
// const auto solve_2 = CommonCode::unsafe_create(0xDAA7F3000).to_raw_code();

Loading…
Cancel
Save