Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

HypergraphArray.h
Go to the documentation of this file.
1 
34 #pragma once
35 
37 
38 namespace ogdf {
39 
42 
43 public:
44 
50 
53 
56  : m_hypergraph(nullptr)
57  {
58  }
59 
61  explicit HypergraphArrayBase(const Hypergraph *pH)
62  {
63  m_hypergraph = pH;
64  }
65 
68  {
69  }
70 
72  const Hypergraph *hypergraphOf() const {
73  return m_hypergraph;
74  }
75 
77  virtual void reinit(int initTableSize) = 0;
78 
80  virtual void reregister(const Hypergraph *H) = 0;
81 
83  virtual void enlargeTable(int newTableSize) = 0;
84 
86  virtual void disconnect() = 0;
87 };
88 
90 
93 template<class T> class HypernodeArray :
94 private Array<T>, protected HypergraphArrayBase {
95 
97  T m_x;
98 
99 public:
100 
103 
105  HypernodeArray(const Hypergraph &H, const T &x)
106  : Array<T>(0,H.hypernodeArrayTableSize() - 1, x),
107  HypergraphArrayBase(&H), m_x(x)
108  {
109  m_it = H.registerHypernodeArray(this);
110  }
111 
112  virtual ~HypernodeArray()
113  {
114  if (m_hypergraph)
116  }
117 
120  {
121  return Array<T>::operator [](v->index());
122  }
123 
125  const T &operator[](int index) const
126  {
127  return Array<T>::operator [](index);
128  }
129 
131  T &operator[](int index)
132  {
133  return Array<T>::operator [](index);
134  }
135 
138  {
140  m_x = a.m_x;
142  return *this;
143  }
144 
146  void init(const Hypergraph &H)
147  {
149  }
150 
152  void init(const Hypergraph &H, const T &x)
153  {
154  Array<T>::init(0, H.hypernodeArrayTableSize() - 1, m_x = 0);
155  reregister(&H);
156  }
157 
158  virtual void reregister(const Hypergraph *H)
159  {
160  if (m_hypergraph)
162 
163  if ((m_hypergraph = H) != nullptr)
164  m_it = H->registerHypernodeArray(this);
165  }
166 
167 private:
168 
169  virtual void enlargeTable(int newTableSize)
170  {
171  Array<T>::resize(newTableSize, m_x);
172  }
173 
174  virtual void reinit(int initTableSize)
175  {
176  Array<T>::init(0, initTableSize - 1, m_x);
177  }
178 
179  virtual void disconnect()
180  {
181  Array<T>::init();
182  m_hypergraph = nullptr;
183  }
184 
186 };
187 
189 
192 template<class T> class HyperedgeArray :
193 private Array<T>, protected HypergraphArrayBase {
194 
196  T m_x;
197 
198 public:
199 
202  : Array<T>(), HypergraphArrayBase()
203  {
204  }
205 
207  HyperedgeArray(const Hypergraph &H, const T &x)
208  : Array<T>(0, H.hyperedgeArrayTableSize() - 1, x),
209  HypergraphArrayBase(&H), m_x(x)
210  {
211  m_it = H.registerHyperedgeArray(this);
212  }
213 
215  virtual ~HyperedgeArray()
216  {
217  if (m_hypergraph)
219  }
220 
222  bool valid() const
223  {
224  return Array<T>::low() <= Array<T>::high();
225  }
226 
229  {
230  return Array<T>::operator [](e->index());
231  }
232 
234  const T &operator[](int index) const
235  {
236  return Array<T>::operator [](index);
237  }
238 
240  T &operator[](int index)
241  {
242  return Array<T>::operator [](index);
243  }
244 
247  {
249  m_x = a.m_x;
251  return *this;
252  }
253 
255  void init(const Hypergraph &H)
256  {
258  }
259 
261  void init(const Hypergraph &H, const T &x)
262  {
263  Array<T>::init(0, H.hyperedgeArrayTableSize() - 1, m_x = 0);
264  reregister(&H);
265  }
266 
267  virtual void reregister(const Hypergraph *H)
268  {
269  if (m_hypergraph)
271 
272  if ((m_hypergraph = H) != nullptr)
273  m_it = H->registerHyperedgeArray(this);
274  }
275 
276 private:
277 
278  virtual void enlargeTable(int newTableSize)
279  {
280  Array<T>::resize(newTableSize, m_x);
281  }
282 
283  virtual void reinit(int initTableSize)
284  {
285  Array<T>::init(0, initTableSize-1, m_x);
286  }
287 
288  virtual void disconnect()
289  {
290  Array<T>::init();
291  m_hypergraph = nullptr;
292  }
293 
295 };
296 
297 }
void unregisterHypernodeArray(ListIterator< HypergraphArrayBase *> it) const
Unregisters a hypernode array.
HypernodeArray< T > & operator=(const HypernodeArray< T > &a)
Assignment operator.
HyperedgeArray(const Hypergraph &H, const T &x)
Constructs a hypernode array associated with H.
const Hypergraph * m_hypergraph
The associated hypergraph.
int index() const
Returns the (unique) hypernode index.
Definition: Hypergraph.h:319
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
const T & operator[](int index) const
Returns a reference to the element with index index.
virtual void reregister(const Hypergraph *H)=0
Associates the array with a new hypergraph.
void init()
Reinitializes the array to an array with empty index set.
Definition: Array.h:354
INDEX high() const
Returns the maximal array index.
Definition: Array.h:279
void init(const Hypergraph &H)
Reinitializes the array. Associates the array with H.
T & operator[](hypernode v)
Returns a reference to the element with index v.
int index() const
Returns the index of a hyperedge.
Definition: Hypergraph.h:185
void unregisterHyperedgeArray(ListIterator< HypergraphArrayBase *> it) const
Unregisters an hyperedge array.
void init(const Hypergraph &H, const T &x)
Reinitializes the array. Associates the array with H.
T & operator[](hyperedge e)
Returns a reference to the element with the index of e.
virtual void reregister(const Hypergraph *H)
Associates the array with a new hypergraph.
T & operator[](int index)
Returns a reference to the element with index index.
virtual void disconnect()
Disconnetion from the hypergraph.
bool valid() const
Returns true iff the array is associated with a hypergraph.
virtual ~HyperedgeArray()
Destructor.
const T & operator[](int index) const
Returns a reference to the element with index index.
int hyperedgeArrayTableSize() const
Returns the table size of hyperedge arrays within the hypergraph.
Definition: Hypergraph.h:520
HypergraphArrayBase(const Hypergraph *pH)
Initializes an array associated with pH.
const Hypergraph * hypergraphOf() const
Returns a pointer to the associated hypergraph.
Declaration and a partial implementation of a Hypergraph class partly based on the original classes f...
void init(const Hypergraph &H, const T &x)
Reinitializes the array. Associates the array with H.
T & operator[](int index)
Returns a reference to the element with index index.
int hypernodeArrayTableSize() const
Returns the table size of hypernode arrays with the hypergraph.
Definition: Hypergraph.h:514
HyperedgeArray< T > & operator=(const HyperedgeArray< T > &a)
Assignment operator.
Class for the representation of hypernodes.
Definition: Hypergraph.h:263
HypernodeArray()
Constructs an empty hypernode array associated with no hypergraph.
ListIterator< HypergraphArrayBase * > m_it
Pointer to list element in the list of all registered hypergraph arrays which references this array...
virtual void reinit(int initTableSize)
Table re-initialization.
virtual ~HypergraphArrayBase()
Destructor, unregisters the array.
void init(const Hypergraph &H)
Reinitializes the array. Associates the array with H.
virtual void reinit(int initTableSize)
Table re-initialization.
Encapsulates a pointer to a list element.
Definition: List.h:42
ListIterator< HypergraphArrayBase * > registerHypernodeArray(HypergraphArrayBase *pHypernodeArray) const
Registers a node array.
HypernodeArray(const Hypergraph &H, const T &x)
Constructs a hypernode array associated with H.
HypergraphArrayBase()
Initializes an array not associated with a hypergraph.
virtual void reregister(const Hypergraph *H)
Associates the array with a new hypergraph.
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
T m_x
The default value for array elements.
virtual void disconnect()
Disconnetion from the hypergraph.
Abstract base class for hypergraph arrays.
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
T m_x
The default value for array elements.
Class for the representation of hyperedges.
Definition: Hypergraph.h:155
The namespace for all OGDF objects.
virtual void enlargeTable(int newTableSize)
Table size enlargement.
HyperedgeArray()
Constructs an empty hypernode array associated with no graph.
INDEX low() const
Returns the minimal array index.
Definition: Array.h:276
virtual void enlargeTable(int newTableSize)=0
Table size enlargement.
Dynamic arrays indexed with nodes.
Definition: Hypergraph.h:402
ListIterator< HypergraphArrayBase * > registerHyperedgeArray(HypergraphArrayBase *pHyperedgeArray) const
Dynamic arrays indexed with hypernodes.
Definition: Hypergraph.h:401
virtual void reinit(int initTableSize)=0
Table re-initialization.
virtual void disconnect()=0
Disconnetion from the hypergraph.
virtual void enlargeTable(int newTableSize)
Table size enlargement.