Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
NodeArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph_d.h>
35
36namespace ogdf {
37
38
40
50
51public:
52 const Graph* m_pGraph;
53
56
58 explicit NodeArrayBase(const Graph* pG) : m_pGraph(pG) {
59 if (pG) {
60 m_it = pG->registerArray(this);
61 }
62 }
63
66 if (m_pGraph) {
68 }
69 base.m_pGraph = nullptr;
71 }
72
73 // destructor, unregisters the array
74 virtual ~NodeArrayBase() {
75 if (m_pGraph) {
77 }
78 }
79
80 // event interface used by Graph
82 virtual void enlargeTable(int newTableSize) = 0;
84 virtual void reinit(int initTableSize) = 0;
86 virtual void disconnect() = 0;
87
89 void reregister(const Graph* pG) {
90 if (m_pGraph) {
92 }
93 if ((m_pGraph = pG) != nullptr) {
94 m_it = pG->registerArray(this);
95 }
96 }
97
100 if (m_pGraph) {
102 }
103 m_pGraph = base.m_pGraph;
104 m_it = base.m_it;
105 base.m_pGraph = nullptr;
107 if (m_pGraph != nullptr) {
109 }
110 }
111};
112
114
124template<class T>
125class NodeArray : private Array<T>, protected NodeArrayBase {
126 T m_x;
127
128public:
129 using key_type = node;
130 using value_type = T;
131
132 using iterator =
136
139
141 NodeArray(const Graph& G) : Array<T>(G.nodeArrayTableSize()), NodeArrayBase(&G) { }
142
144
148 NodeArray(const Graph& G, const T& x)
149 : Array<T>(0, G.nodeArrayTableSize() - 1, x), NodeArrayBase(&G), m_x(x) { }
150
152
156
158
162
168
170 bool valid() const { return Array<T>::low() <= Array<T>::high(); }
171
173 const Graph* graphOf() const { return m_pGraph; }
174
176 const T& operator[](node v) const {
177 OGDF_ASSERT(v != nullptr);
178 OGDF_ASSERT(v->graphOf() == m_pGraph);
179 return Array<T>::operator[](v->index());
180 }
181
184 OGDF_ASSERT(v != nullptr);
185 OGDF_ASSERT(v->graphOf() == m_pGraph);
186 return Array<T>::operator[](v->index());
187 }
188
190 const T& operator()(node v) const {
191 OGDF_ASSERT(v != nullptr);
192 OGDF_ASSERT(v->graphOf() == m_pGraph);
193 return Array<T>::operator[](v->index());
194 }
195
198 OGDF_ASSERT(v != nullptr);
199 OGDF_ASSERT(v->graphOf() == m_pGraph);
200 return Array<T>::operator[](v->index());
201 }
202
205 OGDF_DEPRECATED("NodeArrays should be indexed by a node, not an integer index.")
206
207 const T& operator[](int index) const { return Array<T>::operator[](index); }
208
211 OGDF_DEPRECATED("NodeArrays should be indexed by a node, not an integer index.")
212
213 T& operator[](int index) { return Array<T>::operator[](index); }
214
216
221
223
226 iterator begin() { return iterator(m_pGraph->firstNode(), this); }
227
229
233
235
239
241
244 iterator end() { return iterator(nullptr, this); }
245
247
250 const_iterator end() const { return const_iterator(nullptr, this); }
251
253
256 const_iterator cend() const { return const_iterator(nullptr, this); }
257
259
264
266 void init() {
268 reregister(nullptr);
269 }
270
272 void init(const Graph& G) {
273 Array<T>::init(G.nodeArrayTableSize());
274 reregister(&G);
275 }
276
278
282 void init(const Graph& G, const T& x) {
283 Array<T>::init(0, G.nodeArrayTableSize() - 1, m_x = x);
284 reregister(&G);
285 }
286
288 void fill(const T& x) {
289 int high = m_pGraph->maxNodeIndex();
290 if (high >= 0) {
291 Array<T>::fill(0, high, x);
292 }
293 }
294
298 m_x = a.m_x;
300 return *this;
301 }
302
304
308 Array<T>::operator=(std::move(a));
309 m_x = a.m_x;
310 moveRegister(a);
311 return *this;
312 }
313
315
320
321 static key_type findSuccKey(key_type key) { return key->succ(); }
322
323 static key_type findPredKey(key_type key) { return key->pred(); }
324
326
327private:
329
330 virtual void reinit(int initTableSize) { Array<T>::init(0, initTableSize - 1, m_x); }
331
332 virtual void disconnect() {
334 m_pGraph = nullptr;
335 }
336
338};
339
340}
Pure declaration header, find template implementation in Graph.h.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition Array.h:303
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x.
Definition Array.h:437
INDEX high() const
Returns the maximal array index.
Definition Array.h:294
void init()
Reinitializes the array to an array with empty index set.
Definition Array.h:367
void fill(const E &x)
Sets all elements to x.
Definition Array.h:396
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition Array.h:447
INDEX low() const
Returns the minimal array index.
Definition Array.h:291
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
int maxNodeIndex() const
Returns the largest used node index.
Definition Graph_d.h:628
ListIterator< NodeArrayBase * > registerArray(NodeArrayBase *pNodeArray) const
Registers a node array.
void moveRegisterArray(ListIterator< ArrayBase * > it, ArrayBase *pArray) const
Move the registration it of an graph element array to pArray (used with move semantics for graph elem...
Definition Graph_d.h:1281
node firstNode() const
Returns the first node in the list of all nodes.
Definition Graph_d.h:646
void unregisterArray(ListIterator< NodeArrayBase * > it) const
Unregisters a node array.
Encapsulates a pointer to a list element.
Definition List.h:103
Abstract base class for node arrays.
Definition NodeArray.h:44
const Graph * m_pGraph
The associated graph.
Definition NodeArray.h:52
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
NodeArrayBase()
Initializes an node array not associated with a graph.
Definition NodeArray.h:55
virtual void disconnect()=0
Virtual function called when array is disconnected from the graph.
ListIterator< NodeArrayBase * > m_it
Pointer to list element in the list of all registered node arrays which references this array.
Definition NodeArray.h:49
void moveRegister(NodeArrayBase &base)
Moves array registration from base to this array.
Definition NodeArray.h:99
void reregister(const Graph *pG)
Associates the array with a new graph.
Definition NodeArray.h:89
virtual ~NodeArrayBase()
Definition NodeArray.h:74
NodeArrayBase(NodeArrayBase &base)
Moves node array base to this node array.
Definition NodeArray.h:65
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
NodeArrayBase(const Graph *pG)
Initializes an node array associated with pG.
Definition NodeArray.h:58
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
static key_type findSuccKey(key_type key)
Definition NodeArray.h:321
internal::GraphArrayConstIterator< NodeArray< T > > const_iterator
The type for node array const iterators.
Definition NodeArray.h:135
NodeArray(const Graph &G)
Constructs a node array associated with G.
Definition NodeArray.h:141
const Graph * graphOf() const
Returns a pointer to the associated graph.
Definition NodeArray.h:173
NodeArray< T > & operator=(NodeArray< T > &&a)
Assignment operator (move semantics).
Definition NodeArray.h:307
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
Definition NodeArray.h:328
NodeArray(const NodeArray< T > &A)
Constructs a node array that is a copy of A.
Definition NodeArray.h:155
NodeArray(const Graph &G, const T &x)
Constructs a node array associated with G.
Definition NodeArray.h:148
T m_x
The default value for array elements.
Definition NodeArray.h:126
void init(const Graph &G, const T &x)
Reinitializes the array. Associates the array with G.
Definition NodeArray.h:282
NodeArray()
Constructs an empty node array associated with no graph.
Definition NodeArray.h:138
virtual void disconnect()
Virtual function called when array is disconnected from the graph.
Definition NodeArray.h:332
void fill(const T &x)
Sets all array elements to x.
Definition NodeArray.h:288
void init(const Graph &G)
Reinitializes the array. Associates the array with G.
Definition NodeArray.h:272
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Definition NodeArray.h:330
iterator end()
Returns an iterator to one-past-last entry in the node array.
Definition NodeArray.h:244
NodeArray< T > & operator=(const NodeArray< T > &a)
Assignment operator.
Definition NodeArray.h:296
const T & operator[](node v) const
Returns a reference to the element with index v.
Definition NodeArray.h:176
T & operator()(node v)
Returns a reference to the element with index v.
Definition NodeArray.h:197
bool valid() const
Returns true iff the array is associated with a graph.
Definition NodeArray.h:170
static key_type findPredKey(key_type key)
Definition NodeArray.h:323
T & operator[](node v)
Returns a reference to the element with index v.
Definition NodeArray.h:183
NodeArray(NodeArray< T > &&A)
Constructs a node array containing the elements of A (move semantics).
Definition NodeArray.h:161
const T & operator()(node v) const
Returns a reference to the element with index v.
Definition NodeArray.h:190
iterator begin()
Returns an iterator to the first entry in the node array.
Definition NodeArray.h:226
const_iterator cbegin() const
Returns a const iterator to the first entry in the node array.
Definition NodeArray.h:238
internal::GraphArrayIterator< NodeArray< T > > iterator
The type for node array iterators.
Definition NodeArray.h:133
const_iterator begin() const
Returns a const iterator to the first entry in the node array.
Definition NodeArray.h:232
const_iterator end() const
Returns a const iterator to one-past-last entry in the node array.
Definition NodeArray.h:250
T value_type
The type for array entries.
Definition NodeArray.h:130
void init()
Reinitializes the array. Associates the array with no graph.
Definition NodeArray.h:266
const_iterator cend() const
Returns a const iterator to one-past-last entry in the node array.
Definition NodeArray.h:256
Class for the representation of nodes.
Definition Graph_d.h:177
node succ() const
Returns the successor in the list of all nodes.
Definition Graph_d.h:229
int index() const
Returns the (unique) node index.
Definition Graph_d.h:211
node pred() const
Returns the predecessor in the list of all nodes.
Definition Graph_d.h:232
NodeElement * node
The type of nodes.
Definition Graph_d.h:64
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:120
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Definition GML.h:110