Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 }; // class HypergraphArrayBase
89 
91 template<class T> class HypernodeArray :
92 private Array<T>, protected HypergraphArrayBase {
93 
95  T m_x;
96 
97 public:
98 
101 
103  HypernodeArray(const Hypergraph &H, const T &x)
104  : Array<T>(0,H.hypernodeArrayTableSize() - 1, x),
105  HypergraphArrayBase(&H), m_x(x)
106  {
107  m_it = H.registerHypernodeArray(this);
108  }
109 
110  virtual ~HypernodeArray()
111  {
112  if (m_hypergraph)
114  }
115 
118  {
119  return Array<T>::operator [](v->index());
120  }
121 
123  const T &operator[](int index) const
124  {
125  return Array<T>::operator [](index);
126  }
127 
129  T &operator[](int index)
130  {
131  return Array<T>::operator [](index);
132  }
133 
136  {
138  m_x = a.m_x;
140  return *this;
141  }
142 
144  void init(const Hypergraph &H)
145  {
147  }
148 
150  void init(const Hypergraph &H, const T &x)
151  {
152  Array<T>::init(0, H.hypernodeArrayTableSize() - 1, m_x = 0);
153  reregister(&H);
154  }
155 
156  virtual void reregister(const Hypergraph *H)
157  {
158  if (m_hypergraph)
160 
161  if ((m_hypergraph = H) != nullptr)
162  m_it = H->registerHypernodeArray(this);
163  }
164 
165 private:
166 
167  virtual void enlargeTable(int newTableSize)
168  {
169  Array<T>::resize(newTableSize, m_x);
170  }
171 
172  virtual void reinit(int initTableSize)
173  {
174  Array<T>::init(0, initTableSize - 1, m_x);
175  }
176 
177  virtual void disconnect()
178  {
179  Array<T>::init();
180  m_hypergraph = nullptr;
181  }
182 
184 
185 }; // class HypernodeArray<T>
186 
188 template<class T> class HyperedgeArray :
189 private Array<T>, protected HypergraphArrayBase {
190 
192  T m_x;
193 
194 public:
195 
198  : Array<T>(), HypergraphArrayBase()
199  {
200  }
201 
203  HyperedgeArray(const Hypergraph &H, const T &x)
204  : Array<T>(0, H.hyperedgeArrayTableSize() - 1, x),
205  HypergraphArrayBase(&H), m_x(x)
206  {
207  m_it = H.registerHyperedgeArray(this);
208  }
209 
211  virtual ~HyperedgeArray()
212  {
213  if (m_hypergraph)
215  }
216 
218  bool valid() const
219  {
220  return Array<T>::low() <= Array<T>::high();
221  }
222 
225  {
226  return Array<T>::operator [](e->index());
227  }
228 
230  const T &operator[](int index) const
231  {
232  return Array<T>::operator [](index);
233  }
234 
236  T &operator[](int index)
237  {
238  return Array<T>::operator [](index);
239  }
240 
243  {
245  m_x = a.m_x;
247  return *this;
248  }
249 
251  void init(const Hypergraph &H)
252  {
254  }
255 
257  void init(const Hypergraph &H, const T &x)
258  {
259  Array<T>::init(0, H.hyperedgeArrayTableSize() - 1, m_x = 0);
260  reregister(&H);
261  }
262 
263  virtual void reregister(const Hypergraph *H)
264  {
265  if (m_hypergraph)
267 
268  if ((m_hypergraph = H) != nullptr)
269  m_it = H->registerHyperedgeArray(this);
270  }
271 
272 private:
273 
274  virtual void enlargeTable(int newTableSize)
275  {
276  Array<T>::resize(newTableSize, m_x);
277  }
278 
279  virtual void reinit(int initTableSize)
280  {
281  Array<T>::init(0, initTableSize-1, m_x);
282  }
283 
284  virtual void disconnect()
285  {
286  Array<T>::init();
287  m_hypergraph = nullptr;
288  }
289 
291 
292 }; // class HyperedgeArray<T>
293 
294 } // end namespace ogdf
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:321
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:56
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:206
INDEX high() const
Returns the maximal array index.
Definition: Array.h:131
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:186
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:523
HypergraphArrayBase(const Hypergraph *pH)
Initializes an array associated with pH.
const Hypergraph * hypergraphOf() const
Returns a pointer to the associated hypergraph.
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:517
HyperedgeArray< T > & operator=(const HyperedgeArray< T > &a)
Assignment operator.
Class for the representation of hypernodes.
Definition: Hypergraph.h:265
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.
Declaration and a partial implementation of a Hypergraph class partly based on the original classes f...
virtual void reinit(int initTableSize)
Table re-initialization.
Encapsulates a pointer to a list element.
Definition: List.h:41
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:274
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:284
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:140
T m_x
The default value for array elements.
Class for the representation of hyperedges.
Definition: Hypergraph.h:156
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:128
virtual void enlargeTable(int newTableSize)=0
Table size enlargement.
Dynamic arrays indexed with nodes.
Definition: Hypergraph.h:405
ListIterator< HypergraphArrayBase * > registerHyperedgeArray(HypergraphArrayBase *pHyperedgeArray) const
Dynamic arrays indexed with hypernodes.
Definition: Hypergraph.h:404
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.