Skip to content

Commit d1361ae

Browse files
committed
enqueue vertex -> enqueue node
1 parent 927e652 commit d1361ae

8 files changed

Lines changed: 37 additions & 39 deletions

File tree

docs/gl/algorithms/templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The library provides four primary traversal engines.
1111
- [**`bfs` (Breadth-First Search)**](../../cpp-gl/group__GL-Algorithm.md#function-bfs): Uses a `std::queue`. Explores the graph level by level, expanding uniformly outward from the initial range.
1212
- [**`dfs` (Depth-First Search)**](../../cpp-gl/group__GL-Algorithm.md#function-dfs): Uses a `std::stack`. Dives as deeply as possible along a branch before backtracking.
1313
- [**`r_dfs` (Recursive DFS)**](../../cpp-gl/group__GL-Algorithm.md#function-r_dfs): Uses the C++ call stack. Instead of an initial range, it is initiated with a specific starting vertex ID. It operates identically to `dfs` but requires external logic to manage abort signals, as returning from the recursion only unwinds one level.
14-
- [**`pfs` (Priority-First Search)**](../../cpp-gl/group__GL-Algorithm.md#function-pfs): Uses a `std::priority_queue`. Requires a custom comparator (`PQCmp`) to mathematically order the frontier. This is the underlying engine for algorithms like Dijkstra and Prim.
14+
- [**`pfs` (Priority-First Search)**](../../cpp-gl/group__GL-Algorithm.md#function-pfs): Uses a `std::priority_queue`. Requires a custom comparator (`PQCmp`) to mathematically order the frontier. This is the underlying engine for algorithms like Dijkstra's shortest paths algorithm.
1515

1616
## The Callback Sequence
1717

include/gl/algorithm/core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ template <traits::c_graph GraphType>
126126
using predecessors_map = std::vector<typename GraphType::id_type>;
127127

128128
/// @ingroup GL GL-Algorithm
129-
/// @brief Represents an active node in a search frontier (e.g., a BFS queue or DFS stack).
129+
/// @brief Represents an active node in a search container (e.g., a BFS queue or DFS stack).
130130
/// @tparam GraphType The type of the graph being searched.
131131
template <traits::c_graph GraphType>
132132
struct search_node {

include/gl/algorithm/templates/bfs.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace gl::algorithm {
3535
/// std::cout << "Visited vertex " << v << '\n';
3636
/// return true; // Continue search
3737
/// },
38-
/// gl::algorithm::default_enqueue_vertex_predicate<graph_type, true>(visited) // (5)!
38+
/// gl::algorithm::default_enqueue_node_predicate<graph_type, true>(visited) // (5)!
3939
/// );
4040
/// ```
4141
///
@@ -56,15 +56,15 @@ namespace gl::algorithm {
5656
/// | InitQueueRangeType | The type of the container providing the initial roots to enqueue. | Must be a *forward range* of @ref gl::algorithm::search_node "search nodes". |
5757
/// | VisitVertexPredicate | Type of the callable deciding if a popped vertex should be processed. | Must be one of:<br/>- An `(id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
5858
/// | VisitCallback | Type of the callable executed when a vertex is officially visited. | Must be one of:<br/>- An `(id_type, id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
59-
/// | EnqueueVertexPred | Type of the callable deciding if an adjacent vertex should be pushed to the queue. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
59+
/// | EnqueueNodePred | Type of the callable deciding if a node corresponding to an adjacent vertex should be pushed to the queue. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6060
/// | PreVisitCallback | Type of the callable executed immediately before `VisitCallback`. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6161
/// | PostVisitCallback | Type of the callable executed after all adjacent edges are evaluated. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6262
///
6363
/// @param graph The graph to traverse.
6464
/// @param initial_queue_content A range of initial @ref gl::algorithm::search_node "search nodes" to seed the BFS queue.
6565
/// @param visit_vertex_pred Predicate evaluated immediately after popping a vertex. If it returns `false`, the vertex is skipped.
6666
/// @param visit Callback invoked when a vertex is officially visited. If it returns `false`, the entire BFS immediately aborts.
67-
/// @param enqueue_vertex_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
67+
/// @param enqueue_node_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
6868
/// - `accept` to enqueue,
6969
/// - `reject` to skip,
7070
/// - `abort` to terminate the BFS entirely.
@@ -79,15 +79,15 @@ template <
7979
traits::c_optional_predicate<typename G::id_type, typename G::id_type> VisitCallback =
8080
empty_callback,
8181
traits::c_decision_predicate<typename G::id_type, const typename G::edge_type&>
82-
EnqueueVertexPred = empty_callback,
82+
EnqueueNodePred = empty_callback,
8383
traits::c_optional_callback<void, typename G::id_type> PreVisitCallback = empty_callback,
8484
traits::c_optional_callback<void, typename G::id_type> PostVisitCallback = empty_callback>
8585
bool bfs(
8686
const G& graph,
8787
const InitQueueRangeType& initial_queue_content,
8888
VisitVertexPredicate visit_vertex_pred = {},
8989
VisitCallback visit = {},
90-
EnqueueVertexPred enqueue_vertex_pred = {},
90+
EnqueueNodePred enqueue_node_pred = {},
9191
PreVisitCallback pre_visit = {},
9292
PostVisitCallback post_visit = {}
9393
) {
@@ -117,7 +117,7 @@ bool bfs(
117117

118118
for (const auto& edge : graph.out_edges(node.vertex_id)) {
119119
const auto target_vertex_id = edge.other(node.vertex_id);
120-
const auto enqueue = enqueue_vertex_pred(target_vertex_id, edge);
120+
const auto enqueue = enqueue_node_pred(target_vertex_id, edge);
121121
if (enqueue == decision::abort)
122122
return false;
123123
if (enqueue)

include/gl/algorithm/templates/dfs.hpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace gl::algorithm {
3434
/// std::cout << "Visited vertex " << v << '\n';
3535
/// return true; // Continue search
3636
/// },
37-
/// gl::algorithm::default_enqueue_vertex_predicate<graph_type, true>(visited) // (5)!
37+
/// gl::algorithm::default_enqueue_node_predicate<graph_type, true>(visited) // (5)!
3838
/// );
3939
/// ```
4040
///
@@ -55,15 +55,15 @@ namespace gl::algorithm {
5555
/// | InitStackRangeType | The type of the container providing the initial roots to push to the stack. | Must be a *forward range* of @ref gl::algorithm::search_node "search nodes". |
5656
/// | VisitVertexPredicate | Type of the callable deciding if a popped vertex should be processed. | Must be one of:<br/>- An `(id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
5757
/// | VisitCallback | Type of the callable executed when a vertex is officially visited. | Must be one of:<br/>- An `(id_type, id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
58-
/// | EnqueueVertexPred | Type of the callable deciding if an adjacent vertex should be pushed to the stack. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
58+
/// | EnqueueNodePred | Type of the callable deciding if a node corresponding to an adjacent vertex should be pushed to the stack. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
5959
/// | PreVisitCallback | Type of the callable executed immediately before `VisitCallback`. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6060
/// | PostVisitCallback | Type of the callable executed after all adjacent edges are evaluated. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6161
///
6262
/// @param graph The graph to traverse.
6363
/// @param initial_stack_content A range of initial @ref gl::algorithm::search_node "search nodes" to seed the DFS stack.
6464
/// @param visit_vertex_pred Predicate evaluated immediately after popping a vertex. If it returns `false`, the vertex is skipped.
6565
/// @param visit Callback invoked when a vertex is officially visited. If it returns `false`, the entire DFS immediately aborts.
66-
/// @param enqueue_vertex_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
66+
/// @param enqueue_node_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
6767
/// - `accept` to enqueue,
6868
/// - `reject` to skip,
6969
/// - `abort` to terminate the DFS entirely.
@@ -78,15 +78,15 @@ template <
7878
traits::c_optional_predicate<typename G::id_type, typename G::id_type> VisitCallback =
7979
empty_callback,
8080
traits::c_decision_predicate<typename G::id_type, const typename G::edge_type&>
81-
EnqueueVertexPred = empty_callback,
81+
EnqueueNodePred = empty_callback,
8282
traits::c_optional_callback<void, typename G::id_type> PreVisitCallback = empty_callback,
8383
traits::c_optional_callback<void, typename G::id_type> PostVisitCallback = empty_callback>
8484
bool dfs(
8585
const G& graph,
8686
const InitStackRangeType& initial_stack_content,
8787
VisitVertexPredicate visit_vertex_pred = {},
8888
VisitCallback visit = {},
89-
EnqueueVertexPred enqueue_vertex_pred = {},
89+
EnqueueNodePred enqueue_node_pred = {},
9090
PreVisitCallback pre_visit = {},
9191
PostVisitCallback post_visit = {}
9292
) {
@@ -116,7 +116,7 @@ bool dfs(
116116

117117
for (const auto& edge : graph.out_edges(node.vertex_id)) {
118118
const auto target_vertex_id = edge.other(node.vertex_id);
119-
const auto enqueue = enqueue_vertex_pred(target_vertex_id, edge);
119+
const auto enqueue = enqueue_node_pred(target_vertex_id, edge);
120120
if (enqueue == decision::abort)
121121
return false;
122122
if (enqueue)
@@ -150,7 +150,7 @@ bool dfs(
150150
/// std::cout << "Recursively visiting vertex " << v << '\n';
151151
/// return true;
152152
/// },
153-
/// gl::algorithm::default_enqueue_vertex_predicate<graph_type, false>(visited) // (6)!
153+
/// gl::algorithm::default_enqueue_node_predicate<graph_type, false>(visited) // (6)!
154154
/// );
155155
/// ```
156156
///
@@ -172,7 +172,7 @@ bool dfs(
172172
/// | G | The type of the graph being traversed. | Must satisfy the [**c_graph**](gl_concepts.md#gl-traits-c-graph) concept. |
173173
/// | VisitVertexPredicate | Type of the callable deciding if the current vertex should be processed. | Must be one of:<br/>- An `(id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
174174
/// | VisitCallback | Type of the callable executed when the vertex is officially visited. | Must be one of:<br/>- An `(id_type, id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
175-
/// | EnqueueVertexPred | Type of the callable deciding if an adjacent vertex should be recursed into. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
175+
/// | EnqueueNodePred | Type of the callable deciding if a node corresponding to an adjacent vertex should be recursed into. | Must be one of:<br/>- An `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
176176
/// | PreVisitCallback | Type of the callable executed immediately before `VisitCallback`. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
177177
/// | PostVisitCallback | Type of the callable executed after all adjacent edges are evaluated. | Must be one of:<br/>- An `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
178178
///
@@ -181,16 +181,15 @@ bool dfs(
181181
/// @param pred_id The ID of the predecessor vertex.
182182
/// @param visit_vertex_pred Predicate evaluated immediately upon entry. If it returns `false`, recursion returns early.
183183
/// @param visit Callback invoked when a vertex is officially visited.
184-
/// @param enqueue_vertex_pred Predicate evaluated for each outgoing edge. If `true`, the target is recursed into.
184+
/// @param enqueue_node_pred Predicate evaluated for each outgoing edge. If `true`, the target is recursed into.
185185
/// @param pre_visit Hook executed immediately before the `visit` callback.
186186
/// @param post_visit Hook executed after returning from all adjacent recursive calls.
187187
/// @hideparams
188188
template <
189189
traits::c_graph G,
190190
traits::c_optional_predicate<typename G::id_type> VisitVertexPredicate,
191191
traits::c_optional_predicate<typename G::id_type, typename G::id_type> VisitCallback,
192-
traits::c_decision_predicate<typename G::id_type, const typename G::edge_type&>
193-
EnqueueVertexPred,
192+
traits::c_decision_predicate<typename G::id_type, const typename G::edge_type&> EnqueueNodePred,
194193
traits::c_optional_callback<void, typename G::id_type> PreVisitCallback = empty_callback,
195194
traits::c_optional_callback<void, typename G::id_type> PostVisitCallback = empty_callback>
196195
void r_dfs(
@@ -199,7 +198,7 @@ void r_dfs(
199198
const typename G::id_type pred_id,
200199
VisitVertexPredicate visit_vertex_pred,
201200
VisitCallback visit,
202-
EnqueueVertexPred enqueue_vertex_pred,
201+
EnqueueNodePred enqueue_node_pred,
203202
PreVisitCallback pre_visit = {},
204203
PostVisitCallback post_visit = {}
205204
) {
@@ -215,14 +214,14 @@ void r_dfs(
215214
// recursively search vertices adjacent to the current vertex
216215
for (const auto& edge : graph.out_edges(vertex_id)) {
217216
const auto target_vertex_id = edge.other(vertex_id);
218-
if (enqueue_vertex_pred(target_vertex_id, edge))
217+
if (enqueue_node_pred(target_vertex_id, edge))
219218
r_dfs(
220219
graph,
221220
target_vertex_id,
222221
vertex_id,
223222
visit_vertex_pred,
224223
visit,
225-
enqueue_vertex_pred,
224+
enqueue_node_pred,
226225
pre_visit,
227226
post_visit
228227
);

include/gl/algorithm/templates/pfs.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace gl::algorithm {
4040
/// std::cout << "Priority visited vertex " << v << '\n';
4141
/// return true; // Continue search
4242
/// },
43-
/// gl::algorithm::default_enqueue_vertex_predicate<graph_type, true>(visited) // (6)!
43+
/// gl::algorithm::default_enqueue_node_predicate<graph_type, true>(visited) // (6)!
4444
/// );
4545
/// ```
4646
///
@@ -65,7 +65,7 @@ namespace gl::algorithm {
6565
/// | NodeType | The type of the node stored in the priority queue. | Extracted implicitly. Must be constructible from `(id_type, id_type)` unless `MakeNodeCallback` is provided. |
6666
/// | VisitVertexPredicate | Decides if a popped node should be processed. | Must be one of:<br/>- `(NodeType) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6767
/// | VisitCallback | Executed when a vertex is officially visited. | Must be one of:<br/>- `(id_type, id_type) -> bool` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
68-
/// | EnqueueVertexPred | Decides if an adjacent vertex should be pushed to the queue. | Must be one of:<br/>- `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
68+
/// | EnqueueNodePred | Decides if a node corresponding to an adjacent vertex should be pushed to the queue. | Must be one of:<br/>- `(id_type, const edge_type&) -> decision` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
6969
/// | MakeNodeCallback | Constructs a custom `NodeType` before pushing to the queue. | Must be one of:<br/>- `(id_type, id_type, const edge_type&) -> NodeType` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
7070
/// | PreVisitCallback | Executed immediately before `VisitCallback`. | Must be one of:<br/>- `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
7171
/// | PostVisitCallback | Executed after all adjacent edges are evaluated. | Must be one of:<br/>- `(id_type) -> void` callable<br/>- An @ref gl::algorithm::empty_callback "empty_callback" |
@@ -75,7 +75,7 @@ namespace gl::algorithm {
7575
/// @param initial_queue_content A range of initial nodes to seed the priority queue.
7676
/// @param visit_vertex_pred Predicate evaluated immediately after popping a node. If it returns `false`, the node is skipped (often used for late-rejection in Dijkstra).
7777
/// @param visit Callback invoked when a vertex is officially visited. If it returns `false`, the entire PFS immediately aborts.
78-
/// @param enqueue_vertex_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
78+
/// @param enqueue_node_pred Predicate evaluated for each outgoing edge. Returns a @ref gl::algorithm::decision "decision":
7979
/// - `accept` to enqueue,
8080
/// - `reject` to skip,
8181
/// - `abort` to terminate the PFS entirely.
@@ -93,7 +93,7 @@ template <
9393
traits::c_optional_predicate<typename G::id_type, typename G::id_type> VisitCallback =
9494
empty_callback,
9595
traits::c_decision_predicate<typename G::id_type, const typename G::edge_type&>
96-
EnqueueVertexPred = empty_callback,
96+
EnqueueNodePred = empty_callback,
9797
traits::c_optional_callback<
9898
NodeType,
9999
typename G::id_type,
@@ -108,7 +108,7 @@ bool pfs(
108108
const InitQueueRangeType& initial_queue_content,
109109
VisitVertexPredicate visit_vertex_pred = {},
110110
VisitCallback visit = {},
111-
EnqueueVertexPred enqueue_vertex_pred = {},
111+
EnqueueNodePred enqueue_node_pred = {},
112112
MakeNodeCallback make_node = {},
113113
PreVisitCallback pre_visit = {},
114114
PostVisitCallback post_visit = {}
@@ -141,7 +141,7 @@ bool pfs(
141141

142142
for (const auto& edge : graph.out_edges(node.vertex_id)) {
143143
const auto target_vertex_id = edge.other(node.vertex_id);
144-
const auto enqueue = enqueue_vertex_pred(target_vertex_id, edge);
144+
const auto enqueue = enqueue_node_pred(target_vertex_id, edge);
145145

146146
if (enqueue == decision::abort)
147147
return false;

include/gl/algorithm/traversal/breadth_first_search.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ result_type<Result, predecessors_map<G>> breadth_first_search(
9090
init_range<G>(root_vertex_id),
9191
default_visit_vertex_predicate(visited),
9292
default_visit_callback<G, Result>(visited, pred_map),
93-
default_enqueue_vertex_predicate<G, true>(visited),
93+
default_enqueue_node_predicate<G, true>(visited),
9494
pre_visit,
9595
post_visit
9696
);
@@ -102,7 +102,7 @@ result_type<Result, predecessors_map<G>> breadth_first_search(
102102
init_range<G>(root_id),
103103
default_visit_vertex_predicate(visited),
104104
default_visit_callback<G, Result>(visited, pred_map),
105-
default_enqueue_vertex_predicate<G, true>(visited),
105+
default_enqueue_node_predicate<G, true>(visited),
106106
pre_visit,
107107
post_visit
108108
);

0 commit comments

Comments
 (0)