10 #ifndef SYMBOLIC_PLANNING_DEPTH_FIRST_SEARCH_H_
11 #define SYMBOLIC_PLANNING_DEPTH_FIRST_SEARCH_H_
21 template<
typename NodeT>
28 DepthFirstSearch(
const NodeT& root,
size_t max_depth) : kMaxDepth(max_depth), root_(root) {}
35 const size_t kMaxDepth;
41 template<
typename NodeT>
46 using iterator_category = std::input_iterator_tag;
47 using value_type = std::vector<NodeT>;
48 using difference_type = ptrdiff_t;
49 using pointer =
const value_type*;
50 using reference =
const value_type&;
53 iterator(
const NodeT& root,
size_t max_depth)
54 : stack_({{root, std::vector<NodeT>()}}), kMaxDepth(max_depth) {}
57 bool operator==(
const iterator& other)
const {
return stack_.empty() && other.stack_.empty(); }
58 bool operator!=(
const iterator& other)
const {
return !(*
this == other); }
59 reference operator*()
const {
return ancestors_; }
63 const size_t kMaxDepth = 0;
65 std::stack<std::pair<NodeT, std::vector<NodeT>>> stack_;
66 std::vector<NodeT> ancestors_;
70 template<
typename NodeT>
72 while (!stack_.empty()) {
73 std::pair<NodeT, std::vector<NodeT>>& top = stack_.top();
76 ancestors_.swap(top.second);
77 ancestors_.push_back(std::move(top.first));
81 const NodeT& node = ancestors_.back();
85 if (ancestors_.size() > kMaxDepth)
continue;
89 for (
const NodeT& child : node) {
90 stack_.emplace(child, ancestors_);
98 #endif // SYMBOLIC_PLANNING_DEPTH_FIRST_SEARCH_H_