GEdge *GNode< Point >::Search( Long n, Long i ) const { GEdge *p; for (p=adjacents; p != NULL; p=p->Next()) if (( p->Item() == i) && (p->Node() == n)) break; return p; }
GEdge * Graph::getEdge(long firstNode, long secondNode){ GEdge *p = tnode[firstNode]->getIncidentEdges(); while(p){ if (p->IncidentNode() == secondNode) return p; else p=p->Next(); } return NULL; }
GEdge *GNode< Point >::Del( Long n, Long i ) { GEdge *p = Neighbours(); GEdge *q; if (!p) return NULL; if ((p->Node()==n)&&(p->Item()==i)) { q=p->Next(); etrash.push_back(p); // delete(p); // Problem when using Neighbours() list: cannot delete adjacents=q; } else { for (q=p->Next();q != NULL; p=q,q=q->Next()) if (q && (q->Node() ==n) && (q->Item() == i)) { p->Next(q->Next()); etrash.push_back(q); break; // delete(q); // Problem when using Neighbours() list: cannot delete } } return adjacents; }
/* * Removes the node `n' in graph. * -> Removes all refences in its * neighbourhood nodes. */ Errc Graph3d::Del( Long n ) { GEdge *p; if (!tnode[n]) return FAILURE; for (p=tnode[n]->Neighbours(); p!=NULL;p=p->Next()){ tnode[p->Node()]->Del(n); } delete tnode[n]; tnode[n]=NULL; return SUCCESS; }
GEdge *GNode< Point >::Del( Long n ) { GEdge *p = Neighbours(); GEdge *q; if (!p) return NULL; while (p && ( p->Node() == n )) { etrash.push_back(p); p = p->Next(); adjacents = p; } for ( q=p; q != NULL ; q=q->Next() ) { if ( q->Node() == n ) { p->Next(q->Next()); etrash.push_back(q); // delete(q); // Problem when using Neighbours() list: cannot delete } else p=q; } return adjacents; }
/* * Merges 2 nodes in 1 ->n1 * Updates the adjacent list of all node (n2 ->n1). * and delete n2. */ Errc Graph2d::Merge( Long n1, Long n2 ) { GEdge *ptr; if (_directed) { // std::cerr << "Error: Merge is not implemented for directed graphs." << std::endl; // return FAILURE; if ((n1==n2) || (!tnode[n1]) || (!tnode[n2])) return FAILURE; // Remove links Unlink(n1,n2); Unlink(n2,n1); while((ptr=tnode[n2]->Neighbours())){ if ( n2 != ptr->Node() ) Link(n1,ptr->Node(),ptr->Item(),ptr->weight,true); else Link(n1,n1,ptr->Item(),ptr->weight,true); Unlink(n2,ptr->Node(),ptr->Item()); } // Cross the graph in order to replace n2 by n1 for ( int i = 0; i < this->Size(); ++i ) { const GNode<Point2d> * noeud = (*this)[i]; if ( noeud != NULL ) { for ( ptr = noeud->Neighbours() ; ptr != NULL; ptr = ptr->Next() ) if ( ptr->Node() == n2 ) { Link(i,n1,ptr->Item(),ptr->weight,true); Unlink(i,n2,ptr->Item()); } } } Del(n2); } else { if ((n1==n2) || (!tnode[n1]) || (!tnode[n2])) return FAILURE; Unlink(n1,n2); while((ptr=tnode[n2]->Neighbours())){ if ( n2 != ptr->Node() ) Link(n1,ptr->Node(),ptr->Item(),ptr->weight,true); else Link(n1,n1,ptr->Item(),ptr->weight,true); Unlink(n2,ptr->Node(),ptr->Item()); } Del(n2); } return SUCCESS; }
/* * Creates a copy of graph g. */ Graph3d &Graph3d::operator=( const Graph3d &g ) { Long i; GEdge *l; New(g.size,g.ndep,g.nrow,g.ncol); for (i=0; i<size; i++){ if (g[i] != NULL){ Add(i,g[i]->Item(),g[i]->seed); tnode[i]->value=g[i]->value; for (l=g[i]->Neighbours(); l!=NULL; l=l->Next()){ if (i>l->Node()) Link(i,l->Node(),l->Item(),l->weight); } } } return *this; }
GEdge *GNode::UnConnect( long incidentNode ) { GEdge *p = getIncidentEdges(); GEdge *q; if (!p) return NULL; if(p->IncidentNode() == incidentNode){ adjacents = p->Next(); delete p; } return adjacents; while (p->Next()) { if(p->Next()->IncidentNode() == incidentNode){ q = p->Next(); p->Next(q->Next()); delete q; }else p = p->Next(); } return adjacents; }
GEdge *GNode< Point >::Search( Long n ) const { GEdge *p; for (p=adjacents; p && (p->Node()!=n); p=p->Next()) ; return p; }