Ejemplo n.º 1
0
void addSubgraph(Graph* graph, nodeid_t node_id, xid_t* xids, int n_xids)
{
    xid_t *last = xids + n_xids;
    Edge *e, *next, *edges = NULL;
    Node* node = findNode(&cluster, node_id);
    while (xids != last) { 
        Vertex* src = findVertex(graph, *xids++);
        xid_t xid;
        while ((xid = *xids++) != 0) { 
            Vertex* dst = findVertex(graph, xid);
            e = newEdge(graph);
            dst->nIncomingEdges += 1;
            e->dst = dst;
            e->src = src;
            e->next = edges;
            edges = e;
            l2_list_link(&src->outgoingEdges, &e->node);
        }
    }
    for (e = node->edges; e != NULL; e = next) { 
        next = e->next;
        l2_list_unlink(&e->node);
        if (--e->dst->nIncomingEdges == 0 && l2_list_is_empty(&e->dst->outgoingEdges)) {
            freeVertex(graph, e->dst);
        }
        if (e->dst != e->src && e->src->nIncomingEdges == 0 && l2_list_is_empty(&e->src->outgoingEdges)) {
            freeVertex(graph, e->src);
        }
        freeEdge(graph, e);
    }
    node->edges = edges;
}
Ejemplo n.º 2
0
void addEdgeToGraph(Edge* edge, Graph* graph)
{
	int i;
	if (edge==NULL || edge->source==NULL || edge->destination==NULL || graph==NULL) {
		printf("NULL pointer in 'addEdgeToGraph'\n");
		return;
	}
	
	for (i=0 ; i<graph->numOfEdges ; i++)
	{
		// Checking if such edge is already exist in the graph. If do, free this edge and finish.
		if(graph->edges[i]!=NULL && strcmp(edge->source->data, graph->edges[i]->source->data)==0 &&
			strcmp(edge->destination->data, graph->edges[i]->destination->data)==0)
		{
			freeEdge(edge);
			return;
		}
		// If it doesn't exist and there's nothing on that index location, add the edge to the graph.
		else if(graph->edges[i]==NULL) {
			graph->edges[i] = edge;
			return;	
		}
	}	
	
}							
Ejemplo n.º 3
0
void freeGraph(Graph* graph)
{
	int i;
	if (graph==NULL)
		return;
	for (i=0 ; i<graph->numOfVertices ; i++) {
		freeVertex(graph->vertices[i]);
		graph->vertices[i]=NULL;
	}
	for (i=0 ; i<graph->numOfEdges ; i++) {
		freeEdge(graph->edges[i]);
		graph->edges[i]=NULL;
	}
	free(graph->vertices);
	graph->vertices=NULL;
	free(graph->edges);
	graph->edges=NULL;
	free(graph);
	graph=NULL;
}
Ejemplo n.º 4
0
// disconnects e from the rest of the structure and destroys it
void CDelaunay::deleteEdge(EdgePointer e)
{
  splice(e, (EdgePointer) oprev(e));
  splice((EdgePointer) sym(e), (EdgePointer) oprev(sym(e)));
  freeEdge(e);
}