Usage - lamcw/bitmap-graph GitHub Wiki
Detailed usage of each function can be found here.
Data types
bmgraph_t
An abstract data type. A pointer to internal struct _bmgraph_t. Declared as typedef struct _bmgraph_t *bmgraph_t;
vertex_t
Declared as typedef uint32_t vertex_t.
uint_t
Declared as typedef uint32_t uint_t. Used for size of graphs and tracking the index of bitmap matrix.
Functions
bmgraph_t mkgraph(uint32_t nv)
Malloc a _bmgraph_t struct and initialize all fields inside the struct.
Return value
On success, pointer to the malloc'd struct (a.k.a bmgraph_t) is returned. Otherwise NULL would be returned.
int mkedge(bmgraph_t g, vertex_t from, vertex_t to)
Create an edge from vertex from to vertex to.
Return value
On success, 0 is returned.
int rmedge(bmgraph_t g, vertex_t from, vertex_t to)
Remove the edge from vertex from to vertex to.
Return value
On success, 0 is returned.
int has_edge(bmgraph_t g, vertex_t from, vertex_t to)
Check if vertex from has an edge to to.
Return value
Returns 1 if there is an "edge" from from to to, 0 otherwise. Also returns 0 if g == NULL or from and to are invalid.
int indegree(bmgraph_t g, vertex_t v)
Find the in degree of vertex v.
Return value
Returns the in degree of vertex v. Returns -1 if an error occurs.
int outdegree(bmgraph_t g, vertex_t v)
Find the out degree of vertex v.
Return value
Returns the out degree of vertex v. Returns -1 if an error occurs.
void show_graph(bmgraph_t g, int mode)
Print the bitmap matrix to stdout.
Options
D_MTRX- print adjacency matrixD_LIST- print adjacency listD_READ- print in human-readable format (WIP)
Sample Usage
Print matrix only:
bmgraph_t g = mkgraph(10);
mkedge(g, 1, 2);
show_graph(g, D_MTRX);
destroy_graph(g);
Print matrix and list:
show_graph(g, D_MTRX | D_LIST);
void destroy_graph(bmgraph_t g)
Free all memory allocated for g.