Skip to content

Commit 6b64d19

Browse files
authored
Phase 4B/4C: update docstrings and concept constraints for mapped graph support (#12)
- bellman_ford_shortest_paths.hpp: update @tparam G, @tparam Distances, @tparam Predecessors, @param distances, @param predecessor, Mandates, and Preconditions sections to reflect adjacency_list (index or mapped) and vertex_property_map_for instead of random_access_range requirements - connected_components.hpp: upgrade Kosaraju bidir overload template constraint from index_bidirectional_adjacency_list to bidirectional_adjacency_list; update docstring accordingly
1 parent dc5cb69 commit 6b64d19

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

include/graph/algorithm/bellman_ford_shortest_paths.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void find_negative_cycle(G& g,
8383
* Unlike Dijkstra's algorithm, Bellman-Ford can handle negative edge weights and detects negative
8484
* weight cycles. Returns an optional vertex ID indicating whether a negative cycle was detected.
8585
*
86-
* @tparam G The graph type. Must satisfy index_adjacency_list concept.
86+
* @tparam G The graph type. Must satisfy adjacency_list concept (index or mapped).
8787
* @tparam Sources Input range of source vertex IDs.
88-
* @tparam Distances Random access range for storing distances. Value type must be arithmetic.
89-
* @tparam Predecessors Random access range for storing predecessor information. Can use _null_predecessors
88+
* @tparam Distances Vertex property map satisfying vertex_property_map_for<Distances,G>. Value type must be arithmetic.
89+
* @tparam Predecessors Vertex property map satisfying vertex_property_map_for<Predecessors,G>. Can use null_predecessors
9090
* if path reconstruction is not needed.
9191
* @tparam WF Edge weight function. Defaults to returning 1 for all edges (unweighted).
9292
* @tparam Visitor Visitor type with callbacks for algorithm events. Defaults to empty_visitor.
@@ -96,8 +96,8 @@ void find_negative_cycle(G& g,
9696
*
9797
* @param g The graph to process.
9898
* @param sources Range of source vertex IDs to start from.
99-
* @param distances [out] Shortest distances from sources. Must be sized >= num_vertices(g).
100-
* @param predecessor [out] Predecessor information for path reconstruction. Must be sized >= num_vertices(g).
99+
* @param distances [out] Shortest distances from sources. Must be a vertex property map for G.
100+
* @param predecessor [out] Predecessor information for path reconstruction. Must be a vertex property map for G.
101101
* @param weight Edge weight function: (const edge_t<G>&) -> Distance.
102102
* @param visitor Visitor for algorithm events (examine, relax, not_relaxed, minimized, not_minimized).
103103
* @param compare Distance comparison function: (Distance, Distance) -> bool.
@@ -111,16 +111,16 @@ void find_negative_cycle(G& g,
111111
* - Space: O(1) auxiliary space (excluding output parameters)
112112
*
113113
* **Mandates:**
114-
* - G must satisfy index_adjacency_list (integral vertex IDs)
114+
* - G must satisfy adjacency_list (index or mapped graphs supported)
115115
* - Sources must be input_range with values convertible to vertex_id_t<G>
116-
* - Distances must be random_access_range with arithmetic value type
117-
* - Predecessors must be random_access_range with values convertible from vertex_id_t<G>
116+
* - Distances must satisfy vertex_property_map_for<Distances,G> with arithmetic value type
117+
* - Predecessors must satisfy vertex_property_map_for<Predecessors,G> (or null_predecessors)
118118
* - WF must satisfy basic_edge_weight_function
119119
*
120120
* **Preconditions:**
121-
* - All source vertices must be valid: source < num_vertices(g) for vector-based containers
122-
* - distances.size() >= num_vertices(g)
123-
* - predecessor.size() >= num_vertices(g) (unless using _null_predecessors)
121+
* - All source vertices must be valid vertex IDs in vertices(g)
122+
* - distances must contain an entry for each vertex of g
123+
* - predecessor must contain an entry for each vertex of g (unless using null_predecessors)
124124
* - Weight function must not throw or modify graph state
125125
*
126126
* **Postconditions:**
@@ -337,17 +337,17 @@ requires vertex_property_map_for<Distances, G> &&
337337
* Computes shortest distances without tracking predecessor information. More efficient when
338338
* path reconstruction is not needed. Can detect negative weight cycles.
339339
*
340-
* @tparam G The graph type. Must satisfy index_adjacency_list concept.
340+
* @tparam G The graph type. Must satisfy adjacency_list concept (index or mapped).
341341
* @tparam Sources Input range of source vertex IDs.
342-
* @tparam Distances Random access range for storing distances. Value type must be arithmetic.
342+
* @tparam Distances Vertex property map satisfying vertex_property_map_for<Distances,G>. Value type must be arithmetic.
343343
* @tparam WF Edge weight function. Defaults to returning 1 for all edges (unweighted).
344344
* @tparam Visitor Visitor type with callbacks for algorithm events. Defaults to empty_visitor.
345345
* @tparam Compare Comparison function for distance values. Defaults to less<>.
346346
* @tparam Combine Function to combine distances and weights. Defaults to plus<>.
347347
*
348348
* @param g The graph to process.
349349
* @param sources Range of source vertex IDs to start from.
350-
* @param distances [out] Shortest distances from sources. Must be sized >= num_vertices(g).
350+
* @param distances [out] Shortest distances from sources. Must be a vertex property map for G.
351351
* @param weight Edge weight function: (const edge_t<G>&) -> Distance.
352352
* @param visitor Visitor for algorithm events.
353353
* @param compare Distance comparison function: (Distance, Distance) -> bool.

include/graph/algorithm/connected_components.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ void kosaraju(G&& g, // graph
233233
/**
234234
* @brief Finds strongly connected components using in_edges (no transpose needed).
235235
*
236-
* When the graph satisfies `index_bidirectional_adjacency_list`, the second DFS
236+
* When the graph satisfies `bidirectional_adjacency_list`, the second DFS
237237
* pass can traverse incoming edges directly instead of requiring a separate
238238
* transpose graph. This eliminates the O(V + E) cost of constructing and
239-
* storing the transpose.
239+
* storing the transpose. Works with both index and mapped bidirectional graphs.
240240
*
241241
* @par Complexity Analysis
242242
*
@@ -249,17 +249,16 @@ void kosaraju(G&& g, // graph
249249
*
250250
* @par Container Requirements
251251
*
252-
* - Requires: `index_bidirectional_adjacency_list<G>` (in_edges + index vertices)
253-
* - Requires: `random_access_range<Component>`
254-
* - Works with: All bidirectional `dynamic_graph` container combinations
252+
* - Requires: `bidirectional_adjacency_list<G>` (in_edges without needing a separate transpose)
253+
* - Compatible with both index graphs and mapped graphs.
255254
*
256-
* @tparam G Graph type (must satisfy index_bidirectional_adjacency_list concept)
257-
* @tparam Component Random access range for component IDs
255+
* @tparam G Graph type (must satisfy bidirectional_adjacency_list concept)
256+
* @tparam Component Vertex property map satisfying vertex_property_map_for<Component,G>
258257
*
259258
* @param g The directed bidirectional graph to analyze
260259
* @param component Output: component[v] = component ID for vertex v
261260
*
262-
* @pre `component.size() >= num_vertices(g)`
261+
* @pre component contains an entry for each vertex of g
263262
*
264263
* @post `component[v]` contains the SCC ID for vertex v
265264
* @post Component IDs are assigned 0, 1, 2, ..., num_components-1
@@ -277,8 +276,8 @@ void kosaraju(G&& g, // graph
277276
*
278277
* @see kosaraju(G&&, GT&&, Component&) For non-bidirectional graphs
279278
*/
280-
template <index_bidirectional_adjacency_list G,
281-
class Component>
279+
template <bidirectional_adjacency_list G,
280+
class Component>
282281
requires vertex_property_map_for<Component, G>
283282
void kosaraju(G&& g, // bidirectional graph
284283
Component& component // out: strongly connected component assignment

0 commit comments

Comments
 (0)