diff --git a/SegmentCache.h b/SegmentCache.h index 10ae424..43d027f 100644 --- a/SegmentCache.h +++ b/SegmentCache.h @@ -28,8 +28,8 @@ public: std::set all() { std::set s; - for (std::map >::const_iterator i = cache.begin(); i != cache.end(); ++i) { - s.insert(i->second.get()); + for (auto i : cache) { + s.insert(i.second.get()); } return s; } diff --git a/StateCalculator.cpp b/StateCalculator.cpp index d04a5f7..882b932 100644 --- a/StateCalculator.cpp +++ b/StateCalculator.cpp @@ -25,7 +25,7 @@ StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) { std::set rSeg; rSeg.insert(seg); - recalc(rSeg,VSS,VCC); + recalc(rSeg, VSS, VCC); } /* @@ -36,20 +36,20 @@ void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) { */ #define SANE (100) -void StateCalculator::recalc(const std::set& rSeg, Segment* VSS, Segment* VCC) { +void StateCalculator::recalc(const std::set& segs, Segment* VSS, Segment* VCC) { int sanity(0); - std::set riSegRecalc(rSeg); - while (!riSegRecalc.empty()) { + std::set changed(segs); + while (!changed.empty()) { if (++sanity >= SANE) { throw "ERROR: reached maximum iteration limit while recalculating CPU state"; } StateCalculator c(VSS, VCC); - for (std::set::const_iterator is = riSegRecalc.begin(); is != riSegRecalc.end(); ++is) { - c.recalcNode(*is); + for (auto s : changed) { + c.recalcNode(s); } - riSegRecalc = c.getChanged(); + changed = c.getChanged(); } } @@ -64,16 +64,17 @@ void StateCalculator::recalc(const std::set& rSeg, Segment* VSS, Segme void StateCalculator::recalcNode(Segment* seg) { if (!(seg == this->VSS || seg == this->VCC)) { Circuit c(seg, this->VSS, this->VCC); + for (auto s : c) { + setSeg(s, c.getValue()); + } + } +} - for (std::set::iterator is = c.begin(); is != c.end(); ++is) { - Segment * s(*is); - if (s->on != c.getValue()) { - s->on = c.getValue(); - for (std::set::iterator it = s->gates.begin(); it != s->gates.end(); ++it) { - Trans * t(*it); - setTrans(t, c.getValue()); - } - } +void StateCalculator::setSeg(Segment* s, const bool on) { + if (s->on != on) { + s->on = on; + for (auto t : s->gates) { + setTrans(t, on); } } } diff --git a/StateCalculator.h b/StateCalculator.h index 4716b0d..f624287 100644 --- a/StateCalculator.h +++ b/StateCalculator.h @@ -32,6 +32,7 @@ private: StateCalculator& operator=(const StateCalculator&); void recalcNode(Segment* seg); + void setSeg(Segment* s, const bool on); void setTrans(Trans* t, const bool on); void addRecalc(Segment* seg);