Skip to content

Components: use process & drivers ordering and coloring#3114

Merged
cvvergara merged 17 commits into
pgRouting:developfrom
cvvergara:components-refactor-then-use-processes
Jun 10, 2026
Merged

Components: use process & drivers ordering and coloring#3114
cvvergara merged 17 commits into
pgRouting:developfrom
cvvergara:components-refactor-then-use-processes

Conversation

@cvvergara

@cvvergara cvvergara commented Jun 10, 2026

Copy link
Copy Markdown
Member

Fixes #3113 .

  • Adding new enumerations for component functions
  • To postgres: adding more convertions to postgres array
  • Refactor makeConnected, no need of template
  • Refactor components, no need to convert to another C++ container
  • Refactor component drivers, based on the changes
  • Coloring & Ordering: refactor
    • Add directed parameter to handle directed and undirected functions
    • Prepare to process applicable component functions
  • Coloring & Ordering functions: add new parameter
    • cleanup code
    • standardize code
  • Adjusting component functions to use coloring/ordering process & driver
  • Cleanup: Removing files not needed anymore
    • Adjusting build, individual component drivers not needed anymore

Summary by CodeRabbit

  • New Features

    • Components (connected, biconnected, strong, articulation points, bridges, make-connected) integrated into the unified process/driver flow for consistent SRF outputs.
  • Refactor

    • Consolidated components and ordering/coloring flows into a common processing path, standardized result formats and output handling, added explicit directed/undirected dispatching, and simplified public APIs for more consistent behavior.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Route component algorithms through shared coloring/ordering process and driver functions, extend Which enum, change component API return types to nested int64 vectors, add to_postgres converters and identifier helpers, remove standalone component drivers, and update SRFs and CMake accordingly.

Changes

Component algorithms integrate into process/driver pairs

Layer / File(s) Summary
Enum extension and public API contract updates
include/c_common/enums.h, include/components/components.hpp, include/components/makeConnected.hpp, include/cpp_common/to_postgres.hpp, include/drivers/coloring_driver.hpp, include/drivers/ordering_driver.hpp, include/process/coloring_process.h, include/process/ordering_process.h
The Which enum is extended with CONNECTEDCOMPONENTS, BICONNECTEDCOMPONENTS, STRONGCOMPONENTS, ARTICULATIONPOINTS, BRIDGES, and MAKECONNECTED. Component function declarations change return types (where shown) from std::vector<II_t_rt> to std::vector<std::vector<int64_t>>. New get_tuples overloads and get_identifiers template added to to_postgres.hpp. Driver/process function signatures updated to accept a bool directed parameter.
Component algorithm C++ implementations with new return types
include/components/components.hpp, src/components/components.cpp, src/components/makeConnected.cpp, src/cpp_common/to_postgres.cpp
Core component algorithms (connectedComponents, strongComponents, biconnectedComponents) now construct and return nested vertex-id vectors directly. makeConnected implemented in makeConnected.cpp using a Boost visitor to record new edges. componentsResult helper removed; conversion get_tuples overloads added to emit II_t_rt arrays from nested results.
Coloring process/driver refactoring for component integration
include/drivers/coloring_driver.hpp, src/coloring/coloring_driver.cpp, src/coloring/coloring_process.cpp
pgr_process_coloring and do_coloring gain a bool directed parameter. do_coloring dispatches algorithms based on directed and Which, supports directed strongComponents, undirected components and colorings, and converts results via get_tuples. Unified handling returns "No results found" when none produced.
Coloring SRF refactoring to use process functions
src/coloring/bipartite.c, src/coloring/edgeColoring.c, src/coloring/sequentialVertexColoring.c
SRF functions call pgr_process_coloring with explicit false for directedness and standardize per-call tuple construction (use uint64_t call_cntr, num variable, simplified palloc casts).
Ordering process/driver extension for bridges and articulation points
include/drivers/ordering_driver.hpp, src/ordering/ordering_driver.cpp, src/ordering/ordering_process.cpp
pgr_process_ordering and do_ordering accept bool directed. do_ordering branches on directed: directed mode supports only TOPOSORT; undirected mode conditionally extracts vertices and dispatches SLOAN, CUTCHILL, KING, and identifier-based ARTICULATIONPOINTS/BRIDGES. Identifier outputs use get_identifiers.
SRF refactoring for component and ordering algorithms
src/components/articulationPoints.c, src/components/biconnectedComponents.c, src/components/bridges.c, src/components/connectedComponents.c, src/components/makeConnected.c, src/components/strongComponents.c, src/ordering/cuthillMckeeOrdering.c, src/ordering/kingOrdering.c, src/ordering/sloanOrdering.c, src/ordering/topologicalSort.c
Component SRFs refactored to call pgr_process_coloring/pgr_process_ordering directly instead of local drivers; ordering SRFs updated to pass directed. Tuple construction standardized (typed call_cntr, UInt64GetDatum/UInt32GetDatum for first column, loop variable renamed to num).
Build system updates and documentation
src/components/CMakeLists.txt, src/cpp_common/utilities.cpp, NEWS.md, doc/src/release_notes.rst, locale/en/LC_MESSAGES/pgrouting_doc_strings.po, locale/pot/pgrouting_doc_strings.pot
CMakeLists removes driver/result sources from the components object library; get_name(Which) extended for new component names; NEWS and release notes include issue #3113; locale files updated timestamps and added release-note msgids.

Sequence Diagram(s)

(no sequence diagrams generated)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

Reorganization, coloring

Suggested reviewers

  • robe2
  • iosefa
  • krashish8

Poem

A rabbit hops through refactored code,
Components now share the processing road.
Drivers and processes walk side by side,
Nested vectors carry results with pride.
🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main refactoring: integrating component functions into the coloring and ordering process/driver model.
Linked Issues check ✅ Passed All six component functions (#3113) are correctly mapped and refactored to use their designated process/driver pairs.
Out of Scope Changes check ✅ Passed All changes directly support the component refactoring objective; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
include/process/ordering_process.h (1)

36-39: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Missing stdbool.h include for C compilation.

The function signature at line 47 uses bool, but the C block (lines 36-39) does not include stdbool.h. This will cause a compilation error when this header is included from C code since bool is not a built-in type in C.

Compare with coloring_process.h which correctly includes stdbool.h at line 40.

🐛 Proposed fix
 `#else`
 `#include` <stddef.h>
 `#include` <stdint.h>
+#include <stdbool.h>
 `#endif`
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@include/process/ordering_process.h` around lines 36 - 39, The C compilation
branch in ordering_process.h is missing `#include` <stdbool.h>, causing the use of
the bool type in the function signature to fail; add an `#include` <stdbool.h> to
the C-side include block (alongside the existing <stddef.h> and <stdint.h>) so
the bool type used by the function signature in ordering_process.h is defined
for C builds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@include/cpp_common/to_postgres.hpp`:
- Around line 86-87: The declaration of get_tuples currently takes the nested
vector by value causing an expensive copy; change its signature to accept a
const reference: use const std::vector<std::vector<int64_t>>& for the first
parameter in the get_tuples declaration and update any corresponding
definition(s) (and all callers) to match, ensuring no mutable operations are
attempted on that parameter (or make a local copy where mutation is required).

In `@src/coloring/coloring_driver.cpp`:
- Around line 113-116: The error message in the default case of the
directed-graph branch incorrectly says "for undirected graph"; update the
message to say "for directed graph" in coloring_driver.cpp (and mirror the same
fix in ordering_driver.cpp) by editing the default branch that builds the error
string (the code that uses get_name(which) and writes to err) so the final text
reads "... for directed graph" instead of "... for undirected graph".

In `@src/components/bridges.c`:
- Line 74: The local variable call_cntr in the SRF implementation downcasts
funcctx->call_cntr (a uint64_t) to uint32_t causing possible truncation and
inconsistency with other SRFs like articulationPoints.c; change the declaration
of call_cntr to uint64_t and use funcctx->call_cntr directly, and when returning
the value (the datum produced around the current output path) switch to
Int64GetDatum if the output column expects a 64-bit integer (replace any
UInt32GetDatum/Int32GetDatum usage accordingly).

In `@src/components/components.cpp`:
- Around line 72-76: The typedef in strongComponents is using the wrong graph
type: change the vertex descriptor typedef from pgrouting::UndirectedGraph::V to
the correct directed graph type (pgrouting::DirectedGraph::V) so the function
strongComponents uses the proper vertex descriptor for the DirectedGraph
parameter; update the typedef declaration to reference
pgrouting::DirectedGraph::V (or use graph::V if that alias exists) and rebuild
to ensure type consistency.

In `@src/components/makeConnected.cpp`:
- Line 2: Update the top-of-file header comment in makeConnected.cpp so the
"File:" line correctly names makeConnected.cpp instead of makeConnected.hpp;
locate the header comment near the top of the source (in the makeConnected.cpp
file) and change the filename token to ".cpp" to match the actual source file.
- Around line 82-90: The try-catch wrapper that catches boost::exception,
std::exception, and (...) only suppresses the exception variables with (void)
and immediately rethrows, which is redundant; remove the entire try { ... }
catch(...) { ... } wrapper in makeConnected.cpp (the blocks catching
boost::exception, std::exception&, and ...) so the original code inside the try
can let exceptions propagate naturally, and ensure you also remove the matching
try and closing brace so there are no unmatched braces or scope changes.

In `@src/cpp_common/to_postgres.cpp`:
- Around line 247-267: The function get_tuples uses unqualified
sort(components.begin(), components.end()) which relies on ADL; change this to
std::sort(components.begin(), components.end()) for consistency with the earlier
std::sort usage and to avoid ambiguity; update the call in get_tuples that sorts
the outer vector (components) to use the std:: prefix while leaving the
inner-component sorts intact.

---

Outside diff comments:
In `@include/process/ordering_process.h`:
- Around line 36-39: The C compilation branch in ordering_process.h is missing
`#include` <stdbool.h>, causing the use of the bool type in the function signature
to fail; add an `#include` <stdbool.h> to the C-side include block (alongside the
existing <stddef.h> and <stdint.h>) so the bool type used by the function
signature in ordering_process.h is defined for C builds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8e611969-b9b9-47a7-acb1-0e6cfb33529a

📥 Commits

Reviewing files that changed from the base of the PR and between be1200a and 0ec2002.

📒 Files selected for processing (48)
  • NEWS.md
  • doc/src/release_notes.rst
  • include/c_common/enums.h
  • include/components/components.hpp
  • include/components/componentsResult.hpp
  • include/components/makeConnected.hpp
  • include/cpp_common/to_postgres.hpp
  • include/drivers/coloring_driver.hpp
  • include/drivers/components/articulationPoints_driver.h
  • include/drivers/components/biconnectedComponents_driver.h
  • include/drivers/components/bridges_driver.h
  • include/drivers/components/connectedComponents_driver.h
  • include/drivers/components/makeConnected_driver.h
  • include/drivers/components/strongComponents_driver.h
  • include/drivers/ordering_driver.hpp
  • include/process/coloring_process.h
  • include/process/ordering_process.h
  • locale/en/LC_MESSAGES/pgrouting_doc_strings.po
  • locale/pot/pgrouting_doc_strings.pot
  • src/coloring/bipartite.c
  • src/coloring/coloring_driver.cpp
  • src/coloring/coloring_process.cpp
  • src/coloring/edgeColoring.c
  • src/coloring/sequentialVertexColoring.c
  • src/components/CMakeLists.txt
  • src/components/articulationPoints.c
  • src/components/articulationPoints_driver.cpp
  • src/components/biconnectedComponents.c
  • src/components/biconnectedComponents_driver.cpp
  • src/components/bridges.c
  • src/components/bridges_driver.cpp
  • src/components/components.cpp
  • src/components/componentsResult.cpp
  • src/components/connectedComponents.c
  • src/components/connectedComponents_driver.cpp
  • src/components/makeConnected.c
  • src/components/makeConnected.cpp
  • src/components/makeConnected_driver.cpp
  • src/components/strongComponents.c
  • src/components/strongComponents_driver.cpp
  • src/cpp_common/to_postgres.cpp
  • src/cpp_common/utilities.cpp
  • src/ordering/cuthillMckeeOrdering.c
  • src/ordering/kingOrdering.c
  • src/ordering/ordering_driver.cpp
  • src/ordering/ordering_process.cpp
  • src/ordering/sloanOrdering.c
  • src/ordering/topologicalSort.c
💤 Files with no reviewable changes (14)
  • include/drivers/components/makeConnected_driver.h
  • include/components/componentsResult.hpp
  • src/components/biconnectedComponents_driver.cpp
  • include/drivers/components/connectedComponents_driver.h
  • include/drivers/components/articulationPoints_driver.h
  • src/components/strongComponents_driver.cpp
  • src/components/articulationPoints_driver.cpp
  • include/drivers/components/bridges_driver.h
  • include/drivers/components/strongComponents_driver.h
  • src/components/componentsResult.cpp
  • include/drivers/components/biconnectedComponents_driver.h
  • src/components/bridges_driver.cpp
  • src/components/makeConnected_driver.cpp
  • src/components/connectedComponents_driver.cpp

Comment thread include/cpp_common/to_postgres.hpp Outdated
Comment on lines +113 to +116
default:
err << __FILE_NAME__ << ": Unknown function with name '" << get_name(which)
<< "' for directed graph";
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Copy-paste error: "undirected" in directed branches across both drivers.

Both coloring_driver.cpp and ordering_driver.cpp have the same bug where the error message in the directed == true branch incorrectly states "for undirected graph". This appears to be a copy-paste error when implementing the directed/undirected branching logic.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/coloring/coloring_driver.cpp` around lines 113 - 116, The error message
in the default case of the directed-graph branch incorrectly says "for
undirected graph"; update the message to say "for directed graph" in
coloring_driver.cpp (and mirror the same fix in ordering_driver.cpp) by editing
the default branch that builds the error string (the code that uses
get_name(which) and writes to err) so the final text reads "... for directed
graph" instead of "... for undirected graph".

Comment thread src/components/bridges.c
Comment thread src/components/components.cpp
Comment thread src/components/makeConnected.cpp Outdated
Comment thread src/components/makeConnected.cpp Outdated
Comment thread src/cpp_common/to_postgres.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/ordering/ordering_driver.cpp (1)

63-64: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reset the output parameters before any early return path.

return_count is only assigned inside the non-empty result branches, but Line 178 reads it unconditionally. When an algorithm legitimately returns no rows—or this function exits earlier on an error/empty-input path—the result depends on whatever state the caller happened to pass in, which can skip the "No results found" branch or leak stale tuples downstream.

Suggested fix
 void
 do_ordering(
         const std::string &edges_sql,
         bool directed,
         Which which,

         int64_t *&return_tuples,
         size_t &return_count,

         std::ostringstream &log,
         std::ostringstream &notice,
         std::ostringstream &err) {
+    return_tuples = nullptr;
+    return_count = 0;
     std::string hint = "";

     try {

Also applies to: 170-180

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordering/ordering_driver.cpp` around lines 63 - 64, The function leaves
output params return_tuples and return_count uninitialized on early/empty-return
paths; ensure you initialize and reset them (e.g., set return_tuples to nullptr
and return_count to 0) at the start of the function and before any early return
paths (including error/empty-input branches and the sections around lines
170-180) so callers never observe stale values; update all early-return spots to
explicitly set these output parameters before returning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/ordering/ordering_driver.cpp`:
- Around line 63-64: The function leaves output params return_tuples and
return_count uninitialized on early/empty-return paths; ensure you initialize
and reset them (e.g., set return_tuples to nullptr and return_count to 0) at the
start of the function and before any early return paths (including
error/empty-input branches and the sections around lines 170-180) so callers
never observe stale values; update all early-return spots to explicitly set
these output parameters before returning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c065f1e2-2969-4b67-98f7-ab2b2d0f5b48

📥 Commits

Reviewing files that changed from the base of the PR and between 0151a4e and 448fd35.

📒 Files selected for processing (1)
  • src/ordering/ordering_driver.cpp

@cvvergara cvvergara merged commit fdaabca into pgRouting:develop Jun 10, 2026
64 checks passed
@cvvergara cvvergara deleted the components-refactor-then-use-processes branch June 10, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Components: Integrate into existing process/driver pair

2 participants