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
EdgeArray.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 EdgeArrayBase(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 ~EdgeArrayBase() {
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 EdgeArray : private Array<T>, protected EdgeArrayBase {
126 T m_x;
127
128public:
130 using key_type = edge;
132 using value_type = T;
133
138
141
143 explicit EdgeArray(const Graph& G) : Array<T>(G.edgeArrayTableSize()), EdgeArrayBase(&G) { }
144
146
150 EdgeArray(const Graph& G, const T& x)
151 : Array<T>(0, G.edgeArrayTableSize() - 1, x), EdgeArrayBase(&G), m_x(x) { }
152
154
158
160
164
170
172 bool valid() const { return Array<T>::low() <= Array<T>::high(); }
173
175 const Graph* graphOf() const { return m_pGraph; }
176
178 const T& operator[](edge e) const {
179 OGDF_ASSERT(e != nullptr);
180 OGDF_ASSERT(e->graphOf() == m_pGraph);
181 return Array<T>::operator[](e->index());
182 }
183
186 OGDF_ASSERT(e != nullptr);
187 OGDF_ASSERT(e->graphOf() == m_pGraph);
188 return Array<T>::operator[](e->index());
189 }
190
192 const T& operator()(edge e) const {
193 OGDF_ASSERT(e != nullptr);
194 OGDF_ASSERT(e->graphOf() == m_pGraph);
195 return Array<T>::operator[](e->index());
196 }
197
200 OGDF_ASSERT(e != nullptr);
201 OGDF_ASSERT(e->graphOf() == m_pGraph);
202 return Array<T>::operator[](e->index());
203 }
204
206 const T& operator[](adjEntry adj) const {
207 OGDF_ASSERT(adj != nullptr);
208 return Array<T>::operator[](adj->index() >> 1);
209 }
210
213 OGDF_ASSERT(adj != nullptr);
214 return Array<T>::operator[](adj->index() >> 1);
215 }
216
218 const T& operator()(adjEntry adj) const {
219 OGDF_ASSERT(adj != nullptr);
220 return Array<T>::operator[](adj->index() >> 1);
221 }
222
225 OGDF_ASSERT(adj != nullptr);
226 return Array<T>::operator[](adj->index() >> 1);
227 }
228
231 OGDF_DEPRECATED("Edge arrays should be indexed by an edge, not an integer index.")
232
233 const T& operator[](int index) const { return Array<T>::operator[](index); }
234
237 OGDF_DEPRECATED("Edge arrays should be indexed by an edge, not an integer index.")
238
239 T& operator[](int index) { return Array<T>::operator[](index); }
240
242
247
249
252 iterator begin() { return iterator(m_pGraph->firstEdge(), this); }
253
255
259
261
265
267
270 iterator end() { return iterator(nullptr, this); }
271
273
276 const_iterator end() const { return const_iterator(nullptr, this); }
277
279
282 const_iterator cend() const { return const_iterator(nullptr, this); }
283
285
290
292 void init() {
294 reregister(nullptr);
295 }
296
298 void init(const Graph& G) {
299 Array<T>::init(G.edgeArrayTableSize());
300 reregister(&G);
301 }
302
304
308 void init(const Graph& G, const T& x) {
309 Array<T>::init(0, G.edgeArrayTableSize() - 1, m_x = x);
310 reregister(&G);
311 }
312
314 void fill(const T& x) {
315 int high = m_pGraph->maxEdgeIndex();
316 if (high >= 0) {
317 Array<T>::fill(0, high, x);
318 }
319 }
320
324 m_x = a.m_x;
326 return *this;
327 }
328
330
334 Array<T>::operator=(std::move(a));
335 m_x = a.m_x;
336 moveRegister(a);
337 return *this;
338 }
339
341
346
347 static key_type findSuccKey(key_type key) { return key->succ(); }
348
349 static key_type findPredKey(key_type key) { return key->pred(); }
350
352
353private:
355
356 virtual void reinit(int initTableSize) { Array<T>::init(0, initTableSize - 1, m_x); }
357
358 virtual void disconnect() {
360 m_pGraph = nullptr;
361 }
362
364};
365
367
373
374public:
376
380 explicit BucketEdgeArray(const EdgeArray<int>& edgeArray) : m_pEdgeArray(&edgeArray) { }
381
383 int getBucket(const edge& e) override { return (*m_pEdgeArray)[e]; }
384};
385
386}
Pure declaration header, find template implementation in Graph.h.
Class for adjacency list elements.
Definition Graph_d.h:79
int index() const
Returns the index of this adjacency element.
Definition Graph_d.h:115
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
Bucket function for edges.
Definition EdgeArray.h:371
int getBucket(const edge &e) override
Returns bucket of edge e.
Definition EdgeArray.h:383
const EdgeArray< int > * m_pEdgeArray
Pointer to edge array.
Definition EdgeArray.h:372
BucketEdgeArray(const EdgeArray< int > &edgeArray)
Constructs a bucket function.
Definition EdgeArray.h:380
Abstract base class for bucket functions.
Definition basic.h:241
Abstract base class for edge arrays.
Definition EdgeArray.h:44
const Graph * m_pGraph
The associated graph.
Definition EdgeArray.h:52
EdgeArrayBase()
Initializes an edge array not associated with a graph.
Definition EdgeArray.h:55
virtual ~EdgeArrayBase()
Definition EdgeArray.h:74
EdgeArrayBase(const Graph *pG)
Initializes an edge array associated with pG.
Definition EdgeArray.h:58
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
void moveRegister(EdgeArrayBase &base)
Moves array registration from base to this array.
Definition EdgeArray.h:99
EdgeArrayBase(EdgeArrayBase &base)
Moves edge array base to this edge array.
Definition EdgeArray.h:65
ListIterator< EdgeArrayBase * > m_it
Pointer to list element in the list of all registered edge arrays which references this array.
Definition EdgeArray.h:49
void reregister(const Graph *pG)
Associates the array with a new graph.
Definition EdgeArray.h:89
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
virtual void disconnect()=0
Virtual function called when array is disconnected from the graph.
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
const_iterator end() const
Returns a const iterator to one-past-last entry in the edge array.
Definition EdgeArray.h:276
const T & operator()(adjEntry adj) const
Returns a reference to the element with index edge of adj.
Definition EdgeArray.h:218
void init(const Graph &G, const T &x)
Reinitializes the array. Associates the array with G.
Definition EdgeArray.h:308
internal::GraphArrayIterator< EdgeArray< T > > iterator
The type for edge array iterators.
Definition EdgeArray.h:135
T value_type
The type for array entries.
Definition EdgeArray.h:132
const Graph * graphOf() const
Returns a pointer to the associated graph.
Definition EdgeArray.h:175
T & operator[](edge e)
Returns a reference to the element with index e.
Definition EdgeArray.h:185
virtual void disconnect()
Virtual function called when array is disconnected from the graph.
Definition EdgeArray.h:358
const T & operator[](edge e) const
Returns a reference to the element with index e.
Definition EdgeArray.h:178
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
Definition EdgeArray.h:354
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Definition EdgeArray.h:356
EdgeArray(const Graph &G, const T &x)
Constructs an edge array associated with G.
Definition EdgeArray.h:150
EdgeArray()
Constructs an empty edge array associated with no graph.
Definition EdgeArray.h:140
T m_x
The default value for array elements.
Definition EdgeArray.h:126
T & operator[](adjEntry adj)
Returns a reference to the element with index edge of adj.
Definition EdgeArray.h:212
iterator end()
Returns an iterator to one-past-last entry in the edge array.
Definition EdgeArray.h:270
EdgeArray< T > & operator=(EdgeArray< T > &&a)
Assignment operator (move semantics).
Definition EdgeArray.h:333
EdgeArray(const Graph &G)
Constructs an edge array associated with G.
Definition EdgeArray.h:143
static key_type findSuccKey(key_type key)
Definition EdgeArray.h:347
bool valid() const
Returns true iff the array is associated with a graph.
Definition EdgeArray.h:172
T & operator()(edge e)
Returns a reference to the element with index e.
Definition EdgeArray.h:199
const T & operator[](adjEntry adj) const
Returns a reference to the element with index edge of adj.
Definition EdgeArray.h:206
T & operator()(adjEntry adj)
Returns a reference to the element with index edge of adj.
Definition EdgeArray.h:224
EdgeArray(EdgeArray< T > &&A)
Constructs an edge array containing the elements of A (move semantics).
Definition EdgeArray.h:163
static key_type findPredKey(key_type key)
Definition EdgeArray.h:349
const_iterator cend() const
Returns a const iterator to one-past-last entry in the edge array.
Definition EdgeArray.h:282
void init(const Graph &G)
Reinitializes the array. Associates the array with G.
Definition EdgeArray.h:298
void fill(const T &x)
Sets all array elements to x.
Definition EdgeArray.h:314
const T & operator()(edge e) const
Returns a reference to the element with index e.
Definition EdgeArray.h:192
const_iterator cbegin() const
Returns a const iterator to the first entry in the edge array.
Definition EdgeArray.h:264
EdgeArray< T > & operator=(const EdgeArray< T > &a)
Assignment operator.
Definition EdgeArray.h:322
EdgeArray(const EdgeArray< T > &A)
Constructs an edge array that is a copy of A.
Definition EdgeArray.h:157
void init()
Reinitializes the array. Associates the array with no graph.
Definition EdgeArray.h:292
iterator begin()
Returns an iterator to the first entry in the edge array.
Definition EdgeArray.h:252
internal::GraphArrayConstIterator< EdgeArray< T > > const_iterator
The type for edge array const iterators.
Definition EdgeArray.h:137
const_iterator begin() const
Returns a const iterator to the first entry in the edge array.
Definition EdgeArray.h:258
Class for the representation of edges.
Definition Graph_d.h:300
int index() const
Returns the index of the edge.
Definition Graph_d.h:332
edge succ() const
Returns the successor in the list of all edges.
Definition Graph_d.h:370
edge pred() const
Returns the predecessor in the list of all edges.
Definition Graph_d.h:373
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
ListIterator< NodeArrayBase * > registerArray(NodeArrayBase *pNodeArray) const
Registers a node array.
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition Graph_d.h:652
int maxEdgeIndex() const
Returns the largest used edge index.
Definition Graph_d.h:631
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
void unregisterArray(ListIterator< NodeArrayBase * > it) const
Unregisters a node array.
Encapsulates a pointer to a list element.
Definition List.h:103
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
EdgeElement * edge
The type of edges.
Definition Graph_d.h:68
#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