Change GraphBase::NeighborIterator to use pointer to graph instead of reference
This enables default copy-assignment operator and copy constructor. Also removed GraphBase::NeighborIterator::operator!=(), since it will be generated from the equality operator.
This commit is contained in:
parent
b71d904770
commit
1834109040
@ -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 };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user