10#include "llvm/Support/raw_ostream.h"
50 void dump(llvm::raw_ostream &outstream = llvm::outs()) {
51 outstream <<
"[" <<
toString() <<
"] ";
54 virtual void visit(llvm::raw_ostream &outstream = llvm::outs()) {
74 std::map<TreeNodePtr, std::vector<TreeNodePtr> >
adj_list_;
105 void dump(llvm::raw_ostream &outstream = llvm::outs()) {
107 auto node{entry.first};
108 auto edges{entry.second};
109 outstream << node->toString() <<
" => size: " << edges.size() <<
"\n";
110 for (
auto const &edge_node : edges) {
111 outstream <<
" " << edge_node->toString();
155 auto &edges{source->second};
162 edges.insert(edges.begin(), to);
168 node.first->resetDiscovered();
174 std::string return_string{};
176 std::queue<TreeNodePtr> que{};
180 while (!que.empty()) {
181 auto node{que.front()};
184 return_string +=
" ";
185 return_string += node->toString();
194 auto const &edges{source->second};
195 for (
auto const &edge_node : edges) {
196 if (!edge_node->isDiscovered()) {
197 edge_node->setDiscovered();
202 return return_string;
207 std::string return_string;
210 if (root ==
nullptr) {
215 if (root ==
nullptr) {
216 return return_string;
219 std::stack<TreeNodePtr> visit{};
222 while (!visit.empty()) {
223 auto &node{visit.top()};
225 return_string += node->toString();
226 return_string +=
" ";
238 if (!node->isDiscovered()) {
239 node->setDiscovered();
246 auto const &edges{source->second};
247 for (
auto &node : edges) {
255 return return_string;
bool isDiscovered() const
void dump(llvm::raw_ostream &outstream=llvm::outs())
virtual void visit(llvm::raw_ostream &outstream=llvm::outs())
TreeNode * getParent() const
TreeNode * parent_
Whether this node was discovered or not.
void setParent(TreeNode *from)
bool discovered_
Data item.
TreeNode(const TreeNode &from)
std::string toString() const
TreeNode(T data)
Parent node.
const_dft_iterator(Tree< T > *tree, std::size_t pos)
const_dft_iterator & operator++()
std::vector< TreeNodePtr > * TreeDFTPtr
const_dft_iterator begin()
bool operator!=(const const_dft_iterator &it)
const TreeNodePtr & operator*()
dft_iterator & operator++()
bool operator!=(const dft_iterator &it)
std::vector< TreeNodePtr > * TreeDFTPtr
dft_iterator(Tree< T > *tree, std::size_t pos)
TreeNodePtr & operator*()
void addEdge(const TreeNodePtr from, const TreeNodePtr to)
std::vector< TreeNodePtr > nodes_dft_
void dump(llvm::raw_ostream &outstream=llvm::outs())
const_dft_iterator end() const
const_dft_iterator begin() const
std::vector< TreeNodePtr > nodes_bft_
std::vector< TreeNodePtr > VectorTreePtr
std::string bft(TreeNodePtr root)
TreeNodePtr addNode(T data)
const TreeNodePtr getRoot() const
const VectorTreePtr & getChildren(TreeNodePtr node)
TreeNode< T > * TreeNodePtr
void setRoot(const TreeNodePtr from)
bool foundNode(TreeNodePtr node) const
std::string dft(TreeNodePtr root=nullptr)
std::map< TreeNodePtr, std::vector< TreeNodePtr > > adj_list_
bool hasChildren(TreeNodePtr node)