1#ifndef PBAT_GRAPH_DEPTH_FIRST_SEARCH_H
2#define PBAT_GRAPH_DEPTH_FIRST_SEARCH_H
13template <common::CIndex TIndex = Index>
14struct DepthFirstSearch
17 using StackType = std::stack<IndexType, std::vector<IndexType>>;
19 DepthFirstSearch() =
default;
24 DepthFirstSearch(Eigen::Index n);
41 template <
class FVisit,
class TDerivedP,
class TDerivedAdj>
43 Eigen::DenseBase<TDerivedP>
const& ptr,
44 Eigen::DenseBase<TDerivedAdj>
const& adj,
53 Eigen::Vector<bool, Eigen::Dynamic>
visited;
57template <common::CIndex TIndex>
58inline DepthFirstSearch<TIndex>::DepthFirstSearch(Eigen::Index n)
63template <common::CIndex TIndex>
66 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.DepthFirstSearch.Reserve");
68 std::vector<IndexType> memory{};
69 memory.reserve(
static_cast<std::size_t
>(n));
73template <common::CIndex TIndex>
74template <
class FVisit,
class TDerivedP,
class TDerivedAdj>
76 Eigen::DenseBase<TDerivedP>
const& ptr,
77 Eigen::DenseBase<TDerivedAdj>
const& adj,
81 PBAT_PROFILE_NAMED_SCOPE(
"pbat.graph.DepthFirstSearch");
84 while (not
stack.empty())
93 auto kEnd = ptr[u + 1];
94 for (
auto k = kBegin; k < kEnd; ++k)
Concepts for common types.
Definition Adjacency.h:24
Profiling utilities for the Physics-Based Animation Toolkit (PBAT)
std::stack< IndexType, std::vector< IndexType > > StackType
Stack type used for DFS.
Definition DepthFirstSearch.h:17
void Reserve(Eigen::Index n)
Reserve memory for n vertices.
Definition DepthFirstSearch.h:64
TIndex IndexType
Index type used in the depth-first search.
Definition DepthFirstSearch.h:16
Eigen::Index NumVertices() const
Get the number of vertices in the graph.
Definition DepthFirstSearch.h:51
Eigen::Vector< bool, Eigen::Dynamic > visited
|# vertices| x 1 visited mask
Definition DepthFirstSearch.h:53
void operator()(Eigen::DenseBase< TDerivedP > const &ptr, Eigen::DenseBase< TDerivedAdj > const &adj, TIndex start, FVisit fVisit)
Perform depth-first search on the graph.
Definition DepthFirstSearch.h:75
StackType stack
DFS search stack.
Definition DepthFirstSearch.h:54