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
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,13 @@ This separation ensures maximum code reuse, provides strict zero-cost abstractio
8
8
9
9
### 1. The Generic Templates (Engines)
10
10
11
-
Located at the lowest level, the generic templates (`bfs`, `dfs`, `r_dfs`, `pfs`) 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 search frontier (a queue, stack, or priority queue) and invoke a series of user-provided callback hooks at specific moments during the traversal.
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
+
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.
- Defining the specific logic inside the lambda callbacks and predicates.
18
24
- Managing the final return types and structures.
19
25
20
-
By separating these layers, CPP-GL guarantees that all algorithms inherently benefit from the exact same optimized design and frontier management.
26
+
By separating these layers, CPP-GL guarantees that all algorithms inherently benefit from the exact same optimized design and element management.
21
27
22
28
## Core Algorithm Elements
23
29
@@ -27,7 +33,7 @@ To interact with the generic templates or understand the concrete algorithms, yo
27
33
28
34
The generic engines accept up to 5 or 6 different callbacks per invocation. However, forcing the compiler to execute or optimize away empty lambdas (e.g., `[]{}`) can add overhead in debug builds and slow down compilation.
29
35
30
-
To solve this, CPP-GL uses the [**gl::algorithm::empty_callback**](../../cpp-gl/structgl_1_1algorithm_1_1empty__callback.md) tag. If a hook is not needed, the engine receives this tag, and template metaprogramming (`if constexpr`) physically eliminates that branch of execution at compile time.
36
+
To solve this, CPP-GL uses the [**gl::algorithm::empty_callback**](../../cpp-gl/structgl_1_1algorithm_1_1empty__callback.md) tag. If a hook is not needed, the engine receives this tag, and compile-time evaluation (`if constexpr`) completely optimizes away that branch of execution.
31
37
32
38
### Tri-State Control Flow
33
39
@@ -37,11 +43,11 @@ When evaluating adjacent edges during a search, algorithms often need more contr
37
43
-`decision::reject`: Skip this specific element, but continue the search.
38
44
-`decision::abort`: Instantly terminate the entire algorithm.
39
45
40
-
For convenience, `decision` implicitly constructs from a boolean, where `true` maps to `accept` and `false` maps to `reject`.
46
+
For convenience, `decision` implicitly constructs from a boolean, where `true` maps to `accept` and `false` maps to `reject`. Furthermore, `decision` provides a boolean conversion operator, allowing it to be seamlessly evaluated in standard conditional statements (`if (enqueue_decision) { ... }`).
41
47
42
48
### The Search Node
43
49
44
-
By default, the active frontier of a search engine stores [**gl::algorithm::search_node<G>**](../../cpp-gl/structgl_1_1algorithm_1_1search__node.md) structures. This is a lightweight pair containing:
50
+
By default, the active container of a search engine stores [**gl::algorithm::search_node<G>**](../../cpp-gl/structgl_1_1algorithm_1_1search__node.md) structures. This is a lightweight pair containing:
45
51
46
52
1.`vertex_id`: The vertex currently being visited.
47
53
2.`pred_id`: The vertex from which this current vertex was reached (its parent in the traversal tree).
@@ -56,12 +62,12 @@ CPP-GL manages this via the [**gl::algorithm::result_discriminator**](../../cpp-
56
62
-`ret`: The algorithm will allocate memory and return a stateful object (e.g., `predecessors_map<G>`).
57
63
-`noret`: The algorithm will execute purely for side-effects and return `void` (or a simple success boolean).
58
64
59
-
## Algorithm Categories
65
+
## Available Concrete Algorithms
60
66
61
67
Explore the specific layers of the algorithm module below:
62
68
63
-
-[**The Generic Templates**](templates.md): Deep dive into the callback architecture of `bfs`, `dfs`, `r_dfs`, and `pfs`.
69
+
-[**The Generic Templates**](templates.md): A detailed explanation of the core traversal engines and their execution sequence.
64
70
-[**Concrete Traversals**](traversal.md): Standard wrappers for basic component discovery and state-tracked searching.
65
71
-[**Pathfinding**](pathfinding.md): Algorithms for finding the shortest path between nodes (e.g., Dijkstra).
66
-
-[**Spanning Trees**](spanning_trees.md): Algorithms for calculating Minimum Spanning Trees (e.g., Prim's).
67
-
-[**Topology Solvers**](topology_solvers.md): Graph analysis tools like topological sorting and bipartite coloring.
72
+
-[**Spanning Trees**](spanning_trees.md): Algorithms for finding Minimum Spanning Trees (e.g., Prim's).
73
+
-[**Topology Solvers**](topology_solvers.md): Structural algorithms like topological sorting and bipartite coloring.
0 commit comments