Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
AdjEntryArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
35
36namespace ogdf {
37
38
40
50
51public:
52 const Graph* m_pGraph;
53
56
58 explicit AdjEntryArrayBase(const Graph* pG) : m_pGraph(pG) {
59 if (pG) {
60 m_it = pG->registerArray(this);
61 }
62 }
63
72
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;
88 virtual void resetIndex(int newIndex, int oldIndex) = 0;
89
91 void reregister(const Graph* pG) {
92 if (m_pGraph) {
94 }
95 if ((m_pGraph = pG) != nullptr) {
96 m_it = pG->registerArray(this);
97 }
98 }
99
102 if (m_pGraph) {
104 }
105 m_pGraph = base.m_pGraph;
106 m_it = base.m_it;
107 base.m_pGraph = nullptr;
109 if (m_pGraph != nullptr) {
111 }
112 }
113};
114
116
126template<class T>
127class AdjEntryArray : private Array<T>, protected AdjEntryArrayBase {
128 T m_x;
129
130public:
134 using value_type = T;
135
140
143
145 explicit AdjEntryArray(const Graph& G)
146 : Array<T>(G.adjEntryArrayTableSize()), AdjEntryArrayBase(&G) { }
147
149
153 AdjEntryArray(const Graph& G, const T& x)
154 : Array<T>(0, G.adjEntryArrayTableSize() - 1, x), AdjEntryArrayBase(&G), m_x(x) { }
155
157
162
164
169
175
177 bool valid() const { return Array<T>::low() <= Array<T>::high(); }
178
180 const Graph* graphOf() const { return m_pGraph; }
181
183 const T& operator[](adjEntry adj) const {
184 OGDF_ASSERT(adj != nullptr);
185 OGDF_ASSERT(adj->graphOf() == m_pGraph);
186 return Array<T>::operator[](adj->index());
187 }
188
191 OGDF_ASSERT(adj != nullptr);
192 OGDF_ASSERT(adj->graphOf() == m_pGraph);
193 return Array<T>::operator[](adj->index());
194 }
195
197 const T& operator()(adjEntry adj) const {
198 OGDF_ASSERT(adj != nullptr);
199 OGDF_ASSERT(adj->graphOf() == m_pGraph);
200 return Array<T>::operator[](adj->index());
201 }
202
205 OGDF_ASSERT(adj != nullptr);
206 OGDF_ASSERT(adj->graphOf() == m_pGraph);
207 return Array<T>::operator[](adj->index());
208 }
209
211
216
218
221 iterator begin() { return iterator(findFirstKey(), this); }
222
224
227 const_iterator begin() const { return const_iterator(findFirstKey(), this); }
228
230
234
236
239 iterator end() { return iterator(nullptr, this); }
240
242
245 const_iterator end() const { return const_iterator(nullptr, this); }
246
248
251 const_iterator cend() const { return const_iterator(nullptr, this); }
252
254
259
261 void init() {
263 reregister(nullptr);
264 }
265
267 void init(const Graph& G) {
268 Array<T>::init(G.adjEntryArrayTableSize());
269 reregister(&G);
270 }
271
273
277 void init(const Graph& G, const T& x) {
278 Array<T>::init(0, G.adjEntryArrayTableSize() - 1, m_x = x);
279 reregister(&G);
280 }
281
283 void fill(const T& x) {
285 if (high >= 0) {
286 Array<T>::fill(0, high, x);
287 }
288 }
289
293 m_x = A.m_x;
294 reregister(A.m_pGraph);
295 return *this;
296 }
297
299
303 Array<T>::operator=(std::move(a));
304 m_x = a.m_x;
305 moveRegister(a);
306 return *this;
307 }
308
310
315
318 if (adj->succ() != nullptr) {
319 return adj->succ();
320 }
321 node v = adj->theNode();
322 for (v = v->succ(); v != nullptr && v->firstAdj() == nullptr; v = v->succ()) {
323 ;
324 }
325 return (v != nullptr) ? v->firstAdj() : nullptr;
326 }
327
330 if (adj->pred() != nullptr) {
331 return adj->pred();
332 }
333 node v = adj->theNode();
334 for (v = v->pred(); v != nullptr && v->lastAdj() == nullptr; v = v->pred()) {
335 ;
336 }
337 return (v != nullptr) ? v->lastAdj() : nullptr;
338 }
339
341
342private:
345 node v = m_pGraph->firstNode();
346 while (v != nullptr && v->firstAdj() == nullptr) {
347 v = v->succ();
348 }
349 adjEntry key = (v != nullptr) ? v->firstAdj() : nullptr;
350 return key;
351 }
352
355 node v = m_pGraph->lastNode();
356 while (v != nullptr && v->lastAdj() == nullptr) {
357 v = v->pred();
358 }
359 adjEntry key = (v != nullptr) ? v->lastAdj() : nullptr;
360 return key;
361 }
362
366
367 virtual void reinit(int initTableSize) { Array<T>::init(0, initTableSize - 1, m_x); }
368
372
373 virtual void disconnect() {
375 m_pGraph = nullptr;
376 }
377
379};
380
381}
Includes declaration of graph class.
Class for adjacency list elements.
Definition Graph_d.h:79
adjEntry pred() const
Returns the predecessor in the adjacency list.
Definition Graph_d.h:158
int index() const
Returns the index of this adjacency element.
Definition Graph_d.h:115
adjEntry succ() const
Returns the successor in the adjacency list.
Definition Graph_d.h:155
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:103
Abstract base class for adjacency entry arrays.
AdjEntryArrayBase()
Initializes an adjacency entry array not associated with a graph.
const Graph * m_pGraph
The associated graph.
void moveRegister(AdjEntryArrayBase &base)
Moves array registration from base to this array.
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
AdjEntryArrayBase(const Graph *pG)
Initializes an adjacency entry array associated with pG.
virtual void disconnect()=0
Virtual function called when array is disconnected from the graph.
AdjEntryArrayBase(AdjEntryArrayBase &base)
Moves adjacency entry array base to this adjacency entry array.
virtual void resetIndex(int newIndex, int oldIndex)=0
Virtual function called when the index of an adjacency entry is changed.
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
virtual ~AdjEntryArrayBase()
Destructor, unregisters the array.
ListIterator< AdjEntryArrayBase * > m_it
Pointer to list element in the list of all registered adjacency entry arrays which references this ar...
void reregister(const Graph *pG)
Associates the array with a new graph.
Dynamic arrays indexed with adjacency entries.
void init()
Reinitializes the array. Associates the array with no graph.
AdjEntryArray< T > & operator=(const AdjEntryArray< T > &A)
Assignment operator.
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
void init(const Graph &G, const T &x)
Reinitializes the array. Associates the array with G.
iterator begin()
Returns an iterator to the first entry in the array.
internal::GraphArrayConstIterator< AdjEntryArray< T > > const_iterator
The type for adjEntry array const iterators.
T m_x
The default value for array elements.
const_iterator begin() const
Returns a const iterator to the first entry in the array.
AdjEntryArray(AdjEntryArray< T > &&A)
Constructs an adjacency entry array containing the elements of A (move semantics).
T & operator[](adjEntry adj)
Returns a reference to the element with index adj.
virtual void disconnect()
Virtual function called when array is disconnected from the graph.
iterator end()
Returns an iterator to one-past-last entry in the array.
T & operator()(adjEntry adj)
Returns a reference to the element with index adj.
const Graph * graphOf() const
Returns a pointer to the associated graph.
const T & operator[](adjEntry adj) const
Returns a reference to the element with index adj.
void init(const Graph &G)
Reinitializes the array. Associates the array with G.
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
T value_type
The type for array entries.
const T & operator()(adjEntry adj) const
Returns a reference to the element with index adj.
adjEntry findLastKey() const
Returns the last key (adjacency entry in the graph).
AdjEntryArray(const Graph &G)
Constructs an adjacency entry array associated with G.
internal::GraphArrayIterator< AdjEntryArray< T > > iterator
The type for adjEntry array iterators.
const_iterator cend() const
Returns a const iterator to one-past-last entry in the array.
static adjEntry findPredKey(adjEntry adj)
Returns the key preceeding adj.
AdjEntryArray(const AdjEntryArray< T > &A)
Constructs an adjacency entry array that is a copy of A.
virtual void resetIndex(int newIndex, int oldIndex)
Virtual function called when the index of an adjacency entry is changed.
bool valid() const
Returns true iff the array is associated with a graph.
AdjEntryArray(const Graph &G, const T &x)
Constructs an adjacency entry array associated with G.
AdjEntryArray()
Constructs an empty adjacency entry array associated with no graph.
const_iterator end() const
Returns a const iterator to one-past-last entry in the array.
const_iterator cbegin() const
Returns a const iterator to the first entry in the array.
adjEntry findFirstKey() const
Returns the first key (adjacency entry in the graph).
void fill(const T &x)
Sets all array elements to x.
static adjEntry findSuccKey(adjEntry adj)
Returns the key succeeding adj.
AdjEntryArray< T > & operator=(AdjEntryArray< T > &&a)
Assignment operator (move semantics).
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 grow(INDEX add, const E &x)
Enlarges the array by add elements and sets new elements to x.
Definition Array.h:825
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
ListIterator< NodeArrayBase * > registerArray(NodeArrayBase *pNodeArray) const
Registers a node array.
node lastNode() const
Returns the last node in the list of all nodes.
Definition Graph_d.h:649
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
int maxAdjEntryIndex() const
Returns the largest used adjEntry index.
Definition Graph_d.h:634
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
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
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:223
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition Graph_d.h:226
node pred() const
Returns the predecessor in the list of all nodes.
Definition Graph_d.h:232
AdjElement * adjEntry
The type of adjacency entries.
Definition Graph_d.h:72
#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