dfs.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Inputs:
  12. // A #V list of adjacency lists
  13. // s starting node (index into A)
  14. // Outputs:
  15. // D #V list of indices into rows of A in the order in which graph nodes
  16. // are discovered.
  17. // P #V list of indices into rows of A of predecessor in resulting
  18. // spanning tree {-1 indicates root/not discovered), order corresponds to
  19. // V **not** D.
  20. // C #V list of indices into rows of A in order that nodes are "closed"
  21. // (all descendants have been discovered)
  22. template <
  23. typename AType,
  24. typename DerivedD,
  25. typename DerivedP,
  26. typename DerivedC>
  27. IGL_INLINE void dfs(
  28. const std::vector<std::vector<AType> > & A,
  29. const size_t s,
  30. Eigen::PlainObjectBase<DerivedD> & D,
  31. Eigen::PlainObjectBase<DerivedP> & P,
  32. Eigen::PlainObjectBase<DerivedC> & C);
  33. template <
  34. typename AType,
  35. typename DType,
  36. typename PType,
  37. typename CType>
  38. IGL_INLINE void dfs(
  39. const std::vector<std::vector<AType> > & A,
  40. const size_t s,
  41. std::vector<DType> & D,
  42. std::vector<PType> & P,
  43. std::vector<CType> & C);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "dfs.cpp"
  47. #endif
  48. #endif