38#include <ogdf/basic/internal/config_autogen.h>
50template<
class T,
class =
void>
54struct is_iterator<T,
std::void_t<typename std::iterator_traits<T>::iterator_category>>
57template<
typename Iterator>
58typename std::enable_if<!is_iterator<Iterator>::value,
size_t>::type
guess_dist(Iterator, Iterator) {
62template<
typename Iterator>
63typename std::enable_if<is_iterator<Iterator>::value,
64 typename std::iterator_traits<Iterator>::difference_type>::type
66 if constexpr (std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
67 std::random_access_iterator_tag>::value) {
75template<OGDF_NODE_ITER NI,
bool notifyObservers,
bool copyIDs>
77 int& newNodes,
void* cbData) {
79 if (guessedNodes > 0 && notifyObservers) {
83 for (
auto it = nodesBegin; it != nodesEnd; ++it) {
91 if (notifyObservers) {
101template<OGDF_NODE_ITER NI, OGDF_EDGE_ITER EI,
bool copyEmbedding,
bool copyIDs,
bool notifyObservers>
102std::pair<int, int>
Graph::insert(
const NI& nodesBegin,
const NI& nodesEnd,
const EI& edgesBegin,
107 int newNodes = 0, newEdges = 0;
109 &newNodes, &newEdges);
110 if (nodesBegin == nodesEnd) {
112 return {newNodes, newEdges};
114 insertNodes<NI, notifyObservers, copyIDs>(nodesBegin, nodesEnd, nodeMap, newNodes, cbData);
116 if (edgesBegin == edgesEnd) {
118 return {newNodes, newEdges};
123 if (guessedEdges > 0) {
129 for (
auto it = edgesBegin; it != edgesEnd; ++it) {
133 if (src ==
nullptr || tgt ==
nullptr) {
145 if (notifyObservers) {
158#ifdef OGDF_HEAVY_DEBUG
162 return {newNodes, newEdges};
165 for (
auto it = nodesBegin; it != nodesEnd; ++it) {
167 node v = nodeMap[vG];
169 edge eG = adjG->theEdge();
170 edge e = edgeMap[eG];
178 if (adj->
succ() !=
nullptr || adj->
pred() !=
nullptr || v->
adjEntries.head() == adj) {
186 if (notifyObservers) {
190 for (
auto it = edgesBegin; it != edgesEnd; ++it) {
192 edge e = edgeMap[eG];
193 if (nodeMap[eG->
source()] ==
nullptr || nodeMap[eG->
target()] ==
nullptr) {
207#ifdef OGDF_HEAVY_DEBUG
212 return {newNodes, newEdges};
215template<OGDF_NODE_ITER NI, OGDF_EDGE_FILTER EF,
bool copyIDs,
bool notifyObservers>
216std::pair<int, int>
Graph::insert(
const NI& nodesBegin,
const NI& nodesEnd,
const EF& edgeFilter,
221 int newNodes = 0, newEdges = 0;
223 preInsert(
true, copyIDs, notifyObservers,
true, nodeMap, edgeMap, &newNodes, &newEdges);
224 if (nodesBegin == nodesEnd) {
226 return {newNodes, newEdges};
228 insertNodes<NI, notifyObservers, copyIDs>(nodesBegin, nodesEnd, nodeMap, newNodes, cbData);
230 for (
auto it = nodesBegin; it != nodesEnd; ++it) {
232 node v = nodeMap[vG];
234 edge eG = adjG->theEdge();
235 if (!edgeFilter(eG)) {
239 edge e = edgeMap[eG];
242 node twin = nodeMap[adjG->twinNode()];
243 if (twin ==
nullptr) {
251 if (adjG->isSource()) {
265 if (adj->
succ() ==
nullptr && adj->
pred() ==
nullptr && v->
adjEntries.head() != adj) {
274 if (notifyObservers) {
278 for (
auto it = nodesBegin; it != nodesEnd; ++it) {
281 if (!adjG->isSource()) {
284 edge eG = adjG->theEdge();
285 edge e = edgeMap[eG];
301#ifdef OGDF_HEAVY_DEBUG
306 return {newNodes, newEdges};
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
adjEntry pred() const
Returns the predecessor in the adjacency list.
adjEntry succ() const
Returns the successor in the adjacency list.
bool isSource() const
Returns true iff this is the source adjacency entry of the corresponding edge.
Class for the representation of edges.
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
int index() const
Returns the index of the edge.
AdjElement * m_adjSrc
Corresponding adjacency entry at source node.
AdjElement * m_adjTgt
Corresponding adjacency entry at target node.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
node target() const
Returns the target node of the edge.
node source() const
Returns the source node of the edge.
internal::GraphEdgeRegistry m_regEdgeArrays
The registered edge arrays.
internal::GraphAdjRegistry m_regAdjArrays
The registered adjEntry arrays.
int m_edgeIdCount
The Index that will be assigned to the next created edge.
int m_nodeIdCount
The Index that will be assigned to the next created node.
virtual void postInsert(void *userData, int newNodes, int newEdges)
Callback notifying subclasses that an insert() call has finished.
virtual void nodeInserted(void *userData, node original, node copy)
Callback notifying subclasses that insert() copied a node.
void consistencyCheck() const
Asserts that this graph is consistent.
void insertNodes(const NI &nodesBegin, const NI &nodesEnd, NodeArray< node, true > &nodeMap, int &newNodes, void *cbData)
internal::GraphNodeRegistry m_regNodeArrays
The registered node arrays.
edge pureNewEdge(node src, node tgt, int index)
Creates a new edge object with id index and corresponding AdjElements and adds it to the list of edge...
node pureNewNode(int index)
Creates a new node object with id index and adds it to the list of nodes.
virtual void edgeInserted(void *userData, edge original, edge copy)
Callback notifying subclasses that insert() copied an edge.
std::pair< int, int > insert(const NI &nodesBegin, const NI &nodesEnd, const EI &edgesBegin, const EI &edgesEnd, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap)
Inserts a copy of a given subgraph into this graph.
virtual void * preInsert(bool copyEmbedding, bool copyIDs, bool notifyObservers, bool edgeFilter, NodeArray< node > &nodeMap, EdgeArray< edge > &edgeMap, int *newNodes, int *newEdges)
Callback notifying subclasses that some graph is about to be insert() -ed.
Abstract Base class for graph observers.
Class for the representation of nodes.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
int index() const
Returns the (unique) node index.
const ListPure< GraphObserver * > & getObservers() const
void keyAdded(Key key)
Records the addition of a new key and resizes all registered arrays if necessary.
void reserveSpace(int new_keys)
Resizes all arrays to make space of new_keys new keys.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
RegisteredArray for nodes, edges and adjEntries of a graph.
Graph * graphOf() const
Returns a pointer to the associated graph.
Decralation of graph iterators.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
std::enable_if<!is_iterator< Iterator >::value, size_t >::type guess_dist(Iterator, Iterator)
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
void copyEmbedding(const Graph &from, Graph &to, std::function< adjEntry(adjEntry)> adjMapFromTo)
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)