summaryrefslogtreecommitdiffstats
path: root/Source/cmComputeComponentGraph.cxx
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-01-26 18:25:37 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-01-31 14:27:06 (GMT)
commit91a26ce04136ccafbe37a17afc2efb01abf0992e (patch)
tree91a84614802b2e83d3d4a60010ae520b6d18e850 /Source/cmComputeComponentGraph.cxx
parent65c0a64dc5bc7cb0e13721500bdd754b6630e8ea (diff)
downloadCMake-91a26ce04136ccafbe37a17afc2efb01abf0992e.zip
CMake-91a26ce04136ccafbe37a17afc2efb01abf0992e.tar.gz
CMake-91a26ce04136ccafbe37a17afc2efb01abf0992e.tar.bz2
cmComputeComponentGraph: use `size_t` for component indices
This avoids using casts everywhere when dealing with the sizes.
Diffstat (limited to 'Source/cmComputeComponentGraph.cxx')
-rw-r--r--Source/cmComputeComponentGraph.cxx27
1 files changed, 15 insertions, 12 deletions
diff --git a/Source/cmComputeComponentGraph.cxx b/Source/cmComputeComponentGraph.cxx
index 6826f23..16540c3 100644
--- a/Source/cmComputeComponentGraph.cxx
+++ b/Source/cmComputeComponentGraph.cxx
@@ -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.