diff --git a/include/aoc/common/GraphBase.hpp b/include/aoc/common/GraphBase.hpp index 3686bd5..93a59e6 100644 --- a/include/aoc/common/GraphBase.hpp +++ b/include/aoc/common/GraphBase.hpp @@ -46,19 +46,19 @@ class GraphBase using reference = const value_type&; using iterator_category = std::forward_iterator_tag; - NeighborIterator(const GraphBase& graph, const int vertex) + NeighborIterator(const GraphBase* graph, const int vertex) : graph_{ graph }, incidence_{ -1 }, value_{ -1, -1 } { - if (vertex >= 0 && vertex < graph_.firstVertexIncidences.size()) + if (vertex >= 0 && vertex < graph_->getNVertices()) { - setIncidence(graph_.firstVertexIncidences[vertex]); + setIncidence(graph_->firstVertexIncidences[vertex]); } }; NeighborIterator& operator++() { if (incidence_ >= 0) { - setIncidence(graph_.nextIncidences[incidence_]); + setIncidence(graph_->nextIncidences[incidence_]); } return *this; } @@ -72,10 +72,6 @@ class GraphBase { return incidence_ == other.incidence_; } - bool operator!=(NeighborIterator other) const - { - return !(*this == other); - } const reference operator*() const { return value_; @@ -86,7 +82,7 @@ class GraphBase } private: - const GraphBase& graph_; + const GraphBase* graph_; int incidence_; value_type value_; void setIncidence(const int incidence) @@ -94,7 +90,7 @@ class GraphBase incidence_ = incidence; if (incidence_ >= 0) { - value_ = { graph_.incidenceVertices[incidence_], incidence_ >> 1 }; + value_ = { graph_->incidenceVertices[incidence_], incidence_ >> 1 }; } } }; diff --git a/src/common/GraphBase.cpp b/src/common/GraphBase.cpp index 702a9a0..56b6bef 100644 --- a/src/common/GraphBase.cpp +++ b/src/common/GraphBase.cpp @@ -41,12 +41,12 @@ bool GraphBase::areAdjacent(const int vertex1, const int vertex2) const GraphBase::NeighborIterator GraphBase::begin(const int vertex) const { - return { *this, vertex }; + return { this, vertex }; } GraphBase::NeighborIterator GraphBase::end() const { - return { *this, -1 }; + return { this, -1 }; } int GraphBase::addVertexInternal()