feat: separated cell state checking into separate function in case another algo is faster than .contains
This commit is contained in:
parent
f7e474e1cf
commit
8538c91206
|
|
@ -43,6 +43,10 @@ CellIterator::CellIterator(Cell begin, Cell end)
|
|||
CellIterator::CellIterator(Cell begin, Cell end, Cell state)
|
||||
: state{ state } , begin{ begin }, end{ end } {}
|
||||
|
||||
static inline bool CellIsAlive(Cell const &cell) {
|
||||
return living.contains(cell);
|
||||
}
|
||||
|
||||
CellIterator &CellIterator::operator++() {
|
||||
++(this->state.x);
|
||||
if (this->state.x == this->end.x) {
|
||||
|
|
@ -71,7 +75,7 @@ bool CellIterator::at_end() const {
|
|||
static size_t CountNeighbors(Cell const &cell) {
|
||||
size_t count{ 0 };
|
||||
for (Cell const &c : CellRange{ {cell.x - 1, cell.y - 1}, { cell.x + 2, cell.y + 2} }) {
|
||||
if (c != cell && living.contains(c)) {
|
||||
if (c != cell && CellIsAlive(c)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +151,7 @@ static void FindBorn(std::shared_ptr<ThreadWorkload> wl) {
|
|||
CellRange range{{ center.x - 1, center.y - 1 }, {center.x + 2, center.y + 2 }};
|
||||
std::copy_if(range.begin(), range.end(), std::back_inserter(wl->changes),
|
||||
[&](Cell const &c) -> bool {
|
||||
return !living.contains(c) && CountNeighbors(c) == 3;
|
||||
return !CellIsAlive(c) && CountNeighbors(c) == 3;
|
||||
});
|
||||
});
|
||||
TaskComplete();
|
||||
|
|
|
|||
Loading…
Reference in a new issue