Skip to content

Commit 3bf4d5e

Browse files
committed
alg overview doc refinement
1 parent b6cb5b3 commit 3bf4d5e

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

docs/gl/algorithms/overview.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ This separation ensures maximum code reuse, provides strict zero-cost abstractio
88

99
### 1. The Generic Templates (Engines)
1010

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.
1218

1319
### 2. The Concrete Algorithms
1420

@@ -17,7 +23,7 @@ Concrete algorithms (like `dijkstra_shortest_paths`, `topological_sort`, or `bre
1723
- Defining the specific logic inside the lambda callbacks and predicates.
1824
- Managing the final return types and structures.
1925

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.
2127

2228
## Core Algorithm Elements
2329

@@ -27,7 +33,7 @@ To interact with the generic templates or understand the concrete algorithms, yo
2733

2834
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.
2935

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.
3137

3238
### Tri-State Control Flow
3339

@@ -37,11 +43,11 @@ When evaluating adjacent edges during a search, algorithms often need more contr
3743
- `decision::reject`: Skip this specific element, but continue the search.
3844
- `decision::abort`: Instantly terminate the entire algorithm.
3945

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) { ... }`).
4147

4248
### The Search Node
4349

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:
4551

4652
1. `vertex_id`: The vertex currently being visited.
4753
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-
5662
- `ret`: The algorithm will allocate memory and return a stateful object (e.g., `predecessors_map<G>`).
5763
- `noret`: The algorithm will execute purely for side-effects and return `void` (or a simple success boolean).
5864

59-
## Algorithm Categories
65+
## Available Concrete Algorithms
6066

6167
Explore the specific layers of the algorithm module below:
6268

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.
6470
- [**Concrete Traversals**](traversal.md): Standard wrappers for basic component discovery and state-tracked searching.
6571
- [**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

Comments
 (0)