Site hosted by Angelfire.com: Build your free website today!
YACLib - Yet Another C Library
(c) 2002 - Pedro Flynn <pflynn@microsoftsucks.org>

Graph


typedef enum _VertexColor {white, black} VertexColor;

typedef struct _Vertex {
    void* data;
    LList* edges;
    VertexColor color;
    struct _Vertex* root;
    double d;   
}Vertex;

typedef struct _Edge {
    double weight;
    Vertex* to;
} Edge;

typedef struct _Graph {
    int vcount;
    int ecount;
    LList* vertexes;
    destroyfunc* destroy;
    comparefunc* cmp;
} Graph;


    The Graph data structure represents a graph, based on the adjacency list representation.


Related functions and macros



Graph* graph_create(destroyfunc* destroy, comparefunc* cmp)

description: creates a new, empty graph. The destroy parameter is a pointer to a user-defined destroyfunc. This function will be called by graph_destroy to free dynamically allocated data. If the data to be inserted in the graph should not be freed, destroy should be set to NULL. The cmp parameter is a valid pointer to a user-defined comparefunc. This function'll be used by the Graph data structure to compare the data stored on each vertex.

return value: a pointer to a new Graph data structure, or NULL if the allocation fails.

since: YACLib 1.0

int graph_insert_vertex(Graph* graph, const void* data)

description: inserts a vertex into the graph specified by graph. The new vertex stores a pointer to data.

return value:
0 if the vertex could be inserted, -1 otherwise.

since:
YACLib 1.0

int graph_remove_vertex(Graph* graph, const void* data, void** dataptr)

description: removes a vertex matching data from the graph specified by graph. Upon return, dataptr points to the data stored in the vertex that was removed.

return value:
0 if the vertex could be removed, -1 otherwise.

since:
YACLib 1.0

int graph_insert_directed_edge(Graph* graph, const void* data1, const void* data2, double weight)

description: inserts a directed edge of weight weight in the graph specified by graph, from the vertex matching data1 to the vertex matching data2.

returns:
0 if the edge could be inserted, -1 otherwise.

since: YACLib 1.0

int graph_insert_undirected_edge(Graph* graph, const void* data1, const void* data2, double weight)

description: inserts an undirected edge of weight weight in the graph specified by graph, between the vertex matching data1 and the vertex matching data2.

returns:
0 if the edge could be inserted, -1 otherwise.

since: YACLib 1.0
int graph_remove_edge(Graph* graph, const void* data1, const void* data2)

description: removes the edge that is incident from the vertex matching data1 and incident to the vertex matching data2, in the graph specified by graph.

return value:
0 if the edge could be removed, -1 otherwise.

since: YACLib 1.0

void graph_reset(Graph* graph)

description: This function resets all the vertexes in the graph specified by graph. It sets the color of each vertex to white, the root member to NULL and the d member to DBL_MAX. This function is necessary after a call to graph_dijkstra or graph_prism, because these functions change the values of the members of the vertexes in the graph.

return value:
none.

since: YACLib 1.0
void graph_destroy(Graph* graph)

description: destroys the graph specified by graph. It removes all edges and vertexes in the graph, calling the destroyfunc function passed to graph_create for each vertex as it is removed, provided destroy wasn't set to NULL.   

return value:
none.

since: YACLib 1.0
int graph_size(const Graph* graph)

description: macro that evaluates to the number o vertexes in the graph specified by graph.

return value:
the number o vertexes in graph.

since: YACLib 1.0
int graph_edges(const Graph* graph)

description: macro that evaluates to the number o edges in the graph specified by graph.

return value:
the number o edges in graph.

since: YACLib 1.0
int graph_vertex_data(const Vertex* vertex)

description: macro that evaluates to the data pointer of the vertex specified by vertex.

return value:
the data pointer of vertex.

since: YACLib 1.0