33 #ifndef LLVM_ADT_DEPTHFIRSTITERATOR_H
34 #define LLVM_ADT_DEPTHFIRSTITERATOR_H
50 template<
class SetType,
bool External>
56 template<
class SetType>
69 template <
typename NodeRef,
unsigned SmallSize=8>
74 template <
typename IterT>
81 template <
class GraphT,
83 df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
84 bool ExtStorage =
false,
class GT = GraphTraits<GraphT>>
86 :
public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
88 typedef std::iterator<std::forward_iterator_tag, typename GT::NodeRef> super;
90 typedef typename GT::NodeRef NodeRef;
91 typedef typename GT::ChildIteratorType ChildItTy;
96 typedef std::pair<NodeRef, Optional<ChildItTy>> StackElement;
99 std::vector<StackElement> VisitStack;
104 VisitStack.push_back(StackElement(Node,
None));
109 if (this->
Visited.insert(Node).second)
110 VisitStack.push_back(StackElement(Node,
None));
117 inline void toNext() {
119 NodeRef Node = VisitStack.back().first;
123 Opt.
emplace(GT::child_begin(Node));
128 while (*Opt != GT::child_end(Node)) {
129 NodeRef Next = *(*Opt)++;
131 if (this->
Visited.insert(Next).second) {
133 VisitStack.push_back(StackElement(Next,
None));
140 VisitStack.pop_back();
141 }
while (!VisitStack.empty());
160 return VisitStack == x.VisitStack;
164 const NodeRef &
operator*()
const {
return VisitStack.back().first; }
182 VisitStack.pop_back();
183 if (!VisitStack.empty())
199 return this->
Visited.count(Node) != 0;
208 NodeRef
getPath(
unsigned n)
const {
return VisitStack[n].first; }
230 template <class T, class SetTy = std::set<typename GraphTraits<T>::NodeRef>>
236 template <
class T,
class SetTy>
241 template <
class T,
class SetTy>
246 template <
class T,
class SetTy>
255 df_iterator_default_set<typename GraphTraits<T>::NodeRef>,
256 bool External =
false>
279 template <class T, class SetTy = std::set<typename GraphTraits<T>::NodeRef>>
287 template <
class T,
class SetTy>
292 template <
class T,
class SetTy>
297 template <
class T,
class SetTy>
305 #endif // LLVM_ADT_DEPTHFIRSTITERATOR_H
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void insert(IterT Begin, IterT End)
iterator_range< idf_ext_iterator< T, SetTy > > inverse_depth_first_ext(const T &G, SetTy &S)
df_iterator & skipChildren()
Skips all children of the current node and traverses to next node.
static df_iterator end(const GraphT &G)
idf_iterator(const df_iterator< Inverse< T >, SetTy, External > &V)
SmallPtrSet< NodeRef, SmallSize > BaseSet
idf_iterator< T > idf_begin(const T &G)
idf_iterator< T > idf_end(const T &G)
bool operator!=(const df_iterator &x) const
NodeRef getPath(unsigned n) const
getPath - Return the n'th node in the path from the entry node to the current node.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
df_iterator< T > df_end(const T &G)
idf_ext_iterator< T, SetTy > idf_ext_end(const T &G, SetTy &S)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
iterator_range< df_ext_iterator< T, SetTy > > depth_first_ext(const T &G, SetTy &S)
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
static const unsigned End
idf_ext_iterator(const idf_iterator< T, SetTy, true > &V)
static df_iterator begin(const GraphT &G)
idf_ext_iterator< T, SetTy > idf_ext_begin(const T &G, SetTy &S)
static df_iterator end(const GraphT &G, SetType &S)
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
df_ext_iterator(const df_iterator< T, SetTy, true > &V)
iterator_range< idf_iterator< T > > inverse_depth_first(const T &G)
BaseSet::iterator iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
df_iterator operator++(int)
df_iterator_storage(const df_iterator_storage &S)
std::pair< iterator, bool > insert(NodeRef N)
NodeRef operator->() const
df_iterator< T > df_begin(const T &G)
A range adaptor for a pair of iterators.
df_iterator_storage(SetType &VSet)
bool nodeVisited(NodeRef Node) const
iterator_range< df_iterator< T > > depth_first(const T &G)
df_iterator & operator++()
idf_ext_iterator(const df_iterator< Inverse< T >, SetTy, true > &V)
static df_iterator begin(const GraphT &G, SetType &S)
const NodeRef & operator*() const
bool operator==(const df_iterator &x) const
void emplace(ArgTypes &&...Args)
Create a new object by constructing it in place with the given arguments.
unsigned getPathLength() const
getPathLength - Return the length of the path from the entry node to the current node, counting both nodes.