dfs.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef IGL_DFS_H
  2. #define IGL_DFS_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <vector>
  6. namespace igl
  7. {
  8. /// Traverse a **directed** graph represented by an adjacency list using
  9. /// depth first search
  10. ///
  11. /// @param[in] A #V list of adjacency lists
  12. /// @param[in] s starting node (index into A)
  13. /// @param[out] D #V list of indices into rows of A in the order in which graph nodes
  14. /// are discovered.
  15. /// @param[out] P #V list of indices into rows of A of predecessor in resulting
  16. /// spanning tree {-1 indicates root/not discovered), order corresponds to
  17. /// V **not** D.
  18. /// @param[out] C #V list of indices into rows of A in order that nodes are "closed"
  19. /// (all descendants have been discovered)
  20. template <
  21. typename AType,
  22. typename DerivedD,
  23. typename DerivedP,
  24. typename DerivedC>
  25. IGL_INLINE void dfs(
  26. const std::vector<std::vector<AType> > & A,
  27. const size_t s,
  28. Eigen::PlainObjectBase<DerivedD> & D,
  29. Eigen::PlainObjectBase<DerivedP> & P,
  30. Eigen::PlainObjectBase<DerivedC> & C);
  31. /// \overload
  32. template <
  33. typename AType,
  34. typename DType,
  35. typename PType,
  36. typename CType>
  37. IGL_INLINE void dfs(
  38. const std::vector<std::vector<AType> > & A,
  39. const size_t s,
  40. std::vector<DType> & D,
  41. std::vector<PType> & P,
  42. std::vector<CType> & C);
  43. }
  44. #ifndef IGL_STATIC_LIBRARY
  45. # include "dfs.cpp"
  46. #endif
  47. #endif