Add GraphBase::getDegree()
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
size_t GraphBase::getNVertices() const
|
||||
{
|
||||
return firstVertexIncidences.size();
|
||||
return vertexIncidenceHeaders.size();
|
||||
}
|
||||
|
||||
size_t GraphBase::getNEdges() const
|
||||
@@ -25,6 +25,11 @@ size_t GraphBase::getNEdges() const
|
||||
return nextIncidences.size() >> 1;
|
||||
}
|
||||
|
||||
size_t GraphBase::getDegree(const int vertex) const
|
||||
{
|
||||
return vertexIncidenceHeaders[vertex].second;
|
||||
}
|
||||
|
||||
bool GraphBase::areAdjacent(const int vertex1, const int vertex2) const
|
||||
{
|
||||
auto it = begin(vertex1);
|
||||
@@ -51,17 +56,19 @@ GraphBase::NeighborIterator GraphBase::end() const
|
||||
|
||||
int GraphBase::addVertexInternal()
|
||||
{
|
||||
firstVertexIncidences.push_back(-1);
|
||||
return static_cast<int>(firstVertexIncidences.size()) - 1;
|
||||
vertexIncidenceHeaders.push_back({ -1, 0 });
|
||||
return static_cast<int>(vertexIncidenceHeaders.size()) - 1;
|
||||
}
|
||||
|
||||
void GraphBase::addEdgeInternal(const int vertex1, const int vertex2)
|
||||
{
|
||||
incidenceVertices.push_back(vertex2);
|
||||
nextIncidences.push_back(firstVertexIncidences[vertex1]);
|
||||
firstVertexIncidences[vertex1] = static_cast<int>(incidenceVertices.size()) - 1;
|
||||
nextIncidences.push_back(vertexIncidenceHeaders[vertex1].first);
|
||||
vertexIncidenceHeaders[vertex1].first = static_cast<int>(incidenceVertices.size()) - 1;
|
||||
vertexIncidenceHeaders[vertex1].second++;
|
||||
|
||||
incidenceVertices.push_back(vertex1);
|
||||
nextIncidences.push_back(firstVertexIncidences[vertex2]);
|
||||
firstVertexIncidences[vertex2] = static_cast<int>(incidenceVertices.size()) - 1;
|
||||
nextIncidences.push_back(vertexIncidenceHeaders[vertex2].first);
|
||||
vertexIncidenceHeaders[vertex2].first = static_cast<int>(incidenceVertices.size()) - 1;
|
||||
vertexIncidenceHeaders[vertex2].second++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user