Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

ClusterArray.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array.h>
36 
37 
38 namespace ogdf {
39 
41 
53 
54 public:
56 
58  ClusterArrayBase() : m_pClusterGraph(nullptr) { }
59 
61  explicit ClusterArrayBase(const ClusterGraph *pC) : m_pClusterGraph(pC) {
62  if(pC) m_it = pC->registerArray(this);
63  }
64 
66  ClusterArrayBase(ClusterArrayBase &base) : m_it(base.m_it), m_pClusterGraph(base.m_pClusterGraph) {
67  if(m_pClusterGraph) m_pClusterGraph->moveRegisterArray(m_it, this);
68  base.m_pClusterGraph = nullptr;
70  }
71 
72  // destructor, unregisters the array
73  virtual ~ClusterArrayBase() {
74  if (m_pClusterGraph) m_pClusterGraph->unregisterArray(m_it);
75  }
76 
77  // event interface used by Graph
79  virtual void enlargeTable(int newTableSize) = 0;
81  virtual void reinit(int initTableSize) = 0;
83  virtual void disconnect() = 0;
84 
86  void reregister(const ClusterGraph *pC) {
87  if (m_pClusterGraph) m_pClusterGraph->unregisterArray(m_it);
88  if ((m_pClusterGraph = pC) != nullptr) m_it = pC->registerArray(this);
89  }
90 
93  if (m_pClusterGraph) m_pClusterGraph->unregisterArray(m_it);
94  m_pClusterGraph = base.m_pClusterGraph;
95  m_it = base.m_it;
96  base.m_pClusterGraph = nullptr;
98  if (m_pClusterGraph != nullptr)
99  m_pClusterGraph->moveRegisterArray(m_it, this);
100  }
101 };
102 
104 
110 template<class T> class ClusterArray : private Array<T>, protected ClusterArrayBase {
111  T m_x;
112 
113 public:
115  using key_type = cluster;
117  using value_type = T;
118 
123 
124 
127 
130  Array<T>(C.clusterArrayTableSize()),
131  ClusterArrayBase(&C) { }
132 
134 
138  ClusterArray(const ClusterGraph &C, const T &x) :
139  Array<T>(0,C.clusterArrayTableSize()-1,x),
140  ClusterArrayBase(&C), m_x(x) { }
141 
144 
149  ClusterArray(const ClusterGraph &C, const T &x, int size) :
150  Array<T>(0,size-1,x),
151  ClusterArrayBase(&C), m_x(x) { }
152 
154 
158  Array<T>(A),
159  ClusterArrayBase(A.m_pClusterGraph), m_x(A.m_x) { }
160 
162 
166 
167 
173 
175  bool valid() const { return Array<T>::low() <= Array<T>::high(); }
176 
178  const ClusterGraph *graphOf() const {
179  return m_pClusterGraph;
180  }
181 
183  const T &operator[](cluster c) const {
184  OGDF_ASSERT(c != nullptr);
185  OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
186  return Array<T>::operator [](c->index());
187  }
188 
191  OGDF_ASSERT(c != nullptr);
192  OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
193  return Array<T>::operator [](c->index());
194  }
195 
197  const T &operator()(cluster c) const {
198  OGDF_ASSERT(c != nullptr);
199  OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
200  return Array<T>::operator [](c->index());
201  }
202 
205  OGDF_ASSERT(c != nullptr);
206  OGDF_ASSERT(c->graphOf() == m_pClusterGraph);
207  return Array<T>::operator [](c->index());
208  }
209 
212  OGDF_DEPRECATED("Cluster arrays should be indexed by a cluster, not an integer index.")
213  const T &operator[](int index) const
214  { return Array<T>::operator [](index); }
215 
218  OGDF_DEPRECATED("Cluster arrays should be indexed by a cluster, not an integer index.")
219  T &operator[](int index)
220  { return Array<T>::operator [](index); }
221 
223 
228 
230 
234 
236 
240 
242 
246 
248 
251  iterator end() { return iterator(nullptr, this); }
252 
254 
257  const_iterator end() const { return const_iterator(nullptr, this); }
258 
260 
263  const_iterator cend() const { return const_iterator(nullptr, this); }
264 
266 
271 
273  void init() {
274  Array<T>::init(); reregister(nullptr);
275  }
276 
278  void init(const ClusterGraph &C) {
280  }
281 
283 
287  void init(const ClusterGraph &C, const T &x) {
288  Array<T>::init(0,C.clusterArrayTableSize()-1, m_x = x); reregister(&C);
289  }
290 
292  void fill(const T &x) {
293  int high = m_pClusterGraph->maxClusterIndex();
294  if(high >= 0)
295  Array<T>::fill(0,high,x);
296  }
297 
301  m_x = a.m_x;
303  return *this;
304  }
305 
307 
312  m_x = a.m_x;
313  moveRegister(a);
314  return *this;
315  }
316 
317 
319 
324 
325  static key_type findSuccKey(key_type key) { return key->succ(); }
326  static key_type findPredKey(key_type key) { return key->pred(); }
327 
329 
330 private:
331  virtual void enlargeTable(int newTableSize) {
332  Array<T>::resize(newTableSize,m_x);
333  }
334 
335  virtual void reinit(int initTableSize) {
336  Array<T>::init(0,initTableSize-1,m_x);
337  }
338 
339  virtual void disconnect() {
340  Array<T>::init();
341  m_pClusterGraph = nullptr;
342  }
343 
345 
346 };
347 
348 }
void fill(const T &x)
Sets all array elements to x.
Definition: ClusterArray.h:292
Abstract base class for cluster arrays.
Definition: ClusterArray.h:47
ClusterArray(const ClusterGraph &C, const T &x, int size)
Constructs a cluster array associated with C and a given size (for static use).
Definition: ClusterArray.h:149
ClusterArrayBase(const ClusterGraph *pC)
Initializes a cluster array associated with pC.
Definition: ClusterArray.h:61
static key_type findSuccKey(key_type key)
Definition: ClusterArray.h:325
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
void reregister(const ClusterGraph *pC)
Associates the array with a new cluster graph.
Definition: ClusterArray.h:86
Derived class of GraphObserver providing additional functionality to handle clustered graphs...
const ClusterGraph * graphOf() const
Returns a pointer to the associated cluster graph.
Definition: ClusterArray.h:178
cluster succ() const
Returns the successor of the cluster in the list of all clusters.
Definition: ClusterGraph.h:153
ClusterArray(const ClusterGraph &C)
Constructs a cluster array associated with C.
Definition: ClusterArray.h:129
void init()
Reinitializes the array to an array with empty index set.
Definition: Array.h:354
virtual void disconnect()
Virtual function called when array is disconnected from the cluster graph.
Definition: ClusterArray.h:339
const ClusterGraph * m_pClusterGraph
The associated cluster graph.
Definition: ClusterArray.h:55
ClusterArray()
Constructs an empty cluster array associated with no graph.
Definition: ClusterArray.h:126
INDEX high() const
Returns the maximal array index.
Definition: Array.h:279
ClusterArray(const ClusterArray< T > &A)
Constructs a cluster array that is a copy of A.
Definition: ClusterArray.h:157
Definition: GML.h:110
cluster pred() const
Returns the predecessor of the cluster in the list of all clusters.
Definition: ClusterGraph.h:156
ClusterArrayBase(ClusterArrayBase &base)
Moves cluster array base to this cluster array.
Definition: ClusterArray.h:66
Declaration and implementation of Array class and Array algorithms.
T & operator[](cluster c)
Returns a reference to the element with index c.
Definition: ClusterArray.h:190
ClusterArray< T > & operator=(const ClusterArray< T > &a)
Assignment operator.
Definition: ClusterArray.h:299
void moveRegister(ClusterArrayBase &base)
Moves array registration from base to this array.
Definition: ClusterArray.h:92
T m_x
The default value for array elements.
Definition: ClusterArray.h:111
Representation of clustered graphs.
Definition: ClusterGraph.h:291
void unregisterArray(ListIterator< ClusterArrayBase *> it) const
Unregisters a cluster array.
virtual ~ClusterArrayBase()
Definition: ClusterArray.h:73
virtual void enlargeTable(int newTableSize)=0
Virtual function called when table size has to be enlarged.
E value_type
Represents the data type stored in an array element.
Definition: Array.h:207
const_iterator begin() const
Returns a const iterator to the first entry in the cluster array.
Definition: ClusterArray.h:239
int index() const
Returns the (unique) index of the cluster.
Definition: ClusterGraph.h:144
ClusterElement * cluster
The type of clusters.
Definition: ClusterGraph.h:46
virtual void enlargeTable(int newTableSize)
Virtual function called when table size has to be enlarged.
Definition: ClusterArray.h:331
ClusterArrayBase()
Initializes a cluster array not associated with a cluster graph.
Definition: ClusterArray.h:58
int maxClusterIndex() const
Returns the maximal used cluster index.
Definition: ClusterGraph.h:406
Dynamic arrays indexed with clusters.
Definition: ClusterArray.h:110
ArrayIterator< E > iterator
Provides a random-access iterator that can read or modify any element in an array.
Definition: Array.h:215
const_iterator cbegin() const
Returns a const iterator to the first entry in the cluster array.
Definition: ClusterArray.h:245
static key_type findPredKey(key_type key)
Definition: ClusterArray.h:326
Encapsulates a pointer to a list element.
Definition: List.h:42
int clusterArrayTableSize() const
Returns the table size of cluster arrays associated with this graph.
Definition: ClusterGraph.h:409
const_iterator cend() const
Returns a const iterator to one-past-last entry in the cluster array.
Definition: ClusterArray.h:263
bool valid() const
Returns true iff the array is associated with a graph.
Definition: ClusterArray.h:175
#define OGDF_NEW_DELETE
Makes the class use OGDF&#39;s memory allocator.
Definition: memory.h:84
const T & move(const T &v)
Definition: backward.hpp:243
ListIterator< ClusterArrayBase * > registerArray(ClusterArrayBase *pClusterArray) const
Registers a cluster array.
cluster firstCluster() const
Returns the first cluster in the list of all clusters.
Definition: ClusterGraph.h:432
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
ListIterator< ClusterArrayBase * > m_it
Pointer to list element in the list of all registered cluster arrays which references this array...
Definition: ClusterArray.h:52
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:422
void init(const ClusterGraph &C, const T &x)
Reinitializes the array. Associates the array with C.
Definition: ClusterArray.h:287
ClusterArray(ClusterArray< T > &&A)
Constructs a cluster array containing the elements of A (move semantics).
Definition: ClusterArray.h:165
const T & operator[](cluster c) const
Returns a reference to the element with index c.
Definition: ClusterArray.h:183
virtual void disconnect()=0
Virtual function called when array is disconnected from the cluster graph.
ArrayConstIterator< E > const_iterator
Provides a random-access iterator that can read a const element in an array.
Definition: Array.h:213
const_iterator end() const
Returns a const iterator to one-past-last entry in the cluster array.
Definition: ClusterArray.h:257
iterator end()
Returns an iterator to one-past-last entry in the cluster array.
Definition: ClusterArray.h:251
virtual void reinit(int initTableSize)
Virtual function called when table has to be reinitialized.
Definition: ClusterArray.h:335
void init(const ClusterGraph &C)
Reinitializes the array. Associates the array with C.
Definition: ClusterArray.h:278
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition: config.h:118
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...
Array< E, INDEX > & operator=(const Array< E, INDEX > &A)
Assignment operator.
Definition: Array.h:432
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:288
void fill(const E &x)
Sets all elements to x.
Definition: Array.h:383
The namespace for all OGDF objects.
virtual void reinit(int initTableSize)=0
Virtual function called when table has to be reinitialized.
iterator begin()
Returns an iterator to the first entry in the cluster array.
Definition: ClusterArray.h:233
void init()
Reinitializes the array. Associates the array with no cluster graph.
Definition: ClusterArray.h:273
const T & operator()(cluster c) const
Returns a reference to the element with index c.
Definition: ClusterArray.h:197
ClusterArray< T > & operator=(ClusterArray< T > &&a)
Assignment operator (move semantics).
Definition: ClusterArray.h:310
ClusterArray(const ClusterGraph &C, const T &x)
Constructs a cluster array associated with C.
Definition: ClusterArray.h:138
INDEX low() const
Returns the minimal array index.
Definition: Array.h:276
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
T & operator()(cluster c)
Returns a reference to the element with index c.
Definition: ClusterArray.h:204