Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ClusterArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
36
37namespace ogdf {
38
40
52
53public:
55
58
61 if (pC) {
62 m_it = pC->registerArray(this);
63 }
64 }
65
75
76 // destructor, unregisters the array
82
83 // event interface used by Graph
85 virtual void enlargeTable(int newTableSize) = 0;
87 virtual void reinit(int initTableSize) = 0;
89 virtual void disconnect() = 0;
90
92 void reregister(const ClusterGraph* pC) {
93 if (m_pClusterGraph) {
95 }
96 if ((m_pClusterGraph = pC) != nullptr) {
97 m_it = pC->registerArray(this);
98 }
99 }
100
103 if (m_pClusterGraph) {
105 }
106 m_pClusterGraph = base.m_pClusterGraph;
107 m_it = base.m_it;
108 base.m_pClusterGraph = nullptr;
110 if (m_pClusterGraph != nullptr) {
112 }
113 }
114};
115
117
123template<class T>
124class ClusterArray : private Array<T>, protected ClusterArrayBase {
125 T m_x;
126
127public:
131 using value_type = T;
132
137
140
143 : Array<T>(C.clusterArrayTableSize()), ClusterArrayBase(&C) { }
144
146
150 ClusterArray(const ClusterGraph& C, const T& x)
151 : Array<T>(0, C.clusterArrayTableSize() - 1, x), ClusterArrayBase(&C), m_x(x) { }
152
155
160 ClusterArray(const ClusterGraph& C, const T& x, int size)
161 : Array<T>(0, size - 1, x), ClusterArrayBase(&C), m_x(x) { }
162
164
169
171
175
181
183 bool valid() const { return Array<T>::low() <= Array<T>::high(); }
184
186 const ClusterGraph* graphOf() const { return m_pClusterGraph; }
187
189 const T& operator[](cluster c) const {
190 OGDF_ASSERT(c != nullptr);
191 OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
192 return Array<T>::operator[](c->index());
193 }
194
197 OGDF_ASSERT(c != nullptr);
198 OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
199 return Array<T>::operator[](c->index());
200 }
201
203 const T& operator()(cluster c) const {
204 OGDF_ASSERT(c != nullptr);
205 OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
206 return Array<T>::operator[](c->index());
207 }
208
211 OGDF_ASSERT(c != nullptr);
212 OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
213 return Array<T>::operator[](c->index());
214 }
215
218 OGDF_DEPRECATED("Cluster arrays should be indexed by a cluster, not an integer index.")
219
220 const T& operator[](int index) const { return Array<T>::operator[](index); }
221
224 OGDF_DEPRECATED("Cluster arrays should be indexed by a cluster, not an integer index.")
225
226 T& operator[](int index) { return Array<T>::operator[](index); }
227
229
234
236
240
242
246
248
252
254
257 iterator end() { return iterator(nullptr, this); }
258
260
263 const_iterator end() const { return const_iterator(nullptr, this); }
264
266
269 const_iterator cend() const { return const_iterator(nullptr, this); }
270
272
277
279 void init() {
281 reregister(nullptr);
282 }
283
285 void init(const ClusterGraph& C) {
287 reregister(&C);
288 }
289
291
295 void init(const ClusterGraph& C, const T& x) {
297 reregister(&C);
298 }
299
301 void fill(const T& x) {
303 if (high >= 0) {
304 Array<T>::fill(0, high, x);
305 }
306 }
307
311 m_x = a.m_x;
313 return *this;
314 }
315
317
321 Array<T>::operator=(std::move(a));
322 m_x = a.m_x;
323 moveRegister(a);
324 return *this;
325 }
326
328
333
334 static key_type findSuccKey(key_type key) { return key->succ(); }
335
336 static key_type findPredKey(key_type key) { return key->pred(); }
337
339
340private:
342
343 virtual void reinit(int initTableSize) { Array<T>::init(0, initTableSize - 1, m_x); }
344
345 virtual void disconnect() {
347 m_pClusterGraph = nullptr;
348 }
349
351};
352
353}
Declaration and implementation of Array class and Array algorithms.
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
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
int size() const
Returns the size (number of elements) of the array.
Definition Array.h:297
Abstract base class for cluster arrays.
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
ListIterator< ClusterArrayBase * > m_it
Pointer to list element in the list of all registered cluster arrays which references this array.
ClusterArrayBase(ClusterArrayBase &base)
Moves cluster array base to this cluster array.
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
void reregister(const ClusterGraph *pC)
Associates the array with a new cluster graph.
const ClusterGraph * m_pClusterGraph
The associated cluster graph.
ClusterArrayBase()
Initializes a cluster array not associated with a cluster graph.
ClusterArrayBase(const ClusterGraph *pC)
Initializes a cluster array associated with pC.
void moveRegister(ClusterArrayBase &base)
Moves array registration from base to this array.
virtual void disconnect()=0
Virtual function called when array is disconnected from the cluster graph.
Dynamic arrays indexed with clusters.
T m_x
The default value for array elements.
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
const_iterator cend() const
Returns a const iterator to one-past-last entry in the cluster array.
const_iterator end() const
Returns a const iterator to one-past-last entry in the cluster array.
const_iterator cbegin() const
Returns a const iterator to the first entry in the cluster array.
static key_type findSuccKey(key_type key)
const_iterator begin() const
Returns a const iterator to the first entry in the cluster array.
ClusterArray< T > & operator=(ClusterArray< T > &&a)
Assignment operator (move semantics).
ClusterArray(const ClusterGraph &C)
Constructs a cluster array associated with C.
ClusterArray(ClusterArray< T > &&A)
Constructs a cluster array containing the elements of A (move semantics).
iterator begin()
Returns an iterator to the first entry in the cluster array.
T & operator()(cluster c)
Returns a reference to the element with index c.
ClusterArray(const ClusterGraph &C, const T &x)
Constructs a cluster array associated with C.
static key_type findPredKey(key_type key)
ClusterArray(const ClusterArray< T > &A)
Constructs a cluster array that is a copy of A.
internal::GraphArrayConstIterator< ClusterArray< T > > const_iterator
The type for cluster array const iterators.
const ClusterGraph * graphOf() const
Returns a pointer to the associated cluster graph.
ClusterArray()
Constructs an empty cluster array associated with no graph.
virtual void disconnect()
Virtual function called when array is disconnected from the cluster graph.
ClusterArray(const ClusterGraph &C, const T &x, int size)
Constructs a cluster array associated with C and a given size (for static use).
void init(const ClusterGraph &C, const T &x)
Reinitializes the array. Associates the array with C.
const T & operator[](cluster c) const
Returns a reference to the element with index c.
const T & operator()(cluster c) const
Returns a reference to the element with index c.
bool valid() const
Returns true iff the array is associated with a graph.
void fill(const T &x)
Sets all array elements to x.
void init()
Reinitializes the array. Associates the array with no cluster graph.
T value_type
The type for array entries.
iterator end()
Returns an iterator to one-past-last entry in the cluster array.
void init(const ClusterGraph &C)
Reinitializes the array. Associates the array with C.
internal::GraphArrayIterator< ClusterArray< T > > iterator
The type for cluster array iterators.
T & operator[](cluster c)
Returns a reference to the element with index c.
ClusterArray< T > & operator=(const ClusterArray< T > &a)
Assignment operator.
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Representation of clusters in a clustered graph.
int index() const
Returns the (unique) index of the cluster.
cluster pred() const
Returns the predecessor of the cluster in the list of all clusters.
cluster succ() const
Returns the successor of the cluster in the list of all clusters.
Representation of clustered graphs.
void unregisterArray(ListIterator< ClusterArrayBase * > it) const
Unregisters a cluster array.
void moveRegisterArray(ListIterator< ClusterArrayBase * > it, ClusterArrayBase *pClusterArray) const
Move the registration it of a cluster array to pClusterArray (used with move semantics for cluster ar...
ListIterator< ClusterArrayBase * > registerArray(ClusterArrayBase *pClusterArray) const
Registers a cluster array.
cluster firstCluster() const
Returns the first cluster in the list of all clusters.
int maxClusterIndex() const
Returns the maximal used cluster index.
int clusterArrayTableSize() const
Returns the table size of cluster arrays associated with this graph.
Encapsulates a pointer to a list element.
Definition List.h:103
#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.
ClusterElement * cluster
The type of clusters.
Definition GML.h:110