C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
graph.h
Go to the documentation of this file.
1 
5 #pragma once
6 #include "common.h"
7 #include "link_list.h"
8 
10 typedef struct gnode {
12  int idx;
15 
17 typedef struct gedge {
19  int weight;
21 
22 // fn ptr for adding weighted edge
23 typedef t_gen (*f_wedge)(t_gen, t_gen, t_gen, int);
24 
26 typedef struct graph {
27  // graph info params
28  char *name;
29  int count;
30  int max_size;
32 
33  // graph nodes
35 
36  // graph routines
55 
56  // routies for operating on data
62 
64 typedef struct bfs_info{
66  int level;
67  int comp;
69 
71 typedef struct dfs_info{
73  int pre;
74  int post;
75  int comp;
78 
80 typedef struct dag_info{
83  int indegree;
85 
87 typedef struct dist_info {
91 
93 t_gen create_graph(char *name, int size, t_dparams *prm);
94 t_gen dijkstra(t_gen d, t_gen data);
95 t_gen bellman_ford(t_gen d, t_gen data);
Top level include containg common headers.
t_gen(* f_wedge)(t_gen, t_gen, t_gen, int)
Definition: graph.h:23
struct dag_info t_daginfo
Longest Path and Node order after DAG ordering.
struct graph t_graph
graph struct defn
t_gen dijkstra(t_gen d, t_gen data)
Utils function used by quick sort for swapping graph edges
Definition: graph.c:1043
t_gen kruskals_mst(t_gen d)
Find the Minimum Spanning for weighted undirected graph Using Kruskal's Algorithm
Definition: graph.c:1295
struct bfs_info t_bfsinfo
Level and Parent info after BFS walk.
struct dist_info t_distinfo
Dist info.
t_gen create_graph(char *name, int size, t_dparams *prm)
graph interface APIs
Definition: graph.c:42
struct dfs_info t_dfsinfo
Level and Parent info after DFS walk.
t_gen prims_mst(t_gen d)
Find the Minimum Spanning for weighted undirected graph Using Prim's Algorithm
Definition: graph.c:1217
struct gedge t_gedge
graph neighbor edges represented in neigh list
t_gen bellman_ford(t_gen d, t_gen data)
Find the shortest path from a given source vertex to all source nodes in a graph with negative edges ...
Definition: graph.c:1135
struct gnode t_gnode
graph Vertex
Level and Parent info after BFS walk.
Definition: graph.h:64
t_gen parent
Pointer to Parent Vertex.
Definition: graph.h:65
int comp
Subgraph id of vertex.
Definition: graph.h:67
int level
Level of vertex from the source.
Definition: graph.h:66
Longest Path and Node order after DAG ordering.
Definition: graph.h:80
int indegree
Used internally for topologicaly order and find longest path in DAG.
Definition: graph.h:83
int longest_path
Longest path to vertex in DAG.
Definition: graph.h:82
t_gen node
Pointer to Vertex in topologically sorted order.
Definition: graph.h:81
data params struct defn
Definition: common.h:18
Level and Parent info after DFS walk.
Definition: graph.h:71
t_gen parent
Pointer to Parent Vertex.
Definition: graph.h:72
int post
Post Interval of a vertex on dfs walk.
Definition: graph.h:74
int comp
Subgraph id of vertex.
Definition: graph.h:75
int visited_neighbors
Used internally Flag indicating neighbors still to be visited.
Definition: graph.h:76
int pre
Pre Interval of a vertex on dfs walk.
Definition: graph.h:73
Dist info.
Definition: graph.h:87
t_gnode * parent
Pointer to Vertex vertex.
Definition: graph.h:89
t_gedge edge
Pointer to edge.
Definition: graph.h:88
graph neighbor edges represented in neigh list
Definition: graph.h:17
int weight
Cost of the edge.
Definition: graph.h:19
t_gnode * node
Pointer to neighbor vertex.
Definition: graph.h:18
graph Vertex
Definition: graph.h:10
t_linklist * neigh
Link List to neighbor vertices(nodes)
Definition: graph.h:13
t_gen id
Pointer to store Data.
Definition: graph.h:11
int idx
Index of vertex in adaceny list.
Definition: graph.h:12
graph struct defn
Definition: graph.h:26
f_find find
routine to find a vertex in graph
Definition: graph.h:50
f_len len
routine to get vertex count in graph
Definition: graph.h:51
f_cmpr cmpr
Definition: graph.h:57
f_print wprint
routine to print graph info with edge weights
Definition: graph.h:53
f_gen3 del_edge_sym
routine to del a symmetric edge in graph
Definition: graph.h:42
f_swap swap
Definition: graph.h:58
f_print print
routine to print graph info
Definition: graph.h:52
f_gen conn_comp
routine to get the connected components in graph
Definition: graph.h:48
t_gnode * nodes
Adaceny List Representation of graph vertices.
Definition: graph.h:34
f_wedge add_wedge_sym
routine to add a weighted symmetric edge in graph
Definition: graph.h:44
char * name
Graph Instance Name.
Definition: graph.h:28
f_destroy destroy
routine to destroy the graph instance
Definition: graph.h:54
f_free free
Definition: graph.h:59
f_gen3 add_edge_sym
routine to add a symmetric edge in graph
Definition: graph.h:41
f_gen3 del_edge
routine to del an edge in graph
Definition: graph.h:40
f_gen3 has_edge
routine to check an edge between two vertices graph
Definition: graph.h:45
f_gen3 add_edge
routine to add an edge in graph
Definition: graph.h:39
int max_size
Max Vertex count of graph.
Definition: graph.h:30
f_wedge add_wedge
routine to add a weighted edge in graph
Definition: graph.h:43
f_print print_data
Definition: graph.h:60
f_gen2 bfs
routine to Breadth First Search in graph
Definition: graph.h:46
f_gen2 del_vertex
routine to del a vertex in graph
Definition: graph.h:38
int count
Vertex Count of graph.
Definition: graph.h:29
f_gen2 dfs
routine to Depth First Search in graph
Definition: graph.h:47
f_gen topo_order_dag
routine to topologica order a DAG
Definition: graph.h:49
f_gen2 add_vertex
routine to add a vertex in graph
Definition: graph.h:37
int total_edges
Edge count of graph.
Definition: graph.h:31
f_gen2 f_find
fn type of find a elem function
Definition: typedefs.h:60
void(* f_free)(t_gen, char *, int)
Definition: typedefs.h:67
f_vgen f_print
fn type to print function
Definition: typedefs.h:56
f_vgen f_destroy
fn type of destroy function
Definition: typedefs.h:61
e_cmpr(* f_cmpr)(t_gen, t_gen)
Basic operations required for generic data type support.
Definition: typedefs.h:66
t_gen(* f_gen2)(t_gen, t_gen)
fn ptr that takes two gen ptr and return gen ptr
Definition: typedefs.h:47
int(* f_len)(t_gen)
fn type of get len function
Definition: typedefs.h:55
void * t_gen
Base Data type used for all data structure and data elements.
Definition: typedefs.h:41
t_gen(* f_gen)(t_gen)
Generic data pointer definitions that are common to most data structure operations.
Definition: typedefs.h:46
t_gen(* f_gen3)(t_gen, t_gen, t_gen)
fn ptr that takes three gen ptr and return gen ptr
Definition: typedefs.h:48
f_vgen2 f_swap
Definition: typedefs.h:69