|
2 | 2 | // This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl). |
3 | 3 | // Licensed under the MIT License. See the LICENSE file in the project root for full license information. |
4 | 4 |
|
| 5 | +/// @file hgl/algorithm/traversal/depth_first_search.hpp |
| 6 | +/// @brief Concrete Depth-First Search (DFS) traversal algorithm implementation for hypergraphs. |
| 7 | + |
5 | 8 | #pragma once |
6 | 9 |
|
7 | 10 | #include "hgl/algorithm/core.hpp" |
|
10 | 13 |
|
11 | 14 | namespace hgl::algorithm { |
12 | 15 |
|
| 16 | +/// @ingroup HGL-Algorithm |
| 17 | +/// @brief Executes a concrete Depth-First Search (DFS) traversal over the hypergraph. |
| 18 | +/// |
| 19 | +/// This function utilizes the generic @ref hgl::algorithm::dfs "dfs" template to perform a standard stack-based traversal. |
| 20 | +/// It automatically manages the visited states (for both vertices and hyperedges), search tree tracking, and stack initialization. |
| 21 | +/// |
| 22 | +/// If a specific `root_vertex_id` is provided, the algorithm explores only the connected component reachable from that root. |
| 23 | +/// If `no_root` is used, it iteratively ensures that every disconnected component in the entire hypergraph is fully traversed. |
| 24 | +/// |
| 25 | +/// ### Example Usage |
| 26 | +/// ```cpp |
| 27 | +/// auto search_tree |
| 28 | +/// = hgl::algorithm::depth_first_search(hypergraph, start_id); // (1)! |
| 29 | +/// |
| 30 | +/// hgl::algorithm::depth_first_search<hgl::algorithm::noret>( // (2)! |
| 31 | +/// hypergraph, |
| 32 | +/// hgl::algorithm::no_root, // (3)! |
| 33 | +/// [](const auto& node) { std::cout << "Pre-visit: " << node.vertex_id << '\n'; }, |
| 34 | +/// [](const auto& node) { std::cout << "Post-visit: " << node.vertex_id << '\n'; } |
| 35 | +/// ); |
| 36 | +/// ``` |
| 37 | +/// |
| 38 | +/// 1\. Executes a standard DFS returning a search tree mapped to the components reachable from `start_id`. |
| 39 | +/// |
| 40 | +/// 2\. Executes a DFS purely for side-effects (callbacks) without allocating memory for a search tree. |
| 41 | +/// |
| 42 | +/// 3\. Passing `no_root` forces the algorithm to iterate over all vertices, ensuring disjoint components are traversed. |
| 43 | +/// |
| 44 | +/// ### Template Parameters |
| 45 | +/// | Parameter | Description | Constraint | |
| 46 | +/// | :-------- | :--- | :--- | |
| 47 | +/// | Result | Controls whether the algorithm builds and returns a search tree (`ret`) or evaluates purely for side effects (`noret`). | Must be a valid @ref hgl::algorithm::result_discriminator "result_discriminator" enum value. | |
| 48 | +/// | H | The type of the hypergraph being searched. | Must satisfy the [**c_hypergraph**](hgl_concepts.md#hgl-traits-c-hypergraph) concept. | |
| 49 | +/// | PreVisitCallback | Type of the callable executed immediately before officially visiting a vertex. | Must be one of:<br/>- A `(const search_node<H>&) -> void` callable<br/>- An @ref hgl::algorithm::empty_callback "empty_callback" | |
| 50 | +/// | PostVisitCallback | Type of the callable executed after all adjacent elements are evaluated. | Must be one of:<br/>- A `(const search_node<H>&) -> void` callable<br/>- An @ref hgl::algorithm::empty_callback "empty_callback" | |
| 51 | +/// |
| 52 | +/// @param hypergraph The hypergraph to traverse. |
| 53 | +/// @param root_vertex_id The ID of the vertex to start the search from. If `no_root`, searches the entire hypergraph. |
| 54 | +/// @param pre_visit Hook executed immediately before officially visiting the vertex. |
| 55 | +/// @param post_visit Hook executed after all adjacent hyperedges and target vertices of the current node have been evaluated. |
| 56 | +/// @return A @ref hgl::algorithm::search_tree "search_tree" if `Result == ret`, otherwise nothing (`void`). |
| 57 | +/// @hideparams |
13 | 58 | template < |
14 | 59 | result_discriminator Result = ret, |
15 | 60 | traits::c_hypergraph H, |
|
0 commit comments