You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/gl/algorithms/overview.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,11 @@ This separation ensures maximum code reuse, provides strict zero-cost abstractio
11
11
Located at the lowest level, the generic templates define the strict structural execution of a search. They know nothing about *shortest paths*, *spanning trees*, or *cycle detection*. Their only responsibility is to manage the pending elements (a queue, stack, or priority queue) and invoke a series of user-provided callback hooks at specific moments during the traversal.
12
12
13
13
The core generic templates include:
14
-
-[**`bfs`**](templates.md#breadth-first-search-bfs): A queue-based Breadth-First Search engine.
15
-
-[**`dfs`**](templates.md#depth-first-search-dfs): A stack-based, iterative Depth-First Search engine.
16
-
-[**`r_dfs`**](templates.md#recursive-depth-first-search-r_dfs): A recursive Depth-First Search engine utilizing the call stack.
17
-
-[**`pfs`**](templates.md#priority-first-search-pfs): A priority-queue-based Priority-First Search engine for custom heuristics.
14
+
15
+
-[**`bfs`**](templates.md#the-core-engines): A queue-based Breadth-First Search engine.
16
+
-[**`dfs`**](templates.md#the-core-engines): A stack-based, iterative Depth-First Search engine.
17
+
-[**`r_dfs`**](templates.md#the-core-engines): A recursive Depth-First Search engine utilizing the call stack.
18
+
-[**`pfs`**](templates.md#the-core-engines): A priority-queue-based Priority-First Search engine for custom heuristics.
Copy file name to clipboardExpand all lines: docs/gl/algorithms/templates.md
+54-36Lines changed: 54 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,14 @@ All engines operate on a similar fundamental principle: pop a node from a fronti
8
8
9
9
The library provides four primary traversal engines.
10
10
11
-
*[**`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.
12
-
*[**`dfs` (Depth-First Search)**](../../cpp-gl/group__GL-Algorithm.md#function-dfs): Uses a `std::stack`. Plunges as deeply as possible along a branch before backtracking.
13
-
*[**`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 `start_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.
11
+
-[**`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.
12
+
-[**`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.
13
+
-[**`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.
15
15
16
16
## The Callback Sequence
17
17
18
-
The true power of the generic templates lies in their callback hooks. Every iteration of the engine loop rigidly follows a defined sequence. By injecting custom lambdas (or omitting them via `empty_callback`), you dictate the algorithm's behavior.
18
+
The true power of the generic templates lies in their callback/predicate hooks. Every iteration of the engine loop rigidly follows a defined sequence. By injecting custom lambdas (or omitting them via the [**empty_callback**](../../cpp-gl/structgl_1_1algorithm_1_1empty__callback.md)), you dictate the algorithm's behavior.
19
19
20
20
### Execution Flowchart
21
21
@@ -31,62 +31,80 @@ For a single popped node in `bfs`, `dfs`, or `pfs`, the execution flow looks exa
31
31
The primary callback. If this returns `false`, the entire search is immediately aborted.
32
32
33
33
4.**Edge Iteration**
34
-
The engine iterates over every outgoing edge connected to the `vertex_id`. For each edge:
34
+
The engine iterates over every outgoing edge connected to the `vertex_id`. For each edge it calls:
35
35
36
-
***`enqueue_vertex_pred(target_id, edge)`**
37
-
Evaluates the target vertex. Returns a `gl::algorithm::decision`:
38
-
*`abort`: Kills the entire algorithm.
39
-
*`reject`: Ignores this edge and moves to the next.
If the target was accepted, this hook allows you to construct a custom object to push into the search frontier.
44
47
45
48
5.**`post_visit(vertex_id)`**
46
49
Executed after all adjacent edges have been evaluated and processed.
47
50
48
-
## Custom Node Injection (`pfs`)
51
+
## Custom Node Injection (PFS)
49
52
50
-
While `bfs` and `dfs`strictly operate on the lightweight `gl::algorithm::search_node`, the `pfs` (Priority-First Search) engine often requires tracking dynamic state alongside the vertex ID.
53
+
While BFS and DFS templates strictly operate on the lightweight [**gl::algorithm::search_node<G>**](../../cpp-gl/structgl_1_1algorithm_1_1search__node.md), the Priority-First Search template often requires tracking dynamic state alongside the vertex ID.
51
54
52
55
For instance, in Dijkstra's algorithm, the priority queue must sort nodes based on their accumulated distance from the starting point. You cannot sort based purely on the vertex ID.
53
56
54
-
`pfs` solves this by automatically inferring the `NodeType` from the initial queue range container. If your `NodeType` requires more than just `(target_id, pred_id)` to construct, you must provide a `MakeNodeCallback`.
57
+
`pfs` solves this by automatically inferring the `NodeType` from the initial queue range container. If your `NodeType` requires more than just `(target_id, pred_id)` to construct, you must provide `MakeNodeCallback` which is a `(vertex_id, pred_id, edge) -> NodeType` callback.
55
58
56
59
### Example: PFS Stateful Nodes
57
60
58
61
```cpp
59
-
// 1. Define a custom stateful node
60
-
structpath_node {
62
+
structpath_node { // (1)!
61
63
gl::default_id_type vertex_id;
62
64
gl::default_id_type pred_id;
63
65
int accumulated_distance;
64
66
};
65
67
66
-
// 2. Define the priority comparator
67
-
auto cmp = [](const path_node& a, const path_node& b) {
0 commit comments