Skip to content

Commit dc405cc

Browse files
NetworkOperations: Use const ref to network
NetworkOperations needs a const reference to NetworkBase Co-authored-by: Moritz Sallermann <moritzsallermann@gmail.com>
1 parent 17c39e2 commit dc405cc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

graph_lib/include/network_operations.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ template <typename WeightType = double> class NetworkOperations {
1212
public:
1313
using WeightT = WeightType;
1414

15-
NetworkOperations(NetworkBase<WeightT> network)
15+
NetworkOperations(const NetworkBase<WeightT> &network)
1616
: network(network), marked(std::vector<bool>(network.n_agents(), false)),
1717
count(0), edge_to_vertex(std::vector<size_t>(network.n_agents())) {}
1818

@@ -28,14 +28,16 @@ template <typename WeightType = double> class NetworkOperations {
2828
return std::nullopt; // the path does not exist
2929
}
3030
// If the path exists, return it
31+
// Start from v
3132
for (int x = v; x != s; x = edge_to_vertex[x]) {
3233
path.push_back(x);
3334
}
35+
path.push_back(s); // Finally, add the source
3436
return path;
3537
}
3638

3739
private:
38-
NetworkBase<WeightT> network{}; // UndirectedNetwork or DirectedNetwork
40+
const NetworkBase<WeightT> &network; // UndirectedNetwork or DirectedNetwork
3941
std::vector<bool>
4042
marked{}; // Chronicles whether a vertex has been visited or not
4143
size_t count{}; // Number of vertices visited

0 commit comments

Comments
 (0)