Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
52namespace ogdf {
53
60 FourBlockTree() = default;
61 FourBlockTree(const 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
Includes declaration of graph class.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
The namespace for all OGDF objects.
A node in a 4-block tree.
FourBlockTree(FourBlockTree &&)=delete
FourBlockTree * parent
The parent node of this node in the 4-block tree.
void preorder(_F callback)
Perform a pre-order traversal of the 4-block tree.
NodeArray< node > originalNodes
The nodes in the original graph corresponding to the nodes in g.
void preorder(_F callback) const
Perform a pre-order traversal of the 4-block tree.
FourBlockTree()=default
FourBlockTree(const FourBlockTree &)=delete
adjEntry externalFace
A half-edge in g such that the external face of g is to its right.
std::vector< std::unique_ptr< FourBlockTree > > children
The child nodes of this nodes.
FourBlockTree & operator=(FourBlockTree &&)=delete
static std::unique_ptr< FourBlockTree > construct(const Graph &g, adjEntry externalFace)
Construct a 4-block tree of the given graph.
FourBlockTree & operator=(const FourBlockTree &)=delete
void postorder(_F callback) const
Perform a post-order traversal of the 4-block tree.
adjEntry parentFace
The half-edge in parent->g corresponding to externalFace.
void postorder(_F callback)
Perform a post-order traversal of the 4-block tree.