Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

FourBlockTree.h
Go to the documentation of this file.
1 
44 #pragma once
45 
46 #include <ogdf/basic/Graph.h>
47 #include <ogdf/basic/basic.h>
48 
49 #include <memory>
50 #include <vector>
51 
52 namespace ogdf {
53 
60  FourBlockTree() = default;
61  FourBlockTree(const FourBlockTree&) = delete;
62  FourBlockTree(FourBlockTree&&) = delete;
63  FourBlockTree& operator=(const FourBlockTree&) = delete;
64  FourBlockTree& operator=(FourBlockTree&&) = delete;
65 
67  // free manually bottom-up to avoid stack overflow in case of deep tree
68  postorder([](FourBlockTree& treeNode) -> void { treeNode.children.clear(); });
69  }
70 
74  std::unique_ptr<Graph> g = std::make_unique<Graph>();
75 
83 
88 
95 
102 
106  std::vector<std::unique_ptr<FourBlockTree>> children;
107 
119  static std::unique_ptr<FourBlockTree> construct(const Graph& g, adjEntry externalFace);
120 
130  template<typename _F>
131  void preorder(_F callback) const {
132  struct stackEntry {
133  const FourBlockTree* node;
134  std::vector<std::unique_ptr<FourBlockTree>>::const_iterator nextChild;
135  };
136 
137  std::vector<stackEntry> stack;
138  stack.push_back({this, children.begin()});
139  callback(*this);
140  while (!stack.empty()) {
141  auto& it = stack.back().nextChild;
142  if (it != stack.back().node->children.end()) {
143  const FourBlockTree* child = it->get();
144  ++it;
145  stack.push_back({child, child->children.begin()});
146  callback(*child);
147  } else {
148  stack.pop_back();
149  }
150  }
151  }
152 
162  template<typename _F>
163  void preorder(_F callback) {
164  struct stackEntry {
166  std::vector<std::unique_ptr<FourBlockTree>>::iterator nextChild;
167  };
168 
169  std::vector<stackEntry> stack;
170  stack.push_back({this, children.begin()});
171  callback(*this);
172  while (!stack.empty()) {
173  auto& it = stack.back().nextChild;
174  if (it != stack.back().node->children.end()) {
175  FourBlockTree* child = it->get();
176  ++it;
177  stack.push_back({child, child->children.begin()});
178  callback(*child);
179  } else {
180  stack.pop_back();
181  }
182  }
183  }
184 
194  template<typename _F>
195  void postorder(_F callback) const {
196  struct stackEntry {
197  const FourBlockTree* node;
198  std::vector<std::unique_ptr<FourBlockTree>>::const_iterator nextChild;
199  };
200 
201  std::vector<stackEntry> stack;
202  stack.push_back({this, children.begin()});
203  while (!stack.empty()) {
204  auto& it = stack.back().nextChild;
205  if (it != stack.back().node->children.end()) {
206  const FourBlockTree* child = it->get();
207  ++it;
208  stack.push_back({child, child->children.begin()});
209  } else {
210  callback(*stack.back().node);
211  stack.pop_back();
212  }
213  }
214  }
215 
225  template<typename _F>
226  void postorder(_F callback) {
227  struct stackEntry {
229  std::vector<std::unique_ptr<FourBlockTree>>::iterator nextChild;
230  };
231 
232  std::vector<stackEntry> stack;
233  stack.push_back({this, children.begin()});
234  while (!stack.empty()) {
235  auto& it = stack.back().nextChild;
236  if (it != stack.back().node->children.end()) {
237  FourBlockTree* child = it->get();
238  ++it;
239  stack.push_back({child, child->children.begin()});
240  } else {
241  callback(*stack.back().node);
242  stack.pop_back();
243  }
244  }
245  }
246 };
247 
248 } // namespace ogdf
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::FourBlockTree::children
std::vector< std::unique_ptr< FourBlockTree > > children
The child nodes of this nodes.
Definition: FourBlockTree.h:106
ogdf::FourBlockTree::preorder
void preorder(_F callback)
Perform a pre-order traversal of the 4-block tree.
Definition: FourBlockTree.h:163
ogdf::FourBlockTree::parentFace
adjEntry parentFace
The half-edge in parent->g corresponding to externalFace.
Definition: FourBlockTree.h:101
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::FourBlockTree::originalNodes
NodeArray< node > originalNodes
The nodes in the original graph corresponding to the nodes in g.
Definition: FourBlockTree.h:82
ogdf::FourBlockTree::~FourBlockTree
~FourBlockTree()
Definition: FourBlockTree.h:66
ogdf::FourBlockTree::parent
FourBlockTree * parent
The parent node of this node in the 4-block tree.
Definition: FourBlockTree.h:94
ogdf::FourBlockTree::postorder
void postorder(_F callback)
Perform a post-order traversal of the 4-block tree.
Definition: FourBlockTree.h:226
ogdf::node
NodeElement * node
The type of nodes.
Definition: Graph_d.h:70
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::FourBlockTree::preorder
void preorder(_F callback) const
Perform a pre-order traversal of the 4-block tree.
Definition: FourBlockTree.h:131
ogdf::FourBlockTree
A node in a 4-block tree.
Definition: FourBlockTree.h:59
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::FourBlockTree::externalFace
adjEntry externalFace
A half-edge in g such that the external face of g is to its right.
Definition: FourBlockTree.h:87
ogdf::FourBlockTree::postorder
void postorder(_F callback) const
Perform a post-order traversal of the 4-block tree.
Definition: FourBlockTree.h:195