55 int index()
const {
return m_index; }
58 int degree()
const {
return m_numAdj; }
77 int index()
const {
return m_index; }
107 int index()
const {
return m_index; }
145 &NodeElement::m_pNext,
146 &NodeElement::m_index
151 &EdgeElement::m_pNext,
152 &EdgeElement::m_index
157 &AdjElement::m_pNext_nodeAdj,
168 virtual void setSize(
int numElements) = 0;
175 template<
typename T,
typename E>
194 m_initialValue = initialValue;
204 m_pGraph->unregisterArray(
this);
246 template<
typename ElementType>
270 while (res < minSize)
276 void numUsedIndicesChanged(
int numUsedIndices);
293 template<
typename ElementType>
323 NodeElement* pResult = m_nodeAllocator.
alloc();
331 EdgeElement* pResult = m_edgeAllocator.
alloc();
339 AdjElement* pResult = m_adjAllocator.
alloc();
347 m_nodeAllocator.free(pNode);
353 m_edgeAllocator.free(pEdge);
359 m_adjAllocator.free(pAdj);
396 NodeElement* newNode();
399 EdgeElement* newEdge();
402 EdgeElement*
newEdge(NodeElement* pNode1, NodeElement* pNode2)
404 EdgeElement* pEdge = newEdge();
405 newAdjElement( pNode1, pEdge );
406 newAdjElement( pNode2, pEdge );
418 AdjElement* newAdjElement(NodeElement* pNode, EdgeElement* pEdge);
421 void delAdjElement(AdjElement* pAdj);
426 AdjElement* pAdj = findAdjElement(pNode, pEdge);
427 if (pAdj) delAdjElement(pAdj);
431 AdjElement*
addNode(NodeElement* pNode, EdgeElement* pEdge,
bool checkIfAlreadyExists =
false)
433 if (!checkIfAlreadyExists)
434 return newAdjElement( pNode, pEdge );
436 AdjElement* pAdj = findAdjElement(pNode, pEdge);
438 pAdj = newAdjElement( pNode, pEdge );
449 void removeNode(NodeElement* pNode, EdgeElement* pEdge,
bool removeDuplicates =
false)
451 AdjElement* pAdj = findAdjElement(pNode, pEdge);
452 if (!removeDuplicates && pAdj)
460 pAdj = findAdjElement(pNode, pEdge);
472 AdjElement* findAdjElement(NodeElement* pNode, EdgeElement* pEdge)
const;
475 void delEdge(EdgeElement* pEdge);
478 void delNode(NodeElement* pNode);
480 int numberOfNodes()
const;
481 int numberOfEdges()
const;
493 for (NodeList::iterator it = HyperGraph::NodeList::begin(
this); it.valid(); it++)
497 hgNode_to_gNode[ hgNode ] = gNode;
499 (*pNodeMap)[gNode] = hgNode;
502 for (HyperGraph::EdgeList::iterator it = HyperGraph::EdgeList::begin(
this); it.valid(); it++)
504 EdgeElement* hgEdge = *it;
505 for (HyperGraph::EdgeAdjList::iterator adj_it = HyperGraph::EdgeAdjList::begin(hgEdge); adj_it.valid(); adj_it++)
507 for (HyperGraph::EdgeAdjList::iterator adj_it2 = adj_it.succ(); adj_it2.valid(); adj_it2++)
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 ];
516 (*pEdgeMap)[gEdge] = hgEdge;
528 for (NodeList::iterator it = HyperGraph::NodeList::begin(
this); it.valid(); it++)
530 NodeElement* hgNode = *it;
532 hgNode_to_gNode[ hgNode ] = gNode;
534 (*pNodeMap)[gNode] = hgNode;
537 for (HyperGraph::EdgeList::iterator it = HyperGraph::EdgeList::begin(
this); it.valid(); it++)
539 EdgeElement* hgEdge = *it;
542 (*pNodeMap)[gNodeDummy] = 0;
544 for (HyperGraph::EdgeAdjList::iterator adj_it = HyperGraph::EdgeAdjList::begin(hgEdge); adj_it.valid(); adj_it++)
546 NodeElement* hgNode = (*adj_it)->theNode();
547 node gNode = hgNode_to_gNode[ hgNode ];
550 (*pEdgeMap)[gEdge] = hgEdge;
594 HyperGraph::EdgeElement, HyperGraph::AdjElement,
604 template<
typename ElementType>
614 template<
typename ElementType>
623 template<
typename ElementType>
631 template<
typename ElementType>
635 if (numUsedIndices > m_tableSize)
639 m_tableSize = newTableSize(numUsedIndices);
645 (*it)->setSize(m_tableSize);
692 freeAdjElement( pAdj );
703 if ((*it)->theNode() == pNode)
return *it;
710 if ((*it)->theEdge() == pEdge)
return *it;
724 freeAdjElement( pAdj );
727 freeEdgeElement( pEdge );
738 freeAdjElement( pAdj );
741 freeNodeElement( pNode );
752 while (numberOfNodes())
757 while (numberOfEdges())
765 template<
typename ListType,
typename ArrayType>
768 for (
typename ListType::iterator it = ListType::begin(array.graph()); it.valid(); it++)
770 outStream << array[*it] << std::endl;
775 template<
typename ListType,
typename ArrayType>
778 for (
typename ListType::iterator it = ListType::begin(array.graph());it.valid(); it++)
780 inStream >> array[*it];
785 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::NodeArray<T>& array)
787 writeToStream<HyperGraphTypes::NodeList, HyperGraph::NodeArray<T> >(outStream, array);
792 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::EdgeArray<T>& array)
794 writeToStream<HyperGraphTypes::EdgeList, HyperGraph::EdgeArray<T> >(outStream, array);
799 static std::ostream& operator<<(std::ostream& outStream, HyperGraph::AdjArray<T>& array)
806 outStream << array[*adj_it] << std::endl;
816 readFromStream<HyperGraphTypes::NodeList, HyperGraph::NodeArray<T> >(inStream, array);
824 readFromStream<HyperGraphTypes::EdgeList, HyperGraph::EdgeArray<T> >(inStream, array);
837 inStream >> array[*adj_it];
854 packed_index[*it] = i++;
863 outStream << packed_index[(*adj_it)->theNode()] << std::endl;
874 inStream >> numNodes;
875 inStream >> numEdges;
877 std::vector<HyperGraph::node> pNodes(numNodes);
878 for (
int i=0; i<numNodes;i++)
881 for (
int i=0; i<numEdges;i++)
886 for (
int j=0; j<numAdj; j++)
889 inStream >> packedNodeIndex;
890 graph.
addNode(pNodes[packedNodeIndex], e);
ArrayController< EdgeElement > m_edgeArrayController
controller for edge arrays
T & operator[](const E *e)
Returns a reference to the entry for an indexed element.
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...
AdjArray(HyperGraph *pGraph, const T &initValue)
Declaration of class GraphAttributes which extends a Graph by additional attributes.
The parameterized class Array implements dynamic arrays of type E.
EdgeElement * allocateEdgeElement()
Allocates a new EdgeElement using the EFreeListIndexPool and lets the controller check if arrays have...
The embedded list template.
void delEdge(EdgeElement *pEdge)
Deletes hyper edge pEdge.
int m_numArrays
Number of attached arrays.
void numUsedIndicesChanged(int numUsedIndices)
called by the hyper graph when the amount of used entries has changed.
int index() const
Returns the index of this node.
Data type for general directed graphs (adjacency list representation).
Representation of hyper edges.
static void readFromStream(std::istream &inStream, ArrayType &array)
static std::istream & operator>>(std::istream &inStream, HyperGraph::NodeArray< T > &array)
void freeAdjElement(AdjElement *pAdj)
Frees a used AdjElement.
NodeElement * theNode()
Returns the node whose adjacency list contains this adjacency entry.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
NodeElement * m_pFirstNode
Type declarations for HyperGraph.
void delNode(NodeElement *pNode)
Deletes node pNode.
EdgeElement * theEdge()
Returns the hyper edge associated with this adjacency entry.
ArrayController< AdjElement > m_adjArrayController
controller for adj arrays
AdjElement * newAdjElement(NodeElement *pNode, EdgeElement *pEdge)
Creates a new AdjElement which makes pNode and pEdge incident.
int index() const
Returns the index of this edge.
void delAdjElement(NodeElement *pNode, EdgeElement *pEdge)
Removes the endpoint pNode from the hyper edge pEdge.
void registerArray(GraphArrayBase< AdjElement > *pArray)
void freeEdgeElement(EdgeElement *pEdge)
Frees a used EdgeElement.
HyperGraph()
Creates an empty hyper graph.
NodeArray(HyperGraph *pGraph, const T &initValue)
NodeElement * allocateNodeElement()
Allocates a new NodeElement using the EFreeListIndexPool and lets the controller check if arrays have...
T m_initialValue
The initial value for unset entries.
AdjArray(HyperGraph *pGraph)
GraphArray(HyperGraph *pGraph)
Creates a graph array attached to pGraph.
Representation of adjacency elements.
static iterator pushBack(L *pList, E *elem)
Appends the element elem to the end of pList.
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.
ArrayController< NodeElement > m_nodeArrayController
controller for node arrays
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
void freeNodeElement(NodeElement *pNode)
Frees a used NodeElement.
void registerArray(GraphArrayBase< ElementType > *pArray)
Registers a new graph array and sets the size to m_tableSize.
void registerArray(GraphArrayBase< EdgeElement > *pArray)
Dynamic arrays indexed with hyper edges.
static void remove(V &ts, const T &t)
E * alloc()
Allocates a new Element by either using the free list or allocating a new one with a brand new index...
AdjElement(NodeElement *pNode, EdgeElement *pEdge)
void unregisterArray(GraphArrayBase< ElementType > *pArray)
Unregisters a graph array by removing it from the list.
Representation of node elements.
EFreeListIndexPool< EdgeElement, &EdgeElement::m_pNext, &EdgeElement::m_index > m_edgeAllocator
EdgeArray(HyperGraph *pGraph, const T &initValue)
~ArrayController()
Frees the array controller and unregisters all remaining arrays.
int cardinality() const
Returns the number of incident nodes.
int m_tableSize
Current table size which corresponds to the length of all attached arrays.
void delAdjElement(AdjElement *pAdj)
Removes one endpoint pAdj from a hyper edge.
int degree() const
Returns the number of incident edges.
void unregisterArray(GraphArrayBase< EdgeElement > *pArray)
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.
GraphArrayBase< E > * m_next
the embedded prev pointer.
void registerArray(GraphArrayBase< NodeElement > *pArray)
virtual ~GraphArray()
Destructor.
int numberOfEdges() const
Class for the representation of nodes.
void unregisterArray(GraphArrayBase< NodeElement > *pArray)
NodeArray(HyperGraph *pGraph)
static iterator remove(L *pList, E *elem)
Removes elem from pList.
Implementation of an embedded list iterator used by ogdf::EList.
bool valid() const
returns false if the iterator points at nullptr
EFreeListIndexPool< NodeElement, &NodeElement::m_pNext, &NodeElement::m_index > m_nodeAllocator
EdgeElement * m_pFirstEdge
EdgeElement * newEdge()
Creates a new edge which is not incident to any nodes.
int numberOfNodes() const
void resize(INDEX newSize, const E &x)
Resizes (enlarges or shrinks) the array to hold newSize elements and sets new elements to x...
HyperGraph * m_pGraph
The graph the array is attached to.
Array controllers manage the graph arrays of an element.
EFreeListIndexPool< AdjElement, &AdjElement::m_pNext_nodeAdj, &AdjElement::m_index > m_adjAllocator
const T & operator[](const E *e) const
Returns a const reference to the entry for an indexed element.
AdjElement * allocateAdjElement()
Allocates a new AdjElement using the EFreeListIndexPool and lets the controller check if arrays have ...
EdgeElement * newEdge(NodeElement *pNode1, NodeElement *pNode2)
Creates a new edge which is incident to the two nodes pNode1, pNode2.
EdgeElement * m_pLastEdge
AdjElement * m_pPrev_nodeAdj
AdjElement * m_pPrev_edgeAdj
AdjElement * m_pNext_nodeAdj
const_reference operator[](INDEX i) const
Returns a reference to the element at position i.
The namespace for all OGDF objects.
GraphArrayBase< ElementType > * m_first
First array in the chain of attached arrays.
HyperGraph * graph() const
Returns the graph the array is attached to.
NodeElement * newNode()
Creates a new node.
virtual void setSize(int numElements)
Implementation of GraphArrayBase::setSize(int).
node newNode()
Creates a new node and returns it.
AdjElement * m_pNext_edgeAdj
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.
AdjElement * addNode(NodeElement *pNode, EdgeElement *pEdge, bool checkIfAlreadyExists=false)
Makes pNode and pEdge incident; returns the corresponding HyperGraph::AdjElement. ...
GraphArrayBase< E > * m_prev
Dynamic arrays indexed with adjacency entries.
NodeElement * m_pLastNode
int newTableSize(int minSize)
function to calculate the new tableSize; returns min(2^k | 2^k >= minSize)
void clear()
Clears the graph.
GraphArray(HyperGraph *pGraph, const T &initialValue)
Creates a graph array attached to pGraph with default value initialValue.
Dynamic arrays indexed with nodes.
EdgeArray(HyperGraph *pGraph)
void unregisterArray(GraphArrayBase< AdjElement > *pArray)
void removeNode(NodeElement *pNode, EdgeElement *pEdge, bool removeDuplicates=false)
If pNode and pEdge are incident, the corresponding AdjElement is removed.
AdjElement * findAdjElement(NodeElement *pNode, EdgeElement *pEdge) const
Returns the AdjElement for pNode and pEdge.
static void writeToStream(std::ostream &outStream, ArrayType &array)