Browse Source

feat: operator overloading for append

legacy
Dnomd343 6 months ago
parent
commit
bce32d45a5
  1. 24
      src/core/ranges/internal/ranges.cc
  2. 8
      src/core/ranges/ranges.h
  3. 0
      src/core_test/cases/ranges_union.cc

24
src/core/ranges/internal/ranges.cc

@ -5,20 +5,30 @@ using klotski::cases::Ranges;
using klotski::codec::CommonCode;
using klotski::cases::RangesUnion;
static constexpr auto heads = std::to_array<uint64_t>({
0x0, 0x1, 0x2, 0x4, 0x5, 0x6,
0x8, 0x9, 0xA, 0xC, 0xD, 0xE,
});
void Ranges::reverse() {
for (auto &x : *this) {
x = range_reverse(x);
}
}
std::vector<CommonCode> RangesUnion::codes() const {
constexpr auto heads = std::to_array<uint64_t>({
0x0, 0x1, 0x2,
0x4, 0x5, 0x6,
0x8, 0x9, 0xA,
0xC, 0xD, 0xE,
});
Ranges& Ranges::operator+=(const Ranges &ranges) {
this->insert(this->end(), ranges.begin(), ranges.end());
return *this;
}
RangesUnion& RangesUnion::operator+=(const RangesUnion &ranges_union) {
for (const auto head : heads) {
(*this)[head] += ranges_union[head];
}
return *this;
}
std::vector<CommonCode> RangesUnion::codes() const {
size_type size = 0;
for (const auto head : heads) {
size += (*this)[head].size();

8
src/core/ranges/ranges.h

@ -14,6 +14,9 @@ namespace klotski::cases {
class Ranges final : public std::vector<uint32_t> {
public:
/// Append the ranges from another instance.
Ranges& operator+=(const Ranges &ranges);
/// Spawn klotski-ranges that match the specified block numbers.
void spawn(int n, int n_2x1, int n_1x1);
@ -29,7 +32,10 @@ public:
class RangesUnion final : public std::array<Ranges, 16> {
public:
/// Export RangesUnion as CommonCode list.
/// Append the ranges from another instance.
RangesUnion& operator+=(const RangesUnion &ranges_union);
/// Export the RangesUnion as CommonCode list.
[[nodiscard]] std::vector<codec::CommonCode> codes() const;
};

0
src/core_test/cases/ranges_union.cc

Loading…
Cancel
Save