mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
cmComputeComponentGraph: use size_t for component indices
This avoids using casts everywhere when dealing with the sizes.
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
|
||||
const int cmComputeComponentGraph::INVALID_COMPONENT = -1;
|
||||
const size_t cmComputeComponentGraph::INVALID_COMPONENT =
|
||||
std::numeric_limits<size_t>::max();
|
||||
|
||||
cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
|
||||
: InputGraph(input)
|
||||
@@ -27,7 +30,7 @@ void cmComputeComponentGraph::Compute()
|
||||
|
||||
void cmComputeComponentGraph::Tarjan()
|
||||
{
|
||||
int n = static_cast<int>(this->InputGraph.size());
|
||||
size_t n = this->InputGraph.size();
|
||||
TarjanEntry entry = { 0, 0 };
|
||||
this->TarjanEntries.resize(0);
|
||||
this->TarjanEntries.resize(n, entry);
|
||||
@@ -36,7 +39,7 @@ void cmComputeComponentGraph::Tarjan()
|
||||
this->TarjanWalkId = 0;
|
||||
this->TarjanVisited.resize(0);
|
||||
this->TarjanVisited.resize(n, 0);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
// Start a new DFS from this node if it has never been visited.
|
||||
if (!this->TarjanVisited[i]) {
|
||||
assert(this->TarjanStack.empty());
|
||||
@@ -47,7 +50,7 @@ void cmComputeComponentGraph::Tarjan()
|
||||
}
|
||||
}
|
||||
|
||||
void cmComputeComponentGraph::TarjanVisit(int i)
|
||||
void cmComputeComponentGraph::TarjanVisit(size_t i)
|
||||
{
|
||||
// We are now visiting this node.
|
||||
this->TarjanVisited[i] = this->TarjanWalkId;
|
||||
@@ -61,7 +64,7 @@ void cmComputeComponentGraph::TarjanVisit(int i)
|
||||
// Follow outgoing edges.
|
||||
EdgeList const& nl = this->InputGraph[i];
|
||||
for (cmGraphEdge const& ni : nl) {
|
||||
int j = ni;
|
||||
size_t j = ni;
|
||||
|
||||
// Ignore edges to nodes that have been reached by a previous DFS
|
||||
// walk. Since we did not reach the current node from that walk
|
||||
@@ -90,12 +93,12 @@ void cmComputeComponentGraph::TarjanVisit(int i)
|
||||
// Check if we have found a component.
|
||||
if (this->TarjanEntries[i].Root == i) {
|
||||
// Yes. Create it.
|
||||
int c = static_cast<int>(this->Components.size());
|
||||
size_t c = this->Components.size();
|
||||
this->Components.emplace_back();
|
||||
NodeList& component = this->Components[c];
|
||||
|
||||
// Populate the component list.
|
||||
int j;
|
||||
size_t j;
|
||||
do {
|
||||
// Get the next member of the component.
|
||||
j = this->TarjanStack.top();
|
||||
@@ -118,13 +121,13 @@ void cmComputeComponentGraph::TransferEdges()
|
||||
{
|
||||
// Map inter-component edges in the original graph to edges in the
|
||||
// component graph.
|
||||
int n = static_cast<int>(this->InputGraph.size());
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int i_component = this->TarjanComponents[i];
|
||||
size_t n = this->InputGraph.size();
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
size_t i_component = this->TarjanComponents[i];
|
||||
EdgeList const& nl = this->InputGraph[i];
|
||||
for (cmGraphEdge const& ni : nl) {
|
||||
int j = ni;
|
||||
int j_component = this->TarjanComponents[j];
|
||||
size_t j = ni;
|
||||
size_t j_component = this->TarjanComponents[j];
|
||||
if (i_component != j_component) {
|
||||
// We do not attempt to combine duplicate edges, but instead
|
||||
// store the inter-component edges with suitable multiplicity.
|
||||
|
||||
Reference in New Issue
Block a user