Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

HyperGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 #include <ogdf/basic/EList.h>
36 #include <ogdf/basic/EFreeList.h>
37 
38 namespace ogdf {
39 
41 {
42  friend class HyperGraphTypes;
43 
44 public:
45  // forward declaration to make AdjElement pointers available
46  class AdjElement;
47 
50  {
51  friend class HyperGraph;
52  friend class HyperGraphTypes;
53  public:
55  int index() const { return m_index; }
56 
58  int degree() const { return m_numAdj; }
59 
60  private:
65  int m_numAdj;
66  int m_index;
67  }; // class NodeElement
68 
69 
72  {
73  friend class HyperGraph;
74  friend class HyperGraphTypes;
75  public:
77  int index() const { return m_index; }
78 
80  int cardinality() const { return m_numAdj; }
81 
82  private:
87  int m_numAdj;
88  int m_index;
89  }; // class EdgeElement
90 
91 
93  class AdjElement
94  {
95  friend class HyperGraph;
96  friend class HyperGraphTypes;
97  public:
98  AdjElement() : m_pNode(0), m_pEdge(0) { }
99 
101  NodeElement* theNode() { return m_pNode; }
102 
104  EdgeElement* theEdge() { return m_pEdge; }
105 
107  int index() const { return m_index; }
108  private:
109 
111  m_pNode(pNode),
112  m_pEdge(pEdge),
113  m_pPrev_nodeAdj(0),
114  m_pNext_nodeAdj(0),
115  m_pPrev_edgeAdj(0),
116  m_pNext_edgeAdj(0)
117  { }
118 
121 
124 
127  int m_index;
128  };
129 
130  using node = NodeElement*;
131  using edge = EdgeElement*;
132 
133 protected:
137 
141 
142 protected:
144  NodeElement,
145  &NodeElement::m_pNext,
146  &NodeElement::m_index
148 
150  EdgeElement,
151  &EdgeElement::m_pNext,
152  &EdgeElement::m_index
154 
156  AdjElement,
157  &AdjElement::m_pNext_nodeAdj, // note: we just need one next pointer, nobody cares which one.
158  &AdjElement::m_index
160 
161 
162  template<typename E>
164  {
165  friend class HyperGraph;
166  public:
168  virtual void setSize(int numElements) = 0;
169 
172  };
173 
174 
175  template<typename T, typename E>
176  class GraphArray : protected Array<T>, GraphArrayBase<E>
177  {
178  friend class HyperGraph;
179  public:
180  // Creates an empty graph array not attached to a graph.
181  GraphArray() : Array<T>(), m_pGraph(nullptr), m_initialValue() { }
182 
184  explicit GraphArray(HyperGraph* pGraph) : GraphArray()
185  {
186  m_pGraph = pGraph;
187 
188  if (m_pGraph)
189  m_pGraph->registerArray(this);
190  }
191 
193  GraphArray(HyperGraph* pGraph, const T& initialValue) : GraphArray(pGraph) {
194  m_initialValue = initialValue;
195  }
196 
198 
201  virtual ~GraphArray()
202  {
203  if (m_pGraph)
204  m_pGraph->unregisterArray(this);
205  }
206 
208  const T& operator[](const E* e) const
209  {
210  return Array<T>::operator [](e->index());
211  }
212 
214  T& operator[](const E* e)
215  {
216  return Array<T>::operator [](e->index());
217  }
218 
220  HyperGraph* graph() const
221  {
222  return m_pGraph;
223  }
224 
225  protected:
226 
228  virtual void setSize(int numElements)
229  {
230  if (numElements > Array<T>::size())
231  Array<T>::resize(numElements,m_initialValue);
232  }
233 
236 
239 
240  }; // end of class GraphArray
241 
242 
243  template<typename ElementType> class ArrayControllerTypes;
244 
246  template<typename ElementType>
248  {
249  friend class ArrayControllerTypes<ElementType>;
250  public:
252  ArrayController() : m_tableSize(0)
253  {
255  }
256 
258  ~ArrayController();
259 
261  void registerArray(GraphArrayBase<ElementType>* pArray);
262 
264  void unregisterArray(GraphArrayBase<ElementType>* pArray);
265 
267  int newTableSize(int minSize)
268  {
269  int res = 1;
270  while (res < minSize)
271  res = res << 1;
272  return res;
273  }
274 
276  void numUsedIndicesChanged(int numUsedIndices);
277 
278  protected:
281 
284 
287 
290  };
291 
292 
293  template<typename ElementType>
295  {
296  public:
304  };
305 
306 
310 
311  void registerArray(GraphArrayBase<NodeElement>* pArray) { m_nodeArrayController.registerArray(pArray); }
312  void registerArray(GraphArrayBase<EdgeElement>* pArray) { m_edgeArrayController.registerArray(pArray); }
313  void registerArray(GraphArrayBase<AdjElement>* pArray) { m_adjArrayController.registerArray(pArray); }
314 
315 
316  void unregisterArray(GraphArrayBase<NodeElement>* pArray) { m_nodeArrayController.unregisterArray(pArray); }
317  void unregisterArray(GraphArrayBase<EdgeElement>* pArray) { m_edgeArrayController.unregisterArray(pArray); }
318  void unregisterArray(GraphArrayBase<AdjElement>* pArray) { m_adjArrayController.unregisterArray(pArray); }
319 
321  NodeElement* allocateNodeElement()
322  {
323  NodeElement* pResult = m_nodeAllocator.alloc();
324  m_nodeArrayController.numUsedIndicesChanged(m_nodeAllocator.numUsedIndices());
325  return pResult;
326  }
327 
329  EdgeElement* allocateEdgeElement()
330  {
331  EdgeElement* pResult = m_edgeAllocator.alloc();
332  m_edgeArrayController.numUsedIndicesChanged(m_edgeAllocator.numUsedIndices());
333  return pResult;
334  }
335 
337  AdjElement* allocateAdjElement()
338  {
339  AdjElement* pResult = m_adjAllocator.alloc();
340  m_adjArrayController.numUsedIndicesChanged(m_adjAllocator.numUsedIndices());
341  return pResult;
342  }
343 
345  void freeNodeElement(NodeElement* pNode)
346  {
347  m_nodeAllocator.free(pNode);
348  }
349 
351  void freeEdgeElement(EdgeElement* pEdge)
352  {
353  m_edgeAllocator.free(pEdge);
354  }
355 
357  void freeAdjElement(AdjElement* pAdj)
358  {
359  m_adjAllocator.free(pAdj);
360  }
361 
362 public:
363 
365  template<typename T>
366  class NodeArray : public GraphArray<T, NodeElement>
367  {
368  public:
369  explicit NodeArray(HyperGraph* pGraph) : GraphArray<T, NodeElement>(pGraph) {}
370  NodeArray(HyperGraph* pGraph, const T& initValue) : GraphArray<T, NodeElement>(pGraph, initValue) {}
371  };
372 
374  template<typename T>
375  class EdgeArray : public GraphArray<T, EdgeElement>
376  {
377  public:
378  explicit EdgeArray(HyperGraph* pGraph) : GraphArray<T, EdgeElement>(pGraph) {}
379  EdgeArray(HyperGraph* pGraph, const T& initValue) : GraphArray<T, EdgeElement>(pGraph, initValue) {}
380  };
381 
383  template<typename T>
384  class AdjArray : public GraphArray<T, AdjElement>
385  {
386  public:
387  explicit AdjArray(HyperGraph* pGraph) : GraphArray<T, AdjElement>(pGraph) {}
388  AdjArray(HyperGraph* pGraph, const T& initValue) : GraphArray<T, AdjElement>(pGraph, initValue) {}
389  };
390 
391 
393  HyperGraph();
394 
396  NodeElement* newNode();
397 
399  EdgeElement* newEdge();
400 
402  EdgeElement* newEdge(NodeElement* pNode1, NodeElement* pNode2)
403  {
404  EdgeElement* pEdge = newEdge();
405  newAdjElement( pNode1, pEdge );
406  newAdjElement( pNode2, pEdge );
407  return pEdge;
408  }
409 
411 
418  AdjElement* newAdjElement(NodeElement* pNode, EdgeElement* pEdge);
419 
421  void delAdjElement(AdjElement* pAdj);
422 
424  void delAdjElement(NodeElement* pNode, EdgeElement* pEdge)
425  {
426  AdjElement* pAdj = findAdjElement(pNode, pEdge);
427  if (pAdj) delAdjElement(pAdj);
428  }
429 
431  AdjElement* addNode(NodeElement* pNode, EdgeElement* pEdge, bool checkIfAlreadyExists = false)
432  {
433  if (!checkIfAlreadyExists)
434  return newAdjElement( pNode, pEdge );
435 
436  AdjElement* pAdj = findAdjElement(pNode, pEdge);
437  if (!pAdj)
438  pAdj = newAdjElement( pNode, pEdge );
439  return pAdj;
440  }
441 
443 
449  void removeNode(NodeElement* pNode, EdgeElement* pEdge, bool removeDuplicates = false)
450  {
451  AdjElement* pAdj = findAdjElement(pNode, pEdge);
452  if (!removeDuplicates && pAdj)
453  {
454  delAdjElement(pAdj);
455  } else
456  {
457  while (pAdj)
458  {
459  delAdjElement(pAdj);
460  pAdj = findAdjElement(pNode, pEdge);
461  }
462  }
463  }
464 
466 
472  AdjElement* findAdjElement(NodeElement* pNode, EdgeElement* pEdge) const;
473 
475  void delEdge(EdgeElement* pEdge);
476 
478  void delNode(NodeElement* pNode);
479 
480  int numberOfNodes() const;
481  int numberOfEdges() const;
482 
484  void clear();
485 
486 #if 0
487  void toCliqueGraph(
488  Graph* pG,
491  {
492  HyperGraph::NodeArray<ogdf::node> hgNode_to_gNode(this);
493  for (NodeList::iterator it = HyperGraph::NodeList::begin(this); it.valid(); it++)
494  {
495  HyperGraph::NodeElement* hgNode = *it;
496  ogdf::node gNode = pG->newNode();
497  hgNode_to_gNode[ hgNode ] = gNode;
498  if (pNodeMap)
499  (*pNodeMap)[gNode] = hgNode;
500  }
501 
502  for (HyperGraph::EdgeList::iterator it = HyperGraph::EdgeList::begin(this); it.valid(); it++)
503  {
504  EdgeElement* hgEdge = *it;
505  for (HyperGraph::EdgeAdjList::iterator adj_it = HyperGraph::EdgeAdjList::begin(hgEdge); adj_it.valid(); adj_it++)
506  {
507  for (HyperGraph::EdgeAdjList::iterator adj_it2 = adj_it.succ(); adj_it2.valid(); adj_it2++)
508  {
509  NodeElement* hgNode = (*adj_it)->theNode();
510  NodeElement* hgNode2 = (*adj_it2)->theNode();
511  node gNode = hgNode_to_gNode[ hgNode ];
512  node gNode2 = hgNode_to_gNode[ hgNode2 ];
513 
514  edge gEdge = pG->newEdge(gNode, gNode2);
515  if (pEdgeMap)
516  (*pEdgeMap)[gEdge] = hgEdge;
517  }
518  }
519  }
520  }
521 
522  void toStarGraph(
523  Graph* pG,
524  NodeArray<NodeElement*>* pNodeMap = 0,
525  EdgeArray<EdgeElement*>* pEdgeMap = 0)
526  {
527  HyperGraph::NodeArray<ogdf::node> hgNode_to_gNode(this);
528  for (NodeList::iterator it = HyperGraph::NodeList::begin(this); it.valid(); it++)
529  {
530  NodeElement* hgNode = *it;
531  node gNode = pG->newNode();
532  hgNode_to_gNode[ hgNode ] = gNode;
533  if (pNodeMap)
534  (*pNodeMap)[gNode] = hgNode;
535  }
536 
537  for (HyperGraph::EdgeList::iterator it = HyperGraph::EdgeList::begin(this); it.valid(); it++)
538  {
539  EdgeElement* hgEdge = *it;
540  node gNodeDummy = pG->newNode();
541  if (pNodeMap)
542  (*pNodeMap)[gNodeDummy] = 0;
543 
544  for (HyperGraph::EdgeAdjList::iterator adj_it = HyperGraph::EdgeAdjList::begin(hgEdge); adj_it.valid(); adj_it++)
545  {
546  NodeElement* hgNode = (*adj_it)->theNode();
547  node gNode = hgNode_to_gNode[ hgNode ];
548  edge gEdge = pG->newEdge(gNodeDummy, gNode);
549  if (pEdgeMap)
550  (*pEdgeMap)[gEdge] = hgEdge;
551  }
552  }
553  }
554 #endif
555 }; // end of class HyperGraph
556 
557 
560 {
561 public:
563  using NodeList = EList<
570  >;
571 
573  using EdgeList = EList<
574  HyperGraph, HyperGraph::EdgeElement,
580  >;
581 
583  using NodeAdjList = EList<
584  HyperGraph::NodeElement, HyperGraph::AdjElement,
590  >;
591 
593  using EdgeAdjList = EList<
594  HyperGraph::EdgeElement, HyperGraph::AdjElement,
600  >;
601 };
602 
603 
604 template<typename ElementType>
606 {
607  // Unregisters all arrays, but does not delete them.
610 }
611 
612 
613 // Registers a new graph array and sets the size to #m_tableSize.
614 template<typename ElementType>
616 {
618  pArray->setSize(m_tableSize);
619 }
620 
621 
622 // Unregisters an array by removing it from the list.
623 template<typename ElementType>
625 {
627  pArray->setSize(0);
628 }
629 
630 
631 template<typename ElementType>
633 {
634  // check if we have to grow
635  if (numUsedIndices > m_tableSize)
636  {
637  // we have to resize
638  // calculate new table size
639  m_tableSize = newTableSize(numUsedIndices);
640  // iterate over all arrays
642  it.valid(); it++)
643  {
644  // and resize them
645  (*it)->setSize(m_tableSize);
646  }
647  }
648 }
649 
650 
652 {
655 }
656 
657 
659 {
660  NodeElement* pNode = allocateNodeElement();
663  return pNode;
664 }
665 
666 
668 {
669  EdgeElement* pEdge = allocateEdgeElement();
672  return pEdge;
673 }
674 
675 
677 {
678  AdjElement* pAdj = allocateAdjElement();
679  pAdj->m_pNode = pNode;
680  pAdj->m_pEdge = pEdge;
681 
684  return pAdj;
685 }
686 
687 
689 {
692  freeAdjElement( pAdj );
693 }
694 
695 
697 {
699  {
701  it.valid(); it++)
702  {
703  if ((*it)->theNode() == pNode) return *it;
704  }
705  } else
706  {
708  it.valid(); it++)
709  {
710  if ((*it)->theEdge() == pEdge) return *it;
711  }
712  }
713  return 0;
714 }
715 
716 
718 {
720  {
721  AdjElement* pAdj = *it;
723  it = HyperGraphTypes::EdgeAdjList::remove( pEdge, it );
724  freeAdjElement( pAdj );
725  }
726  HyperGraphTypes::EdgeList::remove( this, pEdge );
727  freeEdgeElement( pEdge );
728 }
729 
730 
732 {
734  {
735  AdjElement* pAdj = *it;
737  it = HyperGraphTypes::NodeAdjList::remove( pNode, it );
738  freeAdjElement( pAdj );
739  }
740  HyperGraphTypes::NodeList::remove( this, pNode );
741  freeNodeElement( pNode );
742 }
743 
744 
745 inline int HyperGraph::numberOfNodes() const { return HyperGraphTypes::NodeList::size(this); }
746 
747 inline int HyperGraph::numberOfEdges() const { return HyperGraphTypes::EdgeList::size(this); }
748 
749 
750 inline void HyperGraph::clear()
751 {
752  while (numberOfNodes())
753  {
754  delNode( HyperGraphTypes::NodeList::front(this) );
755  }
756 
757  while (numberOfEdges())
758  {
759  delEdge( HyperGraphTypes::EdgeList::front(this) );
760  }
761 }
762 
763 
764 
765 template<typename ListType, typename ArrayType>
766 static void writeToStream(std::ostream& outStream, ArrayType& array)
767 {
768  for (typename ListType::iterator it = ListType::begin(array.graph()); it.valid(); it++)
769  {
770  outStream << array[*it] << std::endl;
771  }
772 }
773 
774 
775 template<typename ListType, typename ArrayType>
776 static void readFromStream(std::istream& inStream, ArrayType& array)
777 {
778  for (typename ListType::iterator it = ListType::begin(array.graph());it.valid(); it++)
779  {
780  inStream >> array[*it];
781  }
782 }
783 
784 template<typename T>
785 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::NodeArray<T>& array)
786 {
787  writeToStream<HyperGraphTypes::NodeList, HyperGraph::NodeArray<T> >(outStream, array);
788  return outStream;
789 }
790 
791 template<typename T>
792 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::EdgeArray<T>& array)
793 {
794  writeToStream<HyperGraphTypes::EdgeList, HyperGraph::EdgeArray<T> >(outStream, array);
795  return outStream;
796 }
797 
798 template<typename T>
799 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::AdjArray<T>& array)
800 {
802  {
803  HyperGraph::edge e = *it;
805  {
806  outStream << array[*adj_it] << std::endl;
807  }
808  }
809  return outStream;
810 }
811 
812 
813 template<typename T>
814 static std::istream& operator>>(std::istream& inStream, HyperGraph::NodeArray<T>& array)
815 {
816  readFromStream<HyperGraphTypes::NodeList, HyperGraph::NodeArray<T> >(inStream, array);
817  return inStream;
818 }
819 
820 
821 template<typename T>
822 static std::istream& operator>>(std::istream& inStream, HyperGraph::EdgeArray<T>& array)
823 {
824  readFromStream<HyperGraphTypes::EdgeList, HyperGraph::EdgeArray<T> >(inStream, array);
825  return inStream;
826 }
827 
828 
829 template<typename T>
830 static std::istream& operator>>(std::istream& inStream, HyperGraph::AdjArray<T>& array)
831 {
833  {
834  HyperGraph::edge e = *it;
836  {
837  inStream >> array[*adj_it];
838  }
839  }
840  return inStream;
841 }
842 
843 
844 static std::ostream& operator<<(std::ostream& outStream, HyperGraph& graph)
845 {
846  outStream << graph.numberOfNodes() << std::endl;
847  outStream << graph.numberOfEdges() << std::endl;
848 
849  HyperGraph::NodeArray<int> packed_index(&graph);
850 
851  int i=0;
853  {
854  packed_index[*it] = i++;
855  }
856 
858  {
859  HyperGraph::edge e = *it;
860  outStream << e->cardinality() << std::endl;
862  {
863  outStream << packed_index[(*adj_it)->theNode()] << std::endl;
864  }
865  }
866  return outStream;
867 }
868 
869 
870 static std::istream& operator>>(std::istream& inStream, HyperGraph& graph)
871 {
872  int numNodes;
873  int numEdges;
874  inStream >> numNodes;
875  inStream >> numEdges;
876 
877  std::vector<HyperGraph::node> pNodes(numNodes);
878  for (int i=0; i<numNodes;i++)
879  pNodes[i] = graph.newNode();
880 
881  for (int i=0; i<numEdges;i++)
882  {
883  HyperGraph::edge e = graph.newEdge();
884  int numAdj;
885  inStream >> numAdj;
886  for (int j=0; j<numAdj; j++)
887  {
888  int packedNodeIndex;
889  inStream >> packedNodeIndex;
890  graph.addNode(pNodes[packedNodeIndex], e);
891  }
892  }
893  return inStream;
894 }
895 
896 } // end of namespace ogdf
ArrayController< EdgeElement > m_edgeArrayController
controller for edge arrays
Definition: HyperGraph.h:308
T & operator[](const E *e)
Returns a reference to the entry for an indexed element.
Definition: HyperGraph.h:214
Declaration and implementation of a simple freelist and an index pool which generates unique indices ...
More complex implementation of a FreeList, which is able to generate indeices for the elements...
Definition: EFreeList.h:40
int size() const
Definition: EList.h:457
AdjArray(HyperGraph *pGraph, const T &initValue)
Definition: HyperGraph.h:388
Declaration of class GraphAttributes which extends a Graph by additional attributes.
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:56
EdgeElement * allocateEdgeElement()
Allocates a new EdgeElement using the EFreeListIndexPool and lets the controller check if arrays have...
Definition: HyperGraph.h:329
The embedded list template.
Definition: EList.h:93
void delEdge(EdgeElement *pEdge)
Deletes hyper edge pEdge.
Definition: HyperGraph.h:717
int m_numArrays
Number of attached arrays.
Definition: HyperGraph.h:286
void numUsedIndicesChanged(int numUsedIndices)
called by the hyper graph when the amount of used entries has changed.
Definition: HyperGraph.h:632
int index() const
Returns the index of this node.
Definition: HyperGraph.h:55
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
Representation of hyper edges.
Definition: HyperGraph.h:71
static void readFromStream(std::istream &inStream, ArrayType &array)
Definition: HyperGraph.h:776
static std::istream & operator>>(std::istream &inStream, HyperGraph::NodeArray< T > &array)
Definition: HyperGraph.h:814
void freeAdjElement(AdjElement *pAdj)
Frees a used AdjElement.
Definition: HyperGraph.h:357
NodeElement * theNode()
Returns the node whose adjacency list contains this adjacency entry.
Definition: HyperGraph.h:101
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
NodeElement * m_pFirstNode
Definition: HyperGraph.h:134
Type declarations for HyperGraph.
Definition: HyperGraph.h:559
void delNode(NodeElement *pNode)
Deletes node pNode.
Definition: HyperGraph.h:731
EdgeElement * theEdge()
Returns the hyper edge associated with this adjacency entry.
Definition: HyperGraph.h:104
ArrayController< AdjElement > m_adjArrayController
controller for adj arrays
Definition: HyperGraph.h:309
AdjElement * newAdjElement(NodeElement *pNode, EdgeElement *pEdge)
Creates a new AdjElement which makes pNode and pEdge incident.
Definition: HyperGraph.h:676
int index() const
Returns the index of this edge.
Definition: HyperGraph.h:77
void delAdjElement(NodeElement *pNode, EdgeElement *pEdge)
Removes the endpoint pNode from the hyper edge pEdge.
Definition: HyperGraph.h:424
void registerArray(GraphArrayBase< AdjElement > *pArray)
Definition: HyperGraph.h:313
void freeEdgeElement(EdgeElement *pEdge)
Frees a used EdgeElement.
Definition: HyperGraph.h:351
HyperGraph()
Creates an empty hyper graph.
Definition: HyperGraph.h:651
NodeArray(HyperGraph *pGraph, const T &initValue)
Definition: HyperGraph.h:370
NodeElement * allocateNodeElement()
Allocates a new NodeElement using the EFreeListIndexPool and lets the controller check if arrays have...
Definition: HyperGraph.h:321
T m_initialValue
The initial value for unset entries.
Definition: HyperGraph.h:238
AdjArray(HyperGraph *pGraph)
Definition: HyperGraph.h:387
GraphArray(HyperGraph *pGraph)
Creates a graph array attached to pGraph.
Definition: HyperGraph.h:184
Representation of adjacency elements.
Definition: HyperGraph.h:93
void init()
Definition: EList.h:455
static iterator pushBack(L *pList, E *elem)
Appends the element elem to the end of pList.
Definition: EList.h:258
Declaration and implementation of embedded stack and list functionality which is useful for embedded ...
ArrayController()
Creates a new array controller where the actual table size is zero.
Definition: HyperGraph.h:252
ArrayController< NodeElement > m_nodeArrayController
controller for node arrays
Definition: HyperGraph.h:307
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
void freeNodeElement(NodeElement *pNode)
Frees a used NodeElement.
Definition: HyperGraph.h:345
void registerArray(GraphArrayBase< ElementType > *pArray)
Registers a new graph array and sets the size to m_tableSize.
Definition: HyperGraph.h:615
void registerArray(GraphArrayBase< EdgeElement > *pArray)
Definition: HyperGraph.h:312
Dynamic arrays indexed with hyper edges.
Definition: HyperGraph.h:375
static void remove(V &ts, const T &t)
Definition: Alg.h:36
E * alloc()
Allocates a new Element by either using the free list or allocating a new one with a brand new index...
Definition: EFreeList.h:112
AdjElement(NodeElement *pNode, EdgeElement *pEdge)
Definition: HyperGraph.h:110
void unregisterArray(GraphArrayBase< ElementType > *pArray)
Unregisters a graph array by removing it from the list.
Definition: HyperGraph.h:624
Representation of node elements.
Definition: HyperGraph.h:49
EFreeListIndexPool< EdgeElement, &EdgeElement::m_pNext, &EdgeElement::m_index > m_edgeAllocator
Definition: HyperGraph.h:153
EdgeArray(HyperGraph *pGraph, const T &initValue)
Definition: HyperGraph.h:379
~ArrayController()
Frees the array controller and unregisters all remaining arrays.
Definition: HyperGraph.h:605
int cardinality() const
Returns the number of incident nodes.
Definition: HyperGraph.h:80
int m_tableSize
Current table size which corresponds to the length of all attached arrays.
Definition: HyperGraph.h:289
void delAdjElement(AdjElement *pAdj)
Removes one endpoint pAdj from a hyper edge.
Definition: HyperGraph.h:688
int degree() const
Returns the number of incident edges.
Definition: HyperGraph.h:58
void unregisterArray(GraphArrayBase< EdgeElement > *pArray)
Definition: HyperGraph.h:317
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
int index() const
Returns the index of this adjacency entry.
Definition: HyperGraph.h:107
GraphArrayBase< E > * m_next
the embedded prev pointer.
Definition: HyperGraph.h:171
void registerArray(GraphArrayBase< NodeElement > *pArray)
Definition: HyperGraph.h:311
virtual ~GraphArray()
Destructor.
Definition: HyperGraph.h:201
int numberOfEdges() const
Definition: HyperGraph.h:747
Class for the representation of nodes.
Definition: Graph_d.h:167
void unregisterArray(GraphArrayBase< NodeElement > *pArray)
Definition: HyperGraph.h:316
NodeArray(HyperGraph *pGraph)
Definition: HyperGraph.h:369
E * front() const
Definition: EList.h:460
static iterator remove(L *pList, E *elem)
Removes elem from pList.
Definition: EList.h:366
Implementation of an embedded list iterator used by ogdf::EList.
Definition: EList.h:91
bool valid() const
returns false if the iterator points at nullptr
Definition: EList.h:156
EFreeListIndexPool< NodeElement, &NodeElement::m_pNext, &NodeElement::m_index > m_nodeAllocator
Definition: HyperGraph.h:147
EdgeElement * m_pFirstEdge
Definition: HyperGraph.h:138
EdgeElement * newEdge()
Creates a new edge which is not incident to any nodes.
Definition: HyperGraph.h:667
int numberOfNodes() const
Definition: HyperGraph.h:745
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
HyperGraph * m_pGraph
The graph the array is attached to.
Definition: HyperGraph.h:235
Array controllers manage the graph arrays of an element.
Definition: HyperGraph.h:247
EFreeListIndexPool< AdjElement, &AdjElement::m_pNext_nodeAdj, &AdjElement::m_index > m_adjAllocator
Definition: HyperGraph.h:159
const T & operator[](const E *e) const
Returns a const reference to the entry for an indexed element.
Definition: HyperGraph.h:208
iterator begin() const
Definition: EList.h:480
AdjElement * allocateAdjElement()
Allocates a new AdjElement using the EFreeListIndexPool and lets the controller check if arrays have ...
Definition: HyperGraph.h:337
EdgeElement * newEdge(NodeElement *pNode1, NodeElement *pNode2)
Creates a new edge which is incident to the two nodes pNode1, pNode2.
Definition: HyperGraph.h:402
EdgeElement * m_pLastEdge
Definition: HyperGraph.h:139
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
Definition: Array.h:140
The namespace for all OGDF objects.
GraphArrayBase< ElementType > * m_first
First array in the chain of attached arrays.
Definition: HyperGraph.h:280
HyperGraph * graph() const
Returns the graph the array is attached to.
Definition: HyperGraph.h:220
NodeElement * newNode()
Creates a new node.
Definition: HyperGraph.h:658
virtual void setSize(int numElements)
Implementation of GraphArrayBase::setSize(int).
Definition: HyperGraph.h:228
node newNode()
Creates a new node and returns it.
virtual void setSize(int numElements)=0
Interface method for resizing a graph array.
GraphArrayBase< ElementType > * m_last
Last array in the chain of attached arrays.
Definition: HyperGraph.h:283
AdjElement * addNode(NodeElement *pNode, EdgeElement *pEdge, bool checkIfAlreadyExists=false)
Makes pNode and pEdge incident; returns the corresponding HyperGraph::AdjElement. ...
Definition: HyperGraph.h:431
GraphArrayBase< E > * m_prev
Definition: HyperGraph.h:170
Dynamic arrays indexed with adjacency entries.
Definition: HyperGraph.h:384
NodeElement * m_pLastNode
Definition: HyperGraph.h:135
int newTableSize(int minSize)
function to calculate the new tableSize; returns min(2^k | 2^k >= minSize)
Definition: HyperGraph.h:267
void clear()
Clears the graph.
Definition: HyperGraph.h:750
GraphArray(HyperGraph *pGraph, const T &initialValue)
Creates a graph array attached to pGraph with default value initialValue.
Definition: HyperGraph.h:193
Dynamic arrays indexed with nodes.
Definition: HyperGraph.h:366
EdgeArray(HyperGraph *pGraph)
Definition: HyperGraph.h:378
void unregisterArray(GraphArrayBase< AdjElement > *pArray)
Definition: HyperGraph.h:318
void removeNode(NodeElement *pNode, EdgeElement *pEdge, bool removeDuplicates=false)
If pNode and pEdge are incident, the corresponding AdjElement is removed.
Definition: HyperGraph.h:449
AdjElement * findAdjElement(NodeElement *pNode, EdgeElement *pEdge) const
Returns the AdjElement for pNode and pEdge.
Definition: HyperGraph.h:696
static void writeToStream(std::ostream &outStream, ArrayType &array)
Definition: HyperGraph.h:766