dfs.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef IGL_DFS_H
  2. #define IGL_DFS_H
  3. #include "igl_inline.h"
  4. #include <vector>
  5. namespace igl
  6. {
  7. // Traverse a **directed** graph represented by an adjacency list using
  8. // depth first search
  9. //
  10. // Inputs:
  11. // A #V list of adjacency lists
  12. // s starting node (index into A)
  13. // Outputs:
  14. // D #V list of indices into rows of A in the order in which graph nodes
  15. // are discovered.
  16. // P #V list of indices into rows of A of predecessor in resulting
  17. // spanning tree {-1 indicates root/not discovered), order corresponds to
  18. // V **not** D.
  19. // C #V list of indices into rows of A in order that nodes are "closed"
  20. // (all descendants have been discovered)
  21. template <
  22. typename AType,
  23. typename DerivedD,
  24. typename DerivedP,
  25. typename DerivedC>
  26. IGL_INLINE void dfs(
  27. const std::vector<std::vector<AType> > & A,
  28. const size_t s,
  29. Eigen::PlainObjectBase<DerivedD> & D,
  30. Eigen::PlainObjectBase<DerivedP> & P,
  31. Eigen::PlainObjectBase<DerivedC> & C);
  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