Skip to content

Commit af48dda

Browse files
committed
concrete dfs docs
1 parent e508ac8 commit af48dda

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

include/hgl/algorithm/traversal/depth_first_search.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
33
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
44

5+
/// @file hgl/algorithm/traversal/depth_first_search.hpp
6+
/// @brief Concrete Depth-First Search (DFS) traversal algorithm implementation for hypergraphs.
7+
58
#pragma once
69

710
#include "hgl/algorithm/core.hpp"
@@ -10,6 +13,48 @@
1013

1114
namespace hgl::algorithm {
1215

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
1358
template <
1459
result_discriminator Result = ret,
1560
traits::c_hypergraph H,

0 commit comments

Comments
 (0)