11/*
22 FlowGraph — authoritative flow ledger layered over FlowState.
33
4- Tracks per-flow edge deltas to support exact removal and path inspection,
4+ Tracks per-flow edge allocations to support exact removal and path inspection,
55 while delegating residual and aggregate flow management to FlowState.
66*/
77#include " netgraph/core/flow_graph.hpp"
@@ -13,11 +13,6 @@ namespace netgraph::core {
1313
1414FlowGraph::FlowGraph (const StrictMultiDiGraph& g)
1515 : g_(&g), fs_(g) {
16- // Precompute EdgeId -> (src,dst) directly from edge views
17- auto sv = g_->edge_src_view ();
18- auto dv = g_->edge_dst_view ();
19- src_of_.assign (sv.begin (), sv.end ());
20- dst_of_.assign (dv.begin (), dv.end ());
2116}
2217
2318Flow FlowGraph::place (const FlowIndex& idx, NodeId src, NodeId dst,
@@ -31,7 +26,7 @@ Flow FlowGraph::place(const FlowIndex& idx, NodeId src, NodeId dst,
3126 auto & bucket = ledger_[idx];
3227
3328 // Delegate placement to FlowState, which returns the actual placed flow and
34- // populates bucket with per-edge deltas (EdgeId, Flow) pairs.
29+ // populates bucket with per-edge allocations (EdgeId, Flow) pairs.
3530 Flow placed = fs_.place_on_dag (src, dst, dag, amount, placement, &bucket);
3631
3732 // Coalesce and filter: merge duplicate EdgeIds. Keep any positive totals
@@ -63,7 +58,7 @@ void FlowGraph::remove(const FlowIndex& idx) {
6358 auto it = ledger_.find (idx);
6459 if (it == ledger_.end ()) return ; // flow not found
6560 const auto & deltas = it->second ;
66- // Revert this flow's deltas from the FlowState by subtracting them.
61+ // Revert this flow's allocations from the FlowState by subtracting them.
6762 if (!deltas.empty ()) {
6863 fs_.apply_deltas (deltas, /* add=*/ false ); // false = subtract
6964 }
@@ -93,16 +88,16 @@ std::vector<EdgeId> FlowGraph::get_flow_path(const FlowIndex& idx) const {
9388 if (it == ledger_.end ()) return {};
9489 const auto & deltas = it->second ;
9590
96- // Reconstruct a simple path from the flow's edge deltas .
91+ // Reconstruct a simple path from the flow's edge allocations .
9792 // This only succeeds if the flow forms a single path (not a DAG).
9893
9994 // Step 1: Build adjacency map from edges with positive flow.
10095 std::unordered_map<NodeId, std::vector<std::pair<NodeId, EdgeId>>> adj;
101- // Build adjacency list from deltas using cached src/dst.
96+ // Build adjacency list from allocations using cached src/dst.
10297 for (auto const & pr : deltas) {
10398 if (pr.second < kMinFlow ) continue ;
10499 auto eid = static_cast <std::size_t >(pr.first );
105- NodeId u = src_of_ [eid]; NodeId v = dst_of_ [eid];
100+ NodeId u = g_-> edge_src_view () [eid]; NodeId v = g_-> edge_dst_view () [eid];
106101 adj[u].emplace_back (v, pr.first );
107102 }
108103
0 commit comments