18#ifndef LLVM_ADT_BREADTHFIRSTITERATOR_H
19#define LLVM_ADT_BREADTHFIRSTITERATOR_H
39template <
typename NodeRef,
unsigned SmallSize = 8>
43template <
class GraphT,
56 using NodeRef =
typename GT::NodeRef;
57 using ChildItTy =
typename GT::ChildIteratorType;
60 using QueueElement = std::pair<NodeRef, std::optional<ChildItTy>>;
64 std::queue<std::optional<QueueElement>> VisitQueue;
74 VisitQueue.push(QueueElement(
Node, std::nullopt));
75 VisitQueue.push(std::nullopt);
80 inline void toNext() {
81 std::optional<QueueElement> Head = VisitQueue.front();
82 QueueElement
H = *Head;
83 NodeRef
Node =
H.first;
84 std::optional<ChildItTy> &ChildIt =
H.second;
87 ChildIt.emplace(GT::child_begin(
Node));
88 while (*ChildIt != GT::child_end(
Node)) {
89 NodeRef Next = *(*ChildIt)++;
92 if (this->
Visited.insert(Next).second)
93 VisitQueue.push(QueueElement(Next, std::nullopt));
98 if (!VisitQueue.empty()) {
99 Head = VisitQueue.front();
100 if (Head != std::nullopt)
107 if (!VisitQueue.empty())
108 VisitQueue.push(std::nullopt);
121 return VisitQueue ==
RHS.VisitQueue;
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This file defines the SmallPtrSet class.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
const value_type & reference
bf_iterator operator++(int)
std::ptrdiff_t difference_type
static bf_iterator begin(const GraphT &G)
NodeRef operator->() const
typename GT::NodeRef value_type
reference operator*() const
bf_iterator & operator++()
bool operator==(const bf_iterator &RHS) const
bool operator!=(const bf_iterator &RHS) const
std::forward_iterator_tag iterator_category
unsigned getLevel() const
static bf_iterator end(const GraphT &G)
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bf_iterator< T > bf_end(const T &G)
iterator_range< bf_iterator< T > > breadth_first(const T &G)
bf_iterator< T > bf_begin(const T &G)