mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 20:55:44 +00:00
Make CoordsSet a forward range (#8776)
This commit is contained in:
@@ -105,6 +105,7 @@ public:
|
||||
|
||||
class Iter {
|
||||
public:
|
||||
using iterator_concept = std::forward_iterator_tag;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using value_type = size_t;
|
||||
@@ -112,14 +113,14 @@ public:
|
||||
using reference = size_t;
|
||||
|
||||
private:
|
||||
size_t storeIndex;
|
||||
size_t bitIndex;
|
||||
size_t storeIndex = STORE_COUNT;
|
||||
size_t bitIndex = 0;
|
||||
|
||||
const IterableBitset& bs;
|
||||
const IterableBitset* bs = nullptr;
|
||||
|
||||
void ToNext() {
|
||||
do {
|
||||
const STORE_TYPE current = bs.store[storeIndex] >> bitIndex;
|
||||
const STORE_TYPE current = bs->store[storeIndex] >> bitIndex;
|
||||
if (current != 0) {
|
||||
// Skip ahead by the number of trailing zeroes
|
||||
const auto ctz = std::countr_zero(current);
|
||||
@@ -132,10 +133,12 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
Iter() = default;
|
||||
|
||||
Iter(const IterableBitset& bs, const int startStore, const int startBit)
|
||||
: storeIndex(startStore),
|
||||
bitIndex(startBit),
|
||||
bs(bs) {
|
||||
bs(&bs) {
|
||||
ToNext();
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,7 @@ public:
|
||||
|
||||
class Iter {
|
||||
public:
|
||||
using iterator_concept = std::forward_iterator_tag;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = Coords;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
@@ -197,12 +198,14 @@ public:
|
||||
using reference = Coords;
|
||||
|
||||
private:
|
||||
BackingBitset::Iter iterator;
|
||||
BackingBitset::Iter iterator{};
|
||||
|
||||
const CoordsSet& cs;
|
||||
const CoordsSet* cs = nullptr;
|
||||
|
||||
public:
|
||||
Iter(const CoordsSet& cs, BackingBitset::Iter iter) : iterator(iter), cs(cs) {}
|
||||
Iter() = default;
|
||||
|
||||
Iter(const CoordsSet& cs, BackingBitset::Iter iter) : iterator(iter), cs(&cs) {}
|
||||
|
||||
[[nodiscard]] auto operator==(const Iter& rhs) const -> bool {
|
||||
return iterator == rhs.iterator;
|
||||
@@ -224,8 +227,8 @@ public:
|
||||
[[nodiscard]] auto operator*() const -> Coords {
|
||||
const size_t index = *iterator;
|
||||
|
||||
const int row = static_cast<int>(index / static_cast<size_t>(cs.columnCount));
|
||||
const int column = static_cast<int>(index % static_cast<size_t>(cs.columnCount));
|
||||
const int row = static_cast<int>(index / static_cast<size_t>(cs->columnCount));
|
||||
const int column = static_cast<int>(index % static_cast<size_t>(cs->columnCount));
|
||||
return Coords(row, column);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
#include <iterator>
|
||||
#include <ranges>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
@@ -24,6 +25,9 @@ static_assert(std::is_same_v<
|
||||
static_assert(
|
||||
std::is_same_v<std::iterator_traits<CoordsSet::Iter>::difference_type, std::ptrdiff_t>);
|
||||
static_assert(std::is_same_v<std::iterator_traits<CoordsSet::Iter>::value_type, Coords>);
|
||||
static_assert(std::forward_iterator<CoordsSet::Iter>);
|
||||
static_assert(std::ranges::forward_range<const CoordsSet>);
|
||||
static_assert(std::ranges::sized_range<const CoordsSet>);
|
||||
|
||||
class CoordsSetTest : public ::testing::Test {
|
||||
void SetUp() override {}
|
||||
|
||||
Reference in New Issue
Block a user