Exemplo 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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
void MeshBuilder::clear()
{
	removeVertexMaps();
	removeDiscontinuousVertexMaps();

	for ( int index = polygons()-1 ; index >= 0 ; --index )
	{
		Polygon* item = getPolygon( index );
		item->destroy();
		freePolygon( item );
	}
	m_this->polygons.clear();

	for ( int index = vertices()-1 ; index >= 0 ; --index )
	{
		Vertex* item = getVertex( index );
		item->destroy();
		freeVertex( item );
	}
	m_this->vertices.clear();
}
Exemplo n.º 4
0
Vertex* createVertex(char* data)
{
	Vertex* newVertex;

	if (data==NULL)
		return NULL;
		
	newVertex = (Vertex*)malloc(sizeof(Vertex));
	if (newVertex==NULL)
		return NULL;

	newVertex->data = (char*)malloc(sizeof(data));
	if (newVertex->data == NULL) {
		freeVertex(newVertex);
		return NULL;
	}
	strcpy(newVertex->data, data);
	newVertex->distance = INFINITI;
	newVertex->pie = NULL;
	return newVertex;
} 
Exemplo n.º 5
0
void MeshBuilder::removeVertex( int index )
{
	assert( 0 == getVertex(index)->polygons() ); // no polygon can use the vertex

	Vertex* item = getVertex(index);
	item->destroy();
	m_this->vertices.remove( index );
	freeVertex( item );

	// update vertex indices
	int i;
	for ( i = index ; i < (int)m_this->vertices.size() ; ++i )
		m_this->vertices[i]->m_index = i;

	// update discontinuous vertex map indices
	for ( i = 0 ; i < discontinuousVertexMaps() ; ++i )
		getDiscontinuousVertexMap(i)->vertexRemoved( index );

	// update discontinuous vertex map indices
	for ( i = 0 ; i < vertexMaps() ; ++i )
		getVertexMap(i)->vertexRemoved( index );
}
Exemplo n.º 6
0
Vertex* addVertexToGraph(Vertex* vertex, Graph* graph)
{
	int i=0;
	if (vertex==NULL || graph==NULL) {
		printf("Error - NULL pointer in 'addVertexToGraph'\n");
		return NULL;
	}

	for (i=0 ; i<graph->numOfVertices ; i++)
	{
		// If nothing exists on this list index, add it.
		if (graph->vertices[i] == NULL) {
			graph->vertices[i] = vertex;
			return vertex;
		}
		// If the given vertex is already exist, it free the given one, and return the already existing one.
		if (graph->vertices[i] != NULL && strcmp(vertex->data, graph->vertices[i]->data)==0) {
			freeVertex(vertex);		
			vertex=NULL;
			return graph->vertices[i];	
		}
	}
	return NULL;	// If it got here there have been some kind of fault or error so it returns NULL.
}