Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Graph_d.h
Go to the documentation of this file.
1
35#pragma once
36
37#include <ogdf/basic/Array.h>
39#include <ogdf/basic/List.h>
40#include <ogdf/basic/Observer.h>
42#include <ogdf/basic/basic.h>
43#include <ogdf/basic/comparer.h>
44#include <ogdf/basic/internal/config_autogen.h>
47#include <ogdf/basic/memory.h>
48
49#include <algorithm>
50#include <array>
51#include <functional>
52#include <iterator>
53#include <ostream>
54#include <utility>
55
56#ifdef OGDF_DEBUG
57# include <set>
58#endif
59
60namespace ogdf {
61class AdjElement; // IWYU pragma: keep
62class ClusterElement; // IWYU pragma: keep
63class EdgeElement; // IWYU pragma: keep
64class EdgeSet; // needed for Graph::insert
65class FaceElement; // IWYU pragma: keep
66class Graph; // IWYU pragma: keep
67class NodeElement; // IWYU pragma: keep
68
72
76
80
81
82#if __cpp_concepts >= 201907
83// clang-format off
84template<typename T>
85concept OGDF_NODE_FILTER = requires(T f) {
86 { f(node()) } -> std::convertible_to<bool>;
87};
88template<typename T>
89concept OGDF_EDGE_FILTER = requires(T f) {
90 { f(edge()) } -> std::convertible_to<bool>;
91};
92template<typename T>
93concept OGDF_NODE_ITER = std::forward_iterator<T> && requires(T i) {
94 { *i } -> std::convertible_to<node>;
95};
96template<typename T>
97concept OGDF_EDGE_ITER = std::forward_iterator<T> && requires(T i) {
98 { *i } -> std::convertible_to<edge>;
99};
100using std::begin;
101using std::end;
102template<typename T>
103concept OGDF_NODE_LIST = requires(T l) {
104 OGDF_NODE_ITER<decltype(begin(l))>;
105 OGDF_NODE_ITER<decltype(end(l))>;
106};
107template<typename T>
108concept OGDF_EDGE_LIST = requires(T l) {
109 OGDF_EDGE_ITER<decltype(begin(l))>;
110 OGDF_EDGE_ITER<decltype(end(l))>;
111};
112// clang-format on
113
114# define OGDF_HAS_CONCEPTS
115# define OGDF_CHECK_CONCEPT static_assert
116
117OGDF_CHECK_CONCEPT(OGDF_NODE_ITER<internal::GraphIterator<node>>);
118OGDF_CHECK_CONCEPT(OGDF_EDGE_ITER<internal::GraphIterator<edge>>);
119OGDF_CHECK_CONCEPT(OGDF_NODE_ITER<internal::GraphReverseIterator<node>>);
120OGDF_CHECK_CONCEPT(OGDF_EDGE_ITER<internal::GraphReverseIterator<edge>>);
121OGDF_CHECK_CONCEPT(OGDF_NODE_LIST<internal::GraphObjectContainer<NodeElement>>);
122OGDF_CHECK_CONCEPT(OGDF_EDGE_LIST<internal::GraphObjectContainer<EdgeElement>>);
123OGDF_CHECK_CONCEPT(OGDF_NODE_ITER<ListIteratorBase<node, false, false>>);
124OGDF_CHECK_CONCEPT(OGDF_EDGE_ITER<ListIteratorBase<edge, false, true>>);
125OGDF_CHECK_CONCEPT(OGDF_NODE_ITER<ListIteratorBase<node, true, false>>);
126OGDF_CHECK_CONCEPT(OGDF_EDGE_ITER<ListIteratorBase<edge, true, false>>);
127#else
128# define OGDF_NODE_FILTER typename
129# define OGDF_EDGE_FILTER typename
130# define OGDF_NODE_ITER typename
131# define OGDF_EDGE_ITER typename
132# define OGDF_NODE_LIST typename
133# define OGDF_EDGE_LIST typename
134
135# define OGDF_CHECK_CONCEPT(...)
136#endif
137
139
144 friend class Graph;
146 friend class internal::GraphList<AdjElement>;
147
151 int m_id;
152
154 explicit AdjElement(node v) : m_twin(nullptr), m_edge(nullptr), m_node(v), m_id(0) { }
155
157 AdjElement(edge e, int id) : m_twin(nullptr), m_edge(e), m_node(nullptr), m_id(id) { }
158
159public:
161 edge theEdge() const { return m_edge; }
162
164 operator edge() const { return m_edge; }
165
167 node theNode() const { return m_node; }
168
170 operator node() const { return m_node; }
171
173 adjEntry twin() const { return m_twin; }
174
176 node twinNode() const { return m_twin->m_node; }
177
179 int index() const { return m_id; }
180
182 bool isSource() const;
183
194 bool isBetween(adjEntry adjBefore, adjEntry adjAfter) const;
195
196 // traversing faces in clockwise (resp. counter-clockwise) order
197 // (if face is an interior face)
198
200 adjEntry clockwiseFaceSucc() const { return m_twin->cyclicPred(); }
201
203 adjEntry clockwiseFacePred() const { return cyclicSucc()->m_twin; }
204
206 adjEntry counterClockwiseFaceSucc() const { return m_twin->cyclicSucc(); }
207
209 adjEntry counterClockwiseFacePred() const { return cyclicPred()->m_twin; }
210
211 // default is traversing faces in clockwise order
213 adjEntry faceCycleSucc() const { return clockwiseFaceSucc(); }
214
216 adjEntry faceCyclePred() const { return clockwiseFacePred(); }
217
219 adjEntry succ() const { return static_cast<adjEntry>(m_next); }
220
222 adjEntry pred() const { return static_cast<adjEntry>(m_prev); }
223
225 adjEntry cyclicSucc() const;
227 adjEntry cyclicPred() const;
228
229#ifdef OGDF_DEBUG
230 const Graph* graphOf() const;
231#endif
232
234 static int compare(const AdjElement& x, const AdjElement& y) { return x.m_id - y.m_id; }
236
238};
239
242 friend class Graph;
243 friend class internal::GraphList<NodeElement>;
244
245 //GraphList<AdjElement> m_adjEdges; //!< The adjacency list of the node.
248 int m_id;
249
250#ifdef OGDF_DEBUG
251 // we store the graph containing this node for debugging purposes
253#endif
254
255
257#ifdef OGDF_DEBUG
263 NodeElement(const Graph* pGraph, int id)
264 : m_indeg(0), m_outdeg(0), m_id(id), m_pGraph(pGraph) { }
265#else
266 NodeElement(int id) : m_indeg(0), m_outdeg(0), m_id(id) { }
267#endif
268
269
270public:
273
275 int index() const { return m_id; }
276
278 int indeg() const { return m_indeg; }
279
281 int outdeg() const { return m_outdeg; }
282
284 int degree() const { return m_indeg + m_outdeg; }
285
287 adjEntry firstAdj() const { return adjEntries.head(); }
288
290 adjEntry lastAdj() const { return adjEntries.tail(); }
291
293 node succ() const { return static_cast<node>(m_next); }
294
296 node pred() const { return static_cast<node>(m_prev); }
297
299
303 template<class ADJLIST>
304 void allAdjEntries(ADJLIST& adjList) const {
305 adjList.clear();
306 for (adjEntry adj : this->adjEntries) {
307 adjList.pushBack(adj);
308 }
309 }
310
312
319 template<class EDGELIST>
320 void adjEdges(EDGELIST& edgeList) const {
321 edgeList.clear();
322 for (adjEntry adj : this->adjEntries) {
323 edgeList.pushBack(adj->theEdge());
324 }
325 }
326
328
332 template<class EDGELIST>
333 void inEdges(EDGELIST& edgeList) const;
334
336
340 template<class EDGELIST>
341 void outEdges(EDGELIST& edgeList) const;
342
343#ifdef OGDF_DEBUG
345 const Graph* graphOf() const { return m_pGraph; }
346#endif
347
349 static int compare(const NodeElement& x, const NodeElement& y) { return x.m_id - y.m_id; }
351
353};
354
356 return (m_next) ? static_cast<adjEntry>(m_next) : m_node->firstAdj();
357}
358
360 return (m_prev) ? static_cast<adjEntry>(m_prev) : m_node->lastAdj();
361}
362
365 friend class Graph;
366 friend class internal::GraphList<EdgeElement>;
367
372 int m_id; // The (unique) index of the edge.
373
375
382 EdgeElement(node src, node tgt, AdjElement* adjSrc, AdjElement* adjTgt, int id)
383 : m_src(src), m_tgt(tgt), m_adjSrc(adjSrc), m_adjTgt(adjTgt), m_id(id) { }
384
386
391 EdgeElement(node src, node tgt, int id)
392 : m_src(src), m_tgt(tgt), m_adjSrc(nullptr), m_adjTgt(nullptr), m_id(id) { }
393
394public:
396 int index() const { return m_id; }
397
399 node source() const { return m_src; }
400
402 node target() const { return m_tgt; }
403
405 std::array<node, 2> nodes() const { return std::array<node, 2> {{m_src, m_tgt}}; }
406
408 adjEntry adjSource() const { return m_adjSrc; }
409
411 adjEntry adjTarget() const { return m_adjTgt; }
412
414 node opposite(node v) const {
415 OGDF_ASSERT(isIncident(v));
416 return v == m_src ? m_tgt : m_src;
417 }
418
420 bool isSelfLoop() const { return m_src == m_tgt; }
421
423 bool isInvertedDirected(edge e) const { return m_src == e->target() && m_tgt == e->source(); }
424
426 bool isParallelDirected(edge e) const { return m_src == e->source() && m_tgt == e->target(); }
427
430 return isParallelDirected(e) || isInvertedDirected(e);
431 }
432
434 edge succ() const { return static_cast<edge>(m_next); }
435
437 edge pred() const { return static_cast<edge>(m_prev); }
438
439#ifdef OGDF_DEBUG
441 const Graph* graphOf() const { return m_src->graphOf(); }
442#endif
443
445 bool isIncident(node v) const { return v == m_src || v == m_tgt; }
446
448 bool isAdjacent(edge e) const { return isIncident(e->m_src) || isIncident(e->m_tgt); }
449
452 return (m_src == e->m_src || m_src == e->m_tgt)
453 ? m_src
454 : ((m_tgt == e->m_src || m_tgt == e->m_tgt) ? m_tgt : nullptr);
455 }
456
460 OGDF_ASSERT(this->isIncident(v));
461 return v == m_src ? m_adjSrc : m_adjTgt;
462 }
463
465 static int compare(const EdgeElement& x, const EdgeElement& y) { return x.m_id - y.m_id; }
467
469
470#ifdef OGDF_DEBUG
471private:
472 bool m_hidden = false;
473#endif
474};
475
476#ifdef OGDF_DEBUG
477inline const Graph* AdjElement::graphOf() const { return m_node->graphOf(); }
478#endif
479
480inline bool AdjElement::isSource() const { return this == m_edge->adjSource(); }
481
482inline bool AdjElement::isBetween(adjEntry adjBefore, adjEntry adjAfter) const {
483#ifdef OGDF_DEBUG
484 node v = this->theNode();
485 OGDF_ASSERT(adjBefore->theNode() == v);
486 OGDF_ASSERT(adjAfter->theNode() == v);
487#endif
488 bool result = this != adjBefore && this != adjAfter && adjBefore != adjAfter;
489
490 if (result) {
491 adjEntry adj = adjBefore;
492 for (; adj != this && adj != adjAfter; adj = adj->cyclicSucc()) {
493 ;
494 }
495 result = adj == this;
496 }
497
498 return result;
499}
500
501template<class EDGELIST>
502void NodeElement::inEdges(EDGELIST& edgeList) const {
503 edgeList.clear();
504 for (adjEntry adj : this->adjEntries) {
505 edge e = adj->theEdge();
506 if (adj == e->adjTarget()) {
507 edgeList.pushBack(e);
508 }
509 }
510}
511
512template<class EDGELIST>
513void NodeElement::outEdges(EDGELIST& edgeList) const {
514 edgeList.clear();
515 for (adjEntry adj : this->adjEntries) {
516 edge e = adj->theEdge();
517 if (adj == e->adjSource()) {
518 edgeList.pushBack(e);
519 }
520 }
521}
522
527
528public:
531
533 GraphAdjIterator(Graph* graph = nullptr, adjEntry entry = nullptr);
534
537
539 GraphAdjIterator end() { return GraphAdjIterator(m_pGraph); }
540
542 void next();
543
545 void prev();
546
548 adjEntry operator*() const { return m_entry; }
549
551 AdjElement& operator->() const { return *m_entry; }
552
554 bool operator==(const GraphAdjIterator& iter) const {
555 return m_pGraph == iter.m_pGraph && m_entry == iter.m_entry;
556 }
557
559 bool operator!=(const GraphAdjIterator& iter) const { return !operator==(iter); }
560
563 next();
564 return *this;
565 }
566
569 GraphAdjIterator iter = *this;
570 next();
571 return iter;
572 }
573
576 prev();
577 return *this;
578 }
579
582 GraphAdjIterator iter = *this;
583 prev();
584 return iter;
585 }
586};
587
588namespace internal {
590
597template<typename Key, typename Iterable = GraphObjectContainer<Key>, int Factor = 1>
599 : public RegistryBase<Key*, GraphRegistry<Key, Iterable, Factor>, typename Iterable::iterator> {
602
603public:
604 using iterator = typename Iterable::iterator;
605
607 GraphRegistry(Graph* graph, int* nextKeyIndex)
608 : m_pGraph(graph), m_nextKeyIndex(nextKeyIndex) { }
609
610 static inline int keyToIndex(Key* key) { return key->index(); }
611
612 bool isKeyAssociated(Key* key) const {
613 if (key == nullptr) {
614 return false;
615 }
616#ifdef OGDF_DEBUG
617 if (key->graphOf() == m_pGraph) {
618 OGDF_ASSERT(keyToIndex(key) < this->getArraySize());
619 return true;
620 } else {
621 return false;
622 }
623#else
624 return true;
625#endif
626 }
627
628 int calculateArraySize(int add) const {
629 return calculateTableSize((*m_nextKeyIndex + add) * Factor);
630 }
631
632 int maxKeyIndex() const { return ((*m_nextKeyIndex) * Factor) - 1; }
633
635 Graph* graphOf() const { return m_pGraph; }
636};
637
641
642#ifndef DOXYGEN_IGNORE
643// doxygen has problems keeping these methods apart
645
647
649
651
653
655#endif
656
658template<typename Key, typename Value, bool WithDefault, typename Registry = GraphRegistry<Key>>
659class GraphRegisteredArray : public RegisteredArray<Registry, Value, WithDefault, Graph> {
661
662public:
663 using RA::RA;
664
666 Graph* graphOf() const {
667 if (RA::registeredAt() == nullptr) {
668 return nullptr;
669 } else {
670 return RA::registeredAt()->graphOf();
671 }
672 }
673};
674
676template<typename Value, bool WithDefault>
677class EdgeArrayBase1 : public GraphRegisteredArray<EdgeElement, Value, WithDefault> {
679
680public:
681 using GRA::GRA;
682
683 using GRA::operator[];
684 using GRA::operator();
685
687 const Value& operator[](adjEntry adj) const {
688 OGDF_ASSERT(adj != nullptr);
689 OGDF_ASSERT(GRA::getRegistry().isKeyAssociated(adj->theEdge()));
690 return GRA::operator[](adj->index() >> 1);
691 }
692
694 Value& operator[](adjEntry adj) {
695 OGDF_ASSERT(adj != nullptr);
696 OGDF_ASSERT(GRA::getRegistry().isKeyAssociated(adj->theEdge()));
697 return GRA::operator[](adj->index() >> 1);
698 }
699
701 const Value& operator()(adjEntry adj) const {
702 OGDF_ASSERT(adj != nullptr);
703 OGDF_ASSERT(GRA::getRegistry().isKeyAssociated(adj->theEdge()));
704 return GRA::operator[](adj->index() >> 1);
705 }
706
708 Value& operator()(adjEntry adj) {
709 OGDF_ASSERT(adj != nullptr);
710 OGDF_ASSERT(GRA::getRegistry().isKeyAssociated(adj->theEdge()));
711 return GRA::operator[](adj->index() >> 1);
712 }
713};
714
716template<typename Value, bool WithDefault>
717class EdgeArrayBase2 : public EdgeArrayBase1<Value, WithDefault> {
718public:
719 using EdgeArrayBase1<Value, WithDefault>::EdgeArrayBase1;
720};
721
722template<bool WithDefault>
723class EdgeArrayBase2<edge, WithDefault> : public EdgeArrayBase1<edge, WithDefault> {
725
726public:
727 using EA::EA;
728
731 OGDF_ASSERT(adj != nullptr);
732 OGDF_ASSERT(EA::getRegistry().isKeyAssociated(adj->theEdge()));
733 edge e = EA::operator[](adj->index() >> 1);
734 return adj->isSource() ? e->adjSource() : e->adjTarget();
735 }
736};
737}
738
739#define OGDF_DECL_REG_ARRAY_TYPE(v, c) internal::GraphRegisteredArray<NodeElement, v, c>
742#undef OGDF_DECL_REG_ARRAY_TYPE
743
744#define OGDF_DECL_REG_ARRAY_TYPE(v, c) internal::EdgeArrayBase2<v, c>
747#undef OGDF_DECL_REG_ARRAY_TYPE
748
749#define OGDF_DECL_REG_ARRAY_TYPE(v, c) \
750 internal::GraphRegisteredArray<AdjElement, v, c, internal::GraphAdjRegistry>
753#undef OGDF_DECL_REG_ARRAY_TYPE
754
756
775class OGDF_EXPORT GraphObserver : public Observer<Graph, GraphObserver> {
776public:
778 GraphObserver() = default;
779
780 OGDF_DEPRECATED("calls registrationChanged with only partially-constructed child classes, "
781 "see copy constructor of Observer for fix")
782
783 explicit GraphObserver(const Graph* G) { reregister(G); }
784
786 virtual void nodeDeleted(node v) = 0;
787
789 virtual void nodeAdded(node v) = 0;
790
792 virtual void edgeDeleted(edge e) = 0;
793
795 virtual void edgeAdded(edge e) = 0;
796
798 virtual void cleared() = 0;
799
800 const Graph* getGraph() const { return getObserved(); }
801};
802
803namespace internal {
804template<typename CONTAINER>
805inline void getAllNodes(const Graph& G, CONTAINER& nodes);
806template<typename CONTAINER>
807inline void getAllEdges(const Graph& G, CONTAINER& edges);
808
809inline node adjToNode(adjEntry adj) { return adj->theNode(); }
810
811inline node adjToNode(node n) { return n; }
812}
813
815OGDF_EXPORT bool filter_any_edge(edge e); // { return true; }
816
818OGDF_EXPORT bool filter_any_node(node n); // { return true; }
819
821
866class OGDF_EXPORT Graph : public Observable<GraphObserver, Graph> {
867public:
868 class CCsInfo; // IWYU pragma: keep
869 class HiddenEdgeSet; // IWYU pragma: keep
870
871 friend class GraphObserver;
872
873private:
876
880
882
883public:
890
897
899
904
906 enum class EdgeType { association = 0, generalization = 1, dependency = 2 };
907
909 enum class NodeType {
910 vertex = 0,
911 dummy = 1,
912 generalizationMerger = 2,
913 generalizationExpander = 3,
914 highDegreeExpander = 4,
915 lowDegreeExpander = 5,
916 associationClass = 6
917 };
918
920
921
927
930
933
935
936
939
941
950
952
962
964
966 virtual ~Graph();
967
969
974
976 bool empty() const { return nodes.empty(); }
977
979 int numberOfNodes() const { return nodes.size(); }
980
982 int numberOfEdges() const { return edges.size(); }
983
985 int maxNodeIndex() const { return m_nodeIdCount - 1; }
986
988 int maxEdgeIndex() const { return m_edgeIdCount - 1; }
989
991 int maxAdjEntryIndex() const { return (m_edgeIdCount << 1) - 1; }
992
994 node firstNode() const { return nodes.head(); }
995
997 node lastNode() const { return nodes.tail(); }
998
1000 edge firstEdge() const { return edges.head(); }
1001
1003 edge lastEdge() const { return edges.tail(); }
1004
1013 std::function<bool(node)> includeNode = [](node) { return true; },
1014 bool isFastTest = true) const;
1015
1024 std::function<bool(edge)> includeEdge = [](edge) { return true; },
1025 bool isFastTest = true) const;
1026
1028
1032 template<class CONTAINER>
1033 void allNodes(CONTAINER& nodeContainer) const {
1034 internal::getAllNodes<CONTAINER>(*this, nodeContainer);
1035 }
1036
1038
1042 template<class CONTAINER>
1043 void allEdges(CONTAINER& edgeContainer) const {
1044 internal::getAllEdges<CONTAINER>(*this, edgeContainer);
1045 }
1046
1048
1052
1054
1061 node newNode(int index = -1) {
1062 node v = pureNewNode(index);
1063 m_regNodeArrays.keyAdded(v);
1064 for (GraphObserver* obs : getObservers()) {
1065 obs->nodeAdded(v);
1066 }
1067 return v;
1068 }
1069
1071
1080 inline edge newEdge(node v, node w, int index = -1) {
1081 return newEdge(v, Direction::after, w, Direction::after, index);
1082 }
1083
1085
1099 inline edge newEdge(node v, adjEntry adjTgt, int index = -1) {
1100 return newEdge(v, Direction::after, adjTgt, Direction::after, index);
1101 }
1102
1104
1118 inline edge newEdge(adjEntry adjSrc, node w, int index = -1) {
1119 return newEdge(adjSrc, Direction::after, w, Direction::after, index);
1120 }
1121
1123
1140 inline edge newEdge(adjEntry adjSrc, adjEntry adjTgt, Direction dir = Direction::after,
1141 int index = -1) {
1142 return newEdge(adjSrc, dir, adjTgt, dir, index);
1143 }
1144
1146
1164 template<typename S, typename T>
1165 edge newEdge(S src, Direction dirSrc, T tgt, Direction dirTgt, int index = -1) {
1166 OGDF_ASSERT(src != nullptr);
1167 OGDF_ASSERT(tgt != nullptr);
1168 edge e = pureNewEdge(internal::adjToNode(src), internal::adjToNode(tgt), index);
1169
1170 insertAdjEntry(tgt, e->m_adjTgt, dirTgt);
1171 insertAdjEntry(src, e->m_adjSrc, dirSrc);
1172
1173 m_regEdgeArrays.keyAdded(e);
1174 m_regAdjArrays.keyAdded(e->adjSource());
1175 m_regAdjArrays.keyAdded(e->adjTarget());
1176 for (GraphObserver* obs : getObservers()) {
1177 obs->edgeAdded(e);
1178 }
1179
1180 return e;
1181 }
1182
1184
1188
1190 virtual void delNode(node v);
1191
1193 virtual void delEdge(edge e);
1194
1196 virtual void clear();
1197
1200
1202
1223 friend class Graph;
1224 friend class EdgeElement;
1225
1226 public:
1232 explicit HiddenEdgeSet(Graph& graph) : m_graph(&graph) {
1233 m_it = m_graph->m_hiddenEdgeSets.pushFront(this);
1234 }
1235
1240 if (m_graph) {
1241 restore();
1242 m_graph->m_hiddenEdgeSets.del(m_it);
1243 }
1244 }
1245
1252 void hide(edge e);
1253
1260 void restore(edge e);
1261
1268 void restore();
1269
1271 int size();
1272
1274 bool empty();
1275
1278
1281
1282 private:
1286
1288 };
1289
1294
1296
1305 virtual edge split(edge e);
1306
1308
1317 void unsplit(node u);
1318
1320
1331 virtual void unsplit(edge eIn, edge eOut);
1332
1334
1355 node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight);
1356
1358
1366 node contract(edge e, bool keepSelfLoops = false);
1367
1369
1383 void move(edge e, adjEntry adjSrc, Direction dirSrc, adjEntry adjTgt, Direction dirTgt);
1384
1386
1393
1395
1403 void moveTarget(edge e, adjEntry adjTgt, Direction dir);
1404
1406
1413
1415
1423 void moveSource(edge e, adjEntry adjSrc, Direction dir);
1424
1426
1434 edge searchEdge(node v, node w, bool directed = false) const;
1435
1438
1441
1443
1449 template<class NODELIST>
1450 void collapse(NODELIST& nodesToCollapse) {
1451 node v = nodesToCollapse.popFrontRet();
1452 while (!nodesToCollapse.empty()) {
1453 node w = nodesToCollapse.popFrontRet();
1454 adjEntry adj = w->firstAdj();
1455 while (adj != nullptr) {
1456 adjEntry succ = adj->succ();
1457 edge e = adj->theEdge();
1458 if (e->source() == v || e->target() == v) {
1459 delEdge(e);
1460 } else if (e->source() == w) {
1461 moveSource(e, v);
1462 } else {
1463 moveTarget(e, v);
1464 }
1465 adj = succ;
1466 }
1467 delNode(w);
1468 }
1469 }
1470
1472
1479 template<class ADJ_ENTRY_LIST>
1480 void sort(node v, const ADJ_ENTRY_LIST& newOrder) {
1481 using std::begin;
1482 using std::end;
1483 sort(v, begin(newOrder), end(newOrder));
1484 }
1485
1487
1495 template<class IT>
1496 void sort(node v, IT begin, IT end) {
1497#ifdef OGDF_DEBUG
1498 std::set<int> entries;
1499 int counter = 0;
1500
1501 for (auto it = begin; it != end; ++it) {
1502 adjEntry adj = *it;
1503 entries.insert(adj->index());
1504 OGDF_ASSERT(adj->theNode() == v);
1505 counter++;
1506 }
1507
1508 OGDF_ASSERT(counter == v->degree());
1509 OGDF_ASSERT(entries.size() == static_cast<unsigned int>(v->degree()));
1510#endif
1511 v->adjEntries.sort(begin, end);
1512 }
1513
1515
1518 void reverseAdjEdges(node v) { v->adjEntries.reverse(); }
1519
1521
1528 void moveAdj(adjEntry adjMove, Direction dir, adjEntry adjPos) {
1529 OGDF_ASSERT(adjMove != nullptr);
1530 OGDF_ASSERT(adjPos != nullptr);
1531 OGDF_ASSERT(adjMove->graphOf() == this);
1532 OGDF_ASSERT(adjPos->graphOf() == this);
1534 adjList.move(adjMove, adjList, adjPos, dir);
1535 }
1536
1538
1544 void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter) {
1545 OGDF_ASSERT(adjMove != nullptr);
1546 OGDF_ASSERT(adjAfter != nullptr);
1547 OGDF_ASSERT(adjMove->graphOf() == this);
1548 OGDF_ASSERT(adjAfter->graphOf() == this);
1549 adjMove->m_node->adjEntries.moveAfter(adjMove, adjAfter);
1550 }
1551
1553
1559 void moveAdjBefore(adjEntry adjMove, adjEntry adjBefore) {
1560 OGDF_ASSERT(adjMove != nullptr);
1561 OGDF_ASSERT(adjBefore != nullptr);
1562 OGDF_ASSERT(adjMove->graphOf() == this);
1563 OGDF_ASSERT(adjBefore->graphOf() == this);
1564 adjMove->m_node->adjEntries.moveBefore(adjMove, adjBefore);
1565 }
1566
1569
1571
1577 void swapAdjEdges(adjEntry adj1, adjEntry adj2) {
1578 OGDF_ASSERT(adj1->theNode() == adj2->theNode());
1579 OGDF_ASSERT(adj1->graphOf() == this);
1580
1581 adj1->theNode()->adjEntries.swap(adj1, adj2);
1582 }
1583
1585
1589
1591
1601 int genus() const;
1602
1604
1607 bool representsCombEmbedding() const { return genus() == 0; }
1608
1609#ifdef OGDF_DEBUG
1611 void consistencyCheck() const;
1612#endif
1613
1615
1621
1623 internal::GraphNodeRegistry& nodeRegistry() { return m_regNodeArrays; }
1624
1626 const internal::GraphNodeRegistry& nodeRegistry() const { return m_regNodeArrays; }
1627
1628 operator const internal::GraphNodeRegistry&() const { return m_regNodeArrays; }
1629
1631 internal::GraphEdgeRegistry& edgeRegistry() { return m_regEdgeArrays; }
1632
1634 const internal::GraphEdgeRegistry& edgeRegistry() const { return m_regEdgeArrays; }
1635
1636 operator const internal::GraphEdgeRegistry&() const { return m_regEdgeArrays; }
1637
1639 internal::GraphAdjRegistry& adjEntryRegistry() { return m_regAdjArrays; }
1640
1642 const internal::GraphAdjRegistry& adjEntryRegistry() const { return m_regAdjArrays; }
1643
1644 operator const internal::GraphAdjRegistry&() const { return m_regAdjArrays; }
1645
1647
1672 void resetEdgeIdCount(int maxId);
1673
1674 void resetNodeIdCount(int maxId);
1675
1676
1678
1682
1716 template<OGDF_NODE_ITER NI, OGDF_EDGE_ITER EI, bool copyEmbedding = true, bool copyIDs = false,
1717 bool notifyObservers = true>
1718 std::pair<int, int> insert(const NI& nodesBegin, const NI& nodesEnd, const EI& edgesBegin,
1719 const EI& edgesEnd, NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap);
1720
1748 template<OGDF_NODE_ITER NI, OGDF_EDGE_FILTER EF, bool copyIDs = false, bool notifyObservers = true>
1749 std::pair<int, int> insert(const NI& nodesBegin, const NI& nodesEnd, const EF& edgeFilter,
1750 NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap);
1751
1752 // List short-cuts
1753
1760 template<OGDF_NODE_LIST NL>
1761 std::pair<int, int> insert(const NL& nodeList, const EdgeSet& edgeSet, NodeArray<node>& nodeMap,
1762 EdgeArray<edge>& edgeMap);
1763
1770 template<OGDF_NODE_LIST NL, OGDF_EDGE_LIST EL>
1771 std::pair<int, int> insert(const NL& nodeList, const EL& edgeList, NodeArray<node>& nodeMap,
1772 EdgeArray<edge>& edgeMap) {
1773 m_regNodeArrays.reserveSpace(nodeList.size());
1774 m_regEdgeArrays.reserveSpace(edgeList.size());
1775 m_regAdjArrays.reserveSpace(edgeList.size());
1776 using std::begin;
1777 using std::end;
1778 return insert(begin(nodeList), end(nodeList), begin(edgeList), end(edgeList), nodeMap,
1779 edgeMap);
1780 }
1781
1782 // Often-used special cases
1783
1790 std::pair<int, int> insert(const CCsInfo& info, int cc, NodeArray<node>& nodeMap,
1791 EdgeArray<edge>& edgeMap) {
1792 OGDF_ASSERT(&(info.constGraph()) == nodeMap.registeredAt()->graphOf());
1793 OGDF_ASSERT(&(info.constGraph()) == edgeMap.registeredAt()->graphOf());
1794 m_regNodeArrays.reserveSpace(info.numberOfNodes(cc));
1795 m_regEdgeArrays.reserveSpace(info.numberOfEdges(cc));
1796 m_regAdjArrays.reserveSpace(info.numberOfEdges(cc));
1797 auto count = insert(info.nodes(cc).begin(), info.nodes(cc).end(), filter_any_edge, nodeMap,
1798 edgeMap);
1799 OGDF_ASSERT(count.first == info.numberOfNodes(cc));
1800 OGDF_ASSERT(count.second == info.numberOfEdges(cc));
1801 return count;
1802 }
1803
1810 std::pair<int, int> insert(const Graph& G, NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap) {
1811 if (!nodeMap.registeredAt()) {
1812 nodeMap.init(G);
1813 }
1814 OGDF_ASSERT(nodeMap.registeredAt()->graphOf() == &G);
1815 if (!edgeMap.registeredAt()) {
1816 edgeMap.init(G);
1817 }
1818 OGDF_ASSERT(edgeMap.registeredAt()->graphOf() == &G);
1819 m_regNodeArrays.reserveSpace(G.numberOfNodes());
1820 m_regEdgeArrays.reserveSpace(G.numberOfEdges());
1821 m_regAdjArrays.reserveSpace(G.numberOfEdges());
1822 auto count = insert(G.nodes.begin(), G.nodes.end(), filter_any_edge, nodeMap, edgeMap);
1823 OGDF_ASSERT(count.first == G.numberOfNodes());
1824 OGDF_ASSERT(count.second == G.numberOfEdges());
1825 return count;
1826 }
1827
1834 std::pair<int, int> insert(const Graph& G) {
1835 NodeArray<node> nodeMap(G, nullptr);
1836 EdgeArray<edge> edgeMap(G, nullptr);
1837 return insert(G, nodeMap, edgeMap);
1838 }
1839
1840private:
1841 template<OGDF_NODE_ITER NI, bool notifyObservers, bool copyIDs>
1842 void insertNodes(const NI& nodesBegin, const NI& nodesEnd, NodeArray<node, true>& nodeMap,
1843 int& newNodes, void* cbData);
1844
1845protected:
1861 virtual void* preInsert(bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter,
1862 NodeArray<node>& nodeMap, EdgeArray<edge>& edgeMap, int* newNodes, int* newEdges) {
1863 return nullptr;
1864 };
1865
1873 virtual void nodeInserted(void* userData, node original, node copy) {};
1874
1882 virtual void edgeInserted(void* userData, edge original, edge copy) {};
1883
1891 virtual void postInsert(void* userData, int newNodes, int newEdges) {};
1893
1894public:
1899
1904
1905 public:
1907 CCsInfo() : m_graph(nullptr), m_numCC(0) { }
1908
1910 explicit CCsInfo(const Graph& G);
1911
1913 const Graph& constGraph() const { return *m_graph; }
1914
1916 int numberOfCCs() const { return m_numCC; }
1917
1919 int numberOfNodes(int cc) const { return stopNode(cc) - startNode(cc); }
1920
1922 int numberOfEdges(int cc) const { return stopEdge(cc) - startEdge(cc); }
1923
1925 int startNode(int cc) const { return m_startNode[cc]; }
1926
1928 int stopNode(int cc) const { return m_startNode[cc + 1]; }
1929
1931 return {m_nodes.begin() + startNode(cc), m_nodes.begin() + stopNode(cc)};
1932 }
1933
1935 return {m_edges.begin() + startEdge(cc), m_edges.begin() + stopEdge(cc)};
1936 }
1937
1939 int startEdge(int cc) const { return m_startEdge[cc]; }
1940
1942 int stopEdge(int cc) const { return m_startEdge[cc + 1]; }
1943
1945 node v(int i) const { return m_nodes[i]; }
1946
1948 edge e(int i) const { return m_edges[i]; }
1949 };
1950
1951private:
1959 inline node pureNewNode(int index) {
1960 if (index < 0) {
1961 index = m_nodeIdCount++;
1962 } else {
1963 m_nodeIdCount = max(m_nodeIdCount, index + 1);
1964 }
1965
1966 // simple check against illegal index reuse
1967 OGDF_ASSERT(nodes.empty() || index != nodes.head()->index());
1968 OGDF_ASSERT(nodes.empty() || index != nodes.tail()->index());
1969
1970#ifdef OGDF_DEBUG
1971 node v = new NodeElement(this, index);
1972#else
1973 node v = new NodeElement(index);
1974#endif
1975 nodes.pushBack(v);
1976 return v;
1977 }
1978
1990 edge pureNewEdge(node src, node tgt, int index) {
1991 OGDF_ASSERT(src != nullptr);
1992 OGDF_ASSERT(tgt != nullptr);
1993 OGDF_ASSERT(src->graphOf() == this);
1994 OGDF_ASSERT(tgt->graphOf() == this);
1995
1996 if (index < 0) {
1997 index = m_edgeIdCount++;
1998 } else {
1999 m_edgeIdCount = max(m_edgeIdCount, index + 1);
2000 }
2001
2002 // simple check against illegal index reuse
2003 OGDF_ASSERT(edges.empty() || index != edges.head()->index());
2004 OGDF_ASSERT(edges.empty() || index != edges.tail()->index());
2005
2006 edge e = new EdgeElement(src, tgt, index);
2007 edges.pushBack(e);
2008
2009 e->m_adjSrc = new AdjElement(e, index << 1);
2010 e->m_adjTgt = new AdjElement(e, (index << 1) | 1);
2011
2012 e->m_adjSrc->m_twin = e->m_adjTgt;
2013 e->m_adjSrc->m_node = src;
2014 src->m_outdeg++;
2015
2016 e->m_adjTgt->m_twin = e->m_adjSrc;
2017 e->m_adjTgt->m_node = tgt;
2018 tgt->m_indeg++;
2019
2020 return e;
2021 }
2022
2023 static inline void insertAdjEntry(adjEntry oldAdj, adjEntry newAdj, Direction dir) {
2024 if (dir == Direction::after) {
2025 oldAdj->theNode()->adjEntries.insertAfter(newAdj, oldAdj);
2026 } else {
2027 oldAdj->theNode()->adjEntries.insertBefore(newAdj, oldAdj);
2028 }
2029 }
2030
2031 static inline void insertAdjEntry(node n, adjEntry newAdj, Direction dir) {
2032 if (dir == Direction::after || n->adjEntries.empty()) {
2033 n->adjEntries.pushBack(newAdj);
2034 } else {
2035 n->adjEntries.insertBefore(newAdj, n->adjEntries.head());
2036 }
2037 }
2038
2040 void moveAdj(adjEntry adj, node w);
2041};
2042
2043OGDF_EXPORT std::ostream& operator<<(std::ostream& os, const Graph::EdgeType& et);
2044
2047public:
2049 int getBucket(const edge& e) override { return e->source()->index(); }
2050};
2051
2054public:
2056 int getBucket(const edge& e) override { return e->target()->index(); }
2057};
2058
2059namespace internal {
2060
2061template<typename CONTAINER>
2062inline void getAllNodes(const Graph& G, CONTAINER& nodes) {
2063 nodes.clear();
2064 for (node v : G.nodes) {
2065 nodes.pushBack(v);
2066 }
2067}
2068
2069template<>
2070inline void getAllNodes(const Graph& G, Array<node>& nodes) {
2071 nodes.init(G.numberOfNodes());
2072 int i = 0;
2073 for (node v : G.nodes) {
2074 nodes[i++] = v;
2075 }
2076}
2077
2078template<typename CONTAINER>
2079inline void getAllEdges(const Graph& G, CONTAINER& edges) {
2080 edges.clear();
2081 for (edge v : G.edges) {
2082 edges.pushBack(v);
2083 }
2084}
2085
2086template<>
2087inline void getAllEdges(const Graph& G, Array<edge>& edges) {
2088 edges.init(G.numberOfEdges());
2089 int i = 0;
2090 for (edge v : G.edges) {
2091 edges[i++] = v;
2092 }
2093}
2094
2095}
2096
2097struct NodePair {
2098 node source = nullptr;
2099 node target = nullptr;
2100 NodePair() = default;
2101
2102 NodePair(node src, node tgt) : source(src), target(tgt) { }
2103};
2104
2105inline std::ostream& operator<<(std::ostream& os, const NodePair& np) {
2106 os << "(" << np.source << "," << np.target << ")";
2107 return os;
2108}
2109
2110}
2111
Declaration and implementation of Array class and Array algorithms.
#define OGDF_NODE_FILTER
Definition Graph_d.h:128
#define OGDF_NODE_LIST
Definition Graph_d.h:132
#define OGDF_NODE_ITER
Definition Graph_d.h:130
#define OGDF_CHECK_CONCEPT(...)
Definition Graph_d.h:135
#define OGDF_EDGE_FILTER
Definition Graph_d.h:129
#define OGDF_EDGE_LIST
Definition Graph_d.h:133
#define OGDF_EDGE_ITER
Definition Graph_d.h:131
Decralation of GraphElement and GraphList classes.
Implementation of the ogdf::Graph::insert(...) template methods.
Declaration of doubly linked lists and iterators.
Simple, safe base classes for C++ observables and observers.
Declaration and implementation of RegisteredArray class.
#define OGDF_DECL_REG_ARRAY(NAME)
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry faceCyclePred() const
Returns the cyclic predecessor in face.
Definition Graph_d.h:216
adjEntry pred() const
Returns the predecessor in the adjacency list.
Definition Graph_d.h:222
int index() const
Returns the index of this adjacency element.
Definition Graph_d.h:179
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:173
bool isBetween(adjEntry adjBefore, adjEntry adjAfter) const
Returns whether this adjacency entry lies between adjBefore and adjAfter in clockwise rotation.
Definition Graph_d.h:482
adjEntry clockwiseFaceSucc() const
Returns the clockwise successor in face. Use faceCycleSucc instead!
Definition Graph_d.h:200
AdjElement * m_twin
The corresponding adjacency entry (same edge)
Definition Graph_d.h:148
int m_id
The (unique) index of the adjacency entry.
Definition Graph_d.h:151
adjEntry counterClockwiseFaceSucc() const
Returns the counter-clockwise successor in face.
Definition Graph_d.h:206
static int compare(const AdjElement &x, const AdjElement &y)
Standard Comparer.
Definition Graph_d.h:234
edge m_edge
The associated edge.
Definition Graph_d.h:149
adjEntry counterClockwiseFacePred() const
Returns the counter-clockwise predecessor in face.
Definition Graph_d.h:209
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition Graph_d.h:355
AdjElement(node v)
Constructs an adjacency element for a given node.
Definition Graph_d.h:154
adjEntry succ() const
Returns the successor in the adjacency list.
Definition Graph_d.h:219
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:161
adjEntry clockwiseFacePred() const
Returns the clockwise predecessor in face. Use faceCycleSucc instead!
Definition Graph_d.h:203
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Definition Graph_d.h:480
node m_node
The node whose adjacency list contains this entry.
Definition Graph_d.h:150
const Graph * graphOf() const
Definition Graph_d.h:477
adjEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
Definition Graph_d.h:359
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition Graph_d.h:176
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:167
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition Graph_d.h:213
AdjElement(edge e, int id)
Constructs an adjacency entry for a given edge and index.
Definition Graph_d.h:157
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
iterator begin()
Returns an iterator to the first element.
Definition Array.h:329
void init()
Reinitializes the array to an array with empty index set.
Definition Array.h:372
Abstract base class for bucket functions.
Definition basic.h:257
Bucket function using the index of an edge's source node as bucket.
Definition Graph_d.h:2046
int getBucket(const edge &e) override
Returns source index of e.
Definition Graph_d.h:2049
Bucket function using the index of an edge's target node as bucket.
Definition Graph_d.h:2053
int getBucket(const edge &e) override
Returns target index of e.
Definition Graph_d.h:2056
Class for the representation of edges.
Definition Graph_d.h:364
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:408
bool isParallelDirected(edge e) const
Returns true iff edge e is parallel to this (directed) edge (or if it is the same edge)
Definition Graph_d.h:426
int index() const
Returns the index of the edge.
Definition Graph_d.h:396
EdgeElement(node src, node tgt, int id)
Constructs an edge element (src,tgt).
Definition Graph_d.h:391
node opposite(node v) const
Returns the adjacent node different from v.
Definition Graph_d.h:414
EdgeElement(node src, node tgt, AdjElement *adjSrc, AdjElement *adjTgt, int id)
Constructs an edge element (src,tgt).
Definition Graph_d.h:382
edge succ() const
Returns the successor in the list of all edges.
Definition Graph_d.h:434
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition Graph_d.h:441
AdjElement * m_adjSrc
Corresponding adjacency entry at source node.
Definition Graph_d.h:370
std::array< node, 2 > nodes() const
Returns a list of adjacent nodes. If this edge is a self-loop, both entries will be the same node.
Definition Graph_d.h:405
bool isAdjacent(edge e) const
Returns true iff e is adjacent to the edge.
Definition Graph_d.h:448
AdjElement * m_adjTgt
Corresponding adjacency entry at target node.
Definition Graph_d.h:371
bool isIncident(node v) const
Returns true iff v is incident to the edge.
Definition Graph_d.h:445
node m_tgt
The target node of the edge.
Definition Graph_d.h:369
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition Graph_d.h:411
node m_src
The source node of the edge.
Definition Graph_d.h:368
static int compare(const EdgeElement &x, const EdgeElement &y)
Standard Comparer.
Definition Graph_d.h:465
edge pred() const
Returns the predecessor in the list of all edges.
Definition Graph_d.h:437
node commonNode(edge e) const
Returns the common node of the edge and e. Returns nullptr if the two edges are not adjacent.
Definition Graph_d.h:451
bool isInvertedDirected(edge e) const
Returns true iff edge e is an inverted edge to this (directed) edge.
Definition Graph_d.h:423
bool isParallelUndirected(edge e) const
Returns true iff edge e is parallel to this (undirected) edge (or if it is the same edge)
Definition Graph_d.h:429
bool isSelfLoop() const
Returns true iff the edge is a self-loop (source node = target node).
Definition Graph_d.h:420
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
adjEntry getAdj(node v) const
Returns an adjacency entry of this edge at node v. If this is a self-loop the source adjacency entry ...
Definition Graph_d.h:459
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Edge sets.
Definition GraphSets.h:86
Info structure for maintaining connected components.
Definition Graph_d.h:1896
int numberOfNodes(int cc) const
Returns the number of nodes in connected component cc.
Definition Graph_d.h:1919
int numberOfEdges(int cc) const
Returns the number of edges in connected component cc.
Definition Graph_d.h:1922
Array< node > m_nodes
array of all nodes.
Definition Graph_d.h:1900
edge e(int i) const
Returns the edge with index i.
Definition Graph_d.h:1948
CCsInfo()
Creates a info structure associated with no graph.
Definition Graph_d.h:1907
int m_numCC
the number of connected components.
Definition Graph_d.h:1898
internal::SimpleRange< Array< edge >::const_iterator > edges(int cc) const
Definition Graph_d.h:1934
int numberOfCCs() const
Returns the number of connected components.
Definition Graph_d.h:1916
CCsInfo(const Graph &G)
Creates a info structure associated with graph G.
const Graph & constGraph() const
Returns the associated graph.
Definition Graph_d.h:1913
node v(int i) const
Returns the node with index i.
Definition Graph_d.h:1945
Array< int > m_startEdge
start edge of each connected component in m_edges.
Definition Graph_d.h:1903
Array< int > m_startNode
start node of each connected component in m_nodes.
Definition Graph_d.h:1902
Array< edge > m_edges
array of all edges.
Definition Graph_d.h:1901
int stopNode(int cc) const
Returns the index of (one past) the last node in connected component cc.
Definition Graph_d.h:1928
int stopEdge(int cc) const
Returns the index of (one past) the last edge in connected component cc.
Definition Graph_d.h:1942
int startNode(int cc) const
Returns the index of the first node in connected component cc.
Definition Graph_d.h:1925
internal::SimpleRange< Array< node >::const_iterator > nodes(int cc) const
Definition Graph_d.h:1930
int startEdge(int cc) const
Returns the index of the first edge in connected component cc.
Definition Graph_d.h:1939
const Graph * m_graph
points to the associated graph.
Definition Graph_d.h:1897
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:1222
bool empty()
Checks whether this set is empty.
void hide(edge e)
Hides the given edge.
~HiddenEdgeSet()
Restores all hidden edges.
Definition Graph_d.h:1239
internal::GraphList< EdgeElement >::iterator begin()
Return an iterator to the first hidden edge in this set.
void restore(edge e)
Reveals the given edge.
ListIterator< HiddenEdgeSet * > m_it
Definition Graph_d.h:1284
HiddenEdgeSet(Graph &graph)
Creates a new set of hidden edges.
Definition Graph_d.h:1232
internal::GraphList< EdgeElement >::iterator end()
Return an iterator one past the last hidden edge in this set.
int size()
Returns the number of edges contained in this set.
internal::GraphList< EdgeElement > m_edges
Definition Graph_d.h:1283
void restore()
Restores all edges contained in this set.
Iterator for AdjEntries of a graph.
Definition Graph_d.h:524
AdjElement & operator->() const
Returns a reference to the associated adjElement.
Definition Graph_d.h:551
bool operator!=(const GraphAdjIterator &iter) const
Inequality operator.
Definition Graph_d.h:559
bool operator==(const GraphAdjIterator &iter) const
Equality operator.
Definition Graph_d.h:554
adjEntry operator*() const
Returns the associated adjEntry.
Definition Graph_d.h:548
void next()
Proceeds to the next adjEntry.
GraphAdjIterator & operator++()
Increment operator (prefix).
Definition Graph_d.h:562
GraphAdjIterator & operator--()
Decrement operator (prefix).
Definition Graph_d.h:575
GraphAdjIterator operator--(int)
Decrement operator (postfix).
Definition Graph_d.h:581
void prev()
Returns to the previous adjEntry.
GraphAdjIterator end()
Returns an iterator to the one-past-last adjEntry in the associated graph.
Definition Graph_d.h:539
GraphAdjIterator(Graph *graph=nullptr, adjEntry entry=nullptr)
Constructor.
GraphAdjIterator operator++(int)
Increment operator (postfix).
Definition Graph_d.h:568
GraphAdjIterator begin()
Returns an iterator to the first adjEntry in the associated graph.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
edge newEdge(node v, adjEntry adjTgt, int index=-1)
Creates a new edge at predefined positions in the adjacency lists.
Definition Graph_d.h:1099
node contract(edge e, bool keepSelfLoops=false)
Contracts edge e while preserving the order of adjacency entries.
int maxNodeIndex() const
Returns the largest used node index.
Definition Graph_d.h:985
virtual void unsplit(edge eIn, edge eOut)
Undoes a split operation.
internal::GraphNodeRegistry & nodeRegistry()
Returns a reference to the registry of node arrays associated with this graph.
Definition Graph_d.h:1623
internal::GraphEdgeRegistry & edgeRegistry()
Returns a reference to the registry of edge arrays associated with this graph.
Definition Graph_d.h:1631
void unsplit(node u)
Undoes a split operation.
edge newEdge(adjEntry adjSrc, node w, int index=-1)
Creates a new edge at predefined positions in the adjacency lists.
Definition Graph_d.h:1118
node splitNode(adjEntry adjStartLeft, adjEntry adjStartRight)
Splits a node while preserving the order of adjacency entries.
node chooseNode(std::function< bool(node)> includeNode=[](node) { return true;}, bool isFastTest=true) const
Returns a random node.
node lastNode() const
Returns the last node in the list of all nodes.
Definition Graph_d.h:997
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition Graph_d.h:979
internal::GraphEdgeRegistry m_regEdgeArrays
The registered edge arrays.
Definition Graph_d.h:878
void moveSource(edge e, node w)
Moves the source node of edge e to node w.
void sort(node v, const ADJ_ENTRY_LIST &newOrder)
Sorts the adjacency list of node v according to newOrder.
Definition Graph_d.h:1480
edge lastEdge() const
Returns the last edge in the list of all edges.
Definition Graph_d.h:1003
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition Graph_d.h:1000
void moveAdjBefore(adjEntry adjMove, adjEntry adjBefore)
Moves adjacency entry adjMove before adjBefore.
Definition Graph_d.h:1559
void collapse(NODELIST &nodesToCollapse)
Collapses all nodes in the list nodesToCollapse to the first node in the list.
Definition Graph_d.h:1450
void swapAdjEdges(adjEntry adj1, adjEntry adj2)
Exchanges two entries in an adjacency list.
Definition Graph_d.h:1577
virtual void clear()
Removes all nodes and all edges from the graph.
static void insertAdjEntry(node n, adjEntry newAdj, Direction dir)
Definition Graph_d.h:2031
int maxEdgeIndex() const
Returns the largest used edge index.
Definition Graph_d.h:988
void moveTarget(edge e, node w)
Moves the target node of edge e to node w.
void allEdges(CONTAINER &edgeContainer) const
Returns a container with all edges of the graph.
Definition Graph_d.h:1043
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
void move(edge e, adjEntry adjSrc, Direction dirSrc, adjEntry adjTgt, Direction dirTgt)
Moves edge e to a different adjacency list.
void reverseEdge(edge e)
Reverses the edge e, i.e., exchanges source and target node.
edge newEdge(adjEntry adjSrc, adjEntry adjTgt, Direction dir=Direction::after, int index=-1)
Creates a new edge at predefined positions in the adjacency lists.
Definition Graph_d.h:1140
internal::GraphAdjRegistry m_regAdjArrays
The registered adjEntry arrays.
Definition Graph_d.h:879
void resetNodeIdCount(int maxId)
int maxAdjEntryIndex() const
Returns the largest used adjEntry index.
Definition Graph_d.h:991
int m_edgeIdCount
The Index that will be assigned to the next created edge.
Definition Graph_d.h:875
int m_nodeIdCount
The Index that will be assigned to the next created node.
Definition Graph_d.h:874
virtual void postInsert(void *userData, int newNodes, int newEdges)
Callback notifying subclasses that an insert() call has finished.
Definition Graph_d.h:1891
int numberOfEdges() const
Returns the number of edges in the graph.
Definition Graph_d.h:982
bool representsCombEmbedding() const
Returns true iff the graph represents a combinatorial embedding.
Definition Graph_d.h:1607
void resetEdgeIdCount(int maxId)
Resets the edge id count to maxId.
List< HiddenEdgeSet * > m_hiddenEdgeSets
The list of hidden edges.
Definition Graph_d.h:881
virtual void nodeInserted(void *userData, node original, node copy)
Callback notifying subclasses that insert() copied a node.
Definition Graph_d.h:1873
void reverseAdjEdges()
Reverses all adjacency lists.
std::pair< int, int > insert(const Graph &G)
Inserts a copy of a given Graph G into this graph.
Definition Graph_d.h:1834
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition Graph_d.h:929
std::pair< int, int > insert(const NL &nodeList, const EL &edgeList, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given subgraph into this graph.
Definition Graph_d.h:1771
void moveTarget(edge e, adjEntry adjTgt, Direction dir)
Moves the target node of edge e to a specific position in an adjacency list.
void sort(node v, IT begin, IT end)
Sorts the adjacency list of node v according to the range denoted by two iterators.
Definition Graph_d.h:1496
void allNodes(CONTAINER &nodeContainer) const
Returns a container with all nodes of the graph.
Definition Graph_d.h:1033
virtual void delEdge(edge e)
Removes edge e from the graph.
const internal::GraphNodeRegistry & nodeRegistry() const
Returns a const reference to the registry of node arrays associated with this graph.
Definition Graph_d.h:1626
edge chooseEdge(std::function< bool(edge)> includeEdge=[](edge) { return true;}, bool isFastTest=true) const
Returns a random edge.
void moveAdj(adjEntry adjMove, Direction dir, adjEntry adjPos)
Moves adjacency entry adjMove before or after adjPos.
Definition Graph_d.h:1528
node newNode(int index=-1)
Creates a new node and returns it.
Definition Graph_d.h:1061
static void insertAdjEntry(adjEntry oldAdj, adjEntry newAdj, Direction dir)
Definition Graph_d.h:2023
node firstNode() const
Returns the first node in the list of all nodes.
Definition Graph_d.h:994
edge newEdge(node v, node w, int index=-1)
Creates a new edge (v,w) and returns it.
Definition Graph_d.h:1080
void consistencyCheck() const
Asserts that this graph is consistent.
Graph()
Constructs an empty graph.
internal::GraphAdjRegistry & adjEntryRegistry()
Returns a reference to the registry of adjEntry arrays associated with this graph.
Definition Graph_d.h:1639
std::pair< int, int > insert(const CCsInfo &info, int cc, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given connected component cc into this graph.
Definition Graph_d.h:1790
void reverseAdjEdges(node v)
Reverses the adjacency list of v.
Definition Graph_d.h:1518
NodeType
The type of nodes.
Definition Graph_d.h:909
virtual edge split(edge e)
Splits edge e into two edges introducing a new node.
internal::GraphNodeRegistry m_regNodeArrays
The registered node arrays.
Definition Graph_d.h:877
void moveAdjAfter(adjEntry adjMove, adjEntry adjAfter)
Moves adjacency entry adjMove after adjAfter.
Definition Graph_d.h:1544
bool empty() const
Returns true iff the graph is empty, i.e., contains no nodes.
Definition Graph_d.h:976
void reverseAllEdges()
Reverses all edges in the graph.
EdgeType
The type of edges (only used in derived classes).
Definition Graph_d.h:906
const internal::GraphAdjRegistry & adjEntryRegistry() const
Returns a const reference to the registry of adjEntry arrays associated with this graph.
Definition Graph_d.h:1642
edge pureNewEdge(node src, node tgt, int index)
Creates a new edge object with id index and corresponding AdjElements and adds it to the list of edge...
Definition Graph_d.h:1990
node pureNewNode(int index)
Creates a new node object with id index and adds it to the list of nodes.
Definition Graph_d.h:1959
virtual ~Graph()
Destructor.
void restoreAllEdges()
Restore all hidden edges and invalidate all HiddenEdgeSets.
void moveSource(edge e, adjEntry adjSrc, Direction dir)
Moves the source node of edge e to a specific position in an adjacency list.
edge searchEdge(node v, node w, bool directed=false) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w ))).
void moveAdj(adjEntry adj, node w)
moves adjacency entry to node w
virtual void edgeInserted(void *userData, edge original, edge copy)
Callback notifying subclasses that insert() copied an edge.
Definition Graph_d.h:1882
edge newEdge(S src, Direction dirSrc, T tgt, Direction dirTgt, int index=-1)
Creates a new edge at predefined positions in the adjacency lists.
Definition Graph_d.h:1165
std::pair< int, int > insert(const Graph &G, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given Graph G into this graph.
Definition Graph_d.h:1810
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
int genus() const
Returns the genus of the graph's embedding.
virtual void * preInsert(bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap, int *newNodes, int *newEdges)
Callback notifying subclasses that some graph is about to be insert() -ed.
Definition Graph_d.h:1861
const internal::GraphEdgeRegistry & edgeRegistry() const
Returns a const reference to the registry of edge arrays associated with this graph.
Definition Graph_d.h:1634
Abstract Base class for graph observers.
Definition Graph_d.h:775
const Graph * getGraph() const
Definition Graph_d.h:800
virtual void edgeDeleted(edge e)=0
Called by watched graph just before an edge is deleted.
GraphObserver()=default
Constructs instance of GraphObserver class.
virtual void nodeDeleted(node v)=0
Called by watched graph just before a node is deleted.
virtual void edgeAdded(edge e)=0
Called by watched graph after an edge has been added.
virtual void nodeAdded(node v)=0
Called by watched graph after a node has been added.
virtual void cleared()=0
Called by watched graph when its clear function is called, just before things are removed.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Encapsulates a pointer to a list element.
Definition List.h:113
Class for the representation of nodes.
Definition Graph_d.h:241
void allAdjEntries(ADJLIST &adjList) const
Returns a list with all adjacency entries of this node.
Definition Graph_d.h:304
void adjEdges(EDGELIST &edgeList) const
Returns a list with all edges incident to this node.
Definition Graph_d.h:320
void inEdges(EDGELIST &edgeList) const
Returns a list with all incoming edges of this node.
Definition Graph_d.h:502
int m_id
The (unique) index of the node.
Definition Graph_d.h:248
NodeElement(const Graph *pGraph, int id)
Constructs a node element with index id.
Definition Graph_d.h:263
const Graph * m_pGraph
The graph containg this node (debug only).
Definition Graph_d.h:252
int indeg() const
Returns the indegree of the node.
Definition Graph_d.h:278
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition Graph_d.h:284
void outEdges(EDGELIST &edgeList) const
Returns a list with all outgoing edges of this node.
Definition Graph_d.h:513
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
node succ() const
Returns the successor in the list of all nodes.
Definition Graph_d.h:293
int index() const
Returns the (unique) node index.
Definition Graph_d.h:275
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:287
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition Graph_d.h:345
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition Graph_d.h:290
node pred() const
Returns the predecessor in the list of all nodes.
Definition Graph_d.h:296
int m_indeg
The indegree of the node.
Definition Graph_d.h:246
static int compare(const NodeElement &x, const NodeElement &y)
Standard Comparer.
Definition Graph_d.h:349
int outdeg() const
Returns the outdegree of the node.
Definition Graph_d.h:281
int m_outdeg
The outdegree of the node.
Definition Graph_d.h:247
Base class for an observable object that can be tracked by multiple Observer objects.
Definition Observer.h:127
Base class for an observer for a single Observable object.
Definition Observer.h:53
Dynamic arrays indexed with arbitrary keys.
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< Registry, Value >, internal::RegisteredArrayWithoutDefault< Registry, Value > >::type RA
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Abstract base class for registries.
void keyAdded(Key key)
Records the addition of a new key and resizes all registered arrays if necessary.
void reserveSpace(int new_keys)
Resizes all arrays to make space of new_keys new keys.
int getArraySize() const
Returns the current size of all registered arrays.
RegisteredArray for edges of a graph.
Definition Graph_d.h:677
const Value & operator()(adjEntry adj) const
Returns a const reference to the element associated with the edge corresponding to adj.
Definition Graph_d.h:701
Value & operator[](adjEntry adj)
Returns a reference to the element associated with the edge corresponding to adj.
Definition Graph_d.h:694
Value & operator()(adjEntry adj)
Returns a reference to the element associated with the edge corresponding to adj.
Definition Graph_d.h:708
const Value & operator[](adjEntry adj) const
Returns a const reference to the element associated with the edge corresponding to adj.
Definition Graph_d.h:687
adjEntry mapEndpoint(adjEntry adj) const
Map a source/target adjEntry to the source/target adjEntry of the corresponding edges.
Definition Graph_d.h:730
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
The base class for objects used by (hyper)graphs.
Definition GraphList.h:60
GraphElement * m_next
The successor in the list.
Definition GraphList.h:65
GraphElement * m_prev
The predecessor in the list.
Definition GraphList.h:66
Base class for GraphElement lists.
Definition GraphList.h:72
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:301
T * head() const
Returns the first element in the list.
Definition GraphList.h:324
void move(T *pX, GraphList< T > &L, T *pY, Direction dir)
Moves element pX to list L and inserts it before or after pY.
Definition GraphList.h:339
T * tail() const
Returns the last element in the list.
Definition GraphList.h:327
bool empty() const
Returns true iff the list is empty.
Definition GraphList.h:92
void pushBack(T *pX)
Adds element pX at the end of the list.
Definition GraphList.h:330
int size() const
Returns the size of the list.
Definition GraphList.h:89
Public read-only interface for lists of graph objects.
Definition GraphList.h:410
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Graph * graphOf() const
Returns a pointer to the associated graph.
Definition Graph_d.h:666
Registry for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:599
bool isKeyAssociated(Key *key) const
Definition Graph_d.h:612
static int keyToIndex(Key *key)
Definition Graph_d.h:610
int calculateArraySize(int add) const
Definition Graph_d.h:628
typename Iterable::iterator iterator
Definition Graph_d.h:604
Graph * graphOf() const
Returns a pointer to the associated graph.
Definition Graph_d.h:635
GraphRegistry(Graph *graph, int *nextKeyIndex)
Constructor.
Definition Graph_d.h:607
Declarations for Comparer objects.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Utility macros for declaring copy and move constructors and assignment operations.
#define OGDF_COPY_CONSTR(cls)
Declares the copy constructor for class cls.
Definition copy_move.h:57
#define OGDF_COPY_OP(cls)
Declares the copy assignment operation for class cls. Don't forget to return *this;.
Definition copy_move.h:59
#define OGDF_NO_COPY(cls)
Explicitly disables (deletes) copy construction and assignment for class cls.
Definition copy_move.h:37
#define OGDF_NO_MOVE(cls)
Explicitly disables (deletes) move construction and assignment for class cls.
Definition copy_move.h:42
Decralation of graph iterators.
#define OGDF_AUGMENT_STATICCOMPARER(type)
Add this macro to your class to turn it into a full static comparer.
Definition comparer.h:229
NodeElement * node
The type of nodes.
Definition Graph_d.h:71
EdgeElement * edge
The type of edges.
Definition Graph_d.h:75
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:206
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition memory.h:92
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
node adjToNode(adjEntry adj)
Definition Graph_d.h:809
void getAllNodes(const Graph &G, CONTAINER &nodes)
Definition Graph_d.h:2062
void getAllEdges(const Graph &G, CONTAINER &edges)
Definition Graph_d.h:2079
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
void copyEmbedding(const Graph &from, Graph &to, std::function< adjEntry(adjEntry)> adjMapFromTo)
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition tuples.h:77
bool filter_any_edge(edge e)
std::function<bool(edge)> that returns true for any edge e
Direction
Definition basic.h:150
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
bool filter_any_node(node n)
std::function<bool(node)> that returns true for any node n
NodePair()=default
NodePair(node src, node tgt)
Definition Graph_d.h:2102