Skip to content

Commit d2cca2c

Browse files
Address PR review nits and UB concerns
Co-authored-by: Andrey G <networmix@gmail.com>
1 parent d37a357 commit d2cca2c

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

include/netgraph/core/cost_utils.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ namespace netgraph::core {
1717
return static_cast<Cost>(std::numeric_limits<Cost>::max() - 1);
1818
}
1919

20-
// Saturating add for path costs. If either argument is "infinity" (max), or
21-
// the sum would overflow, returns cost_finite_max().
20+
// Saturating add for path costs.
21+
// - If either argument is "infinity" (cost_max), returns cost_max.
22+
// - If finite addition would overflow, returns cost_finite_max.
2223
[[nodiscard]] inline constexpr Cost saturating_cost_add(Cost a, Cost b) noexcept {
2324
if (a == cost_max() || b == cost_max()) return cost_max();
2425
if (a >= cost_finite_max() || b >= cost_finite_max()) return cost_finite_max();

src/shortest_paths.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ shortest_paths_core(const StrictMultiDiGraph& g, NodeId src,
228228
return {std::move(dist), std::move(dag)};
229229
}
230230

231-
std::vector<int> seen(static_cast<std::size_t>(N), 0);
232-
int seen_token = 0;
231+
std::vector<std::uint32_t> seen(static_cast<std::size_t>(N), 0u);
232+
std::uint32_t seen_token = 0u;
233233
auto parent_reaches_child_via_pred_links = [&](NodeId parent, NodeId child) {
234234
if (parent == child) return true;
235235
++seen_token;

tests/cpp/flow_policy_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ TEST(FlowPolicyCore, EqualBalanced_ShortestPath_IgnoresHigherCostTier) {
351351
expect_edge_flows_by_uv(fg, {{0,1,10.0}, {1,4,10.0}, {0,2,0.0}, {2,4,0.0}});
352352
}
353353

354-
TEST(FlowPolicyCore, MaxPathCostFactor_DoesNotOverflowAndRejectValidPath) {
354+
TEST(FlowPolicyCore, MaxPathCostFactor_DoesNotOverflowOrRejectValidPath) {
355355
const auto kMax = std::numeric_limits<Cost>::max();
356356
// Single edge with very large cost; max_path_cost_factor should not overflow
357357
// and incorrectly reject this valid path.

tests/cpp/max_flow_tests.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ TEST(MaxFlow, EqualBalanced_ZeroCostCycleStillFindsFeasibleFlow) {
243243
MaxFlowOptions opts_eq;
244244
opts_eq.placement = FlowPlacement::EqualBalanced;
245245
opts_eq.shortest_path = false;
246-
auto [total_eq, __] = algs.max_flow(gh, 0, 3, opts_eq);
246+
auto [total_eq, unused_summary_eq] = algs.max_flow(gh, 0, 3, opts_eq);
247+
(void)unused_summary_eq;
247248
EXPECT_NEAR(total_eq, 1.0, 1e-9)
248249
<< "Equal-balanced should not collapse to zero flow on zero-cost cycle";
249250
}
@@ -699,7 +700,8 @@ TEST(MaxFlow, PlacementModes_EqualCapacity_IdenticalResult) {
699700
MaxFlowOptions opts_eq;
700701
opts_eq.placement = FlowPlacement::EqualBalanced;
701702
opts_eq.shortest_path = true;
702-
auto [total_eq, __] = algs.max_flow(gh, 0, 3, opts_eq);
703+
auto [total_eq, unused_summary_eq] = algs.max_flow(gh, 0, 3, opts_eq);
704+
(void)unused_summary_eq;
703705

704706
// Both should saturate both paths
705707
EXPECT_NEAR(total_prop, 20.0, 1e-9);

0 commit comments

Comments
 (0)