2023 Day 16 Part 2 optimisation
We reduce the number of items we put on the list of beams to analyse. Saving memory allocations list modifications.
This commit is contained in:
@@ -126,11 +126,7 @@ private:
|
|||||||
while (!beams.empty()) {
|
while (!beams.empty()) {
|
||||||
auto beam{beams.front()};
|
auto beam{beams.front()};
|
||||||
beams.pop_front();
|
beams.pop_front();
|
||||||
if (!loc_valid(beam.loc_)) { continue; }
|
while (loc_valid(beam.loc_) && energised_.insert(beam).second) {
|
||||||
// Insert into hash of energised locations. If that fails we've done this before and don't
|
|
||||||
// need to do it again.
|
|
||||||
if (auto [it, success] = energised_.insert(beam); !success) { continue; }
|
|
||||||
|
|
||||||
switch (grid_[beam.loc_.second][beam.loc_.first]) {
|
switch (grid_[beam.loc_.second][beam.loc_.first]) {
|
||||||
case '.':
|
case '.':
|
||||||
break;
|
break;
|
||||||
@@ -169,9 +165,8 @@ private:
|
|||||||
default:
|
default:
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
beam.loc_ = beam.loc_ + beam.dir_;
|
beam.loc_ = beam.loc_ + beam.dir_;
|
||||||
beams.push_back(beam);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user