Data Structures Lerax  1.1.0
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1
12
13#ifndef GRAPH_H
14#define GRAPH_H
15
16#include <stdbool.h>
17#include "../set/set.h"
18
19typedef struct Graph Graph;
20
27
28static inline const char* graph_edge_type_name(EdgeType edge_type) {
29 switch (edge_type) {
30 case TREE: return "TREE";
31 case CROSS: return "CROSS";
32 case FORWARD: return "FORWARD";
33 case BACK: return "BACK";
34 }
35 return "?";
36}
37
38
45
52
59Graph* graph_tarjan_create(bool directed);
60
66size_t graph_size(Graph *g);
67
74
81
88void graph_add_node(Graph *g, int node);
89
97void graph_add_edge(Graph *g, int u, int v);
98
107void graph_add_edge_with_weight(Graph *g, int u, int v, int weight);
108
109
118int graph_get_edge_weight(Graph *g, int u, int v);
119
120
128void graph_remove_edge(Graph *g, int u, int v);
129
136void graph_remove_node(Graph *g, int node);
137
146bool graph_has_edge(Graph *g, int u, int v);
147
155bool graph_has_node(Graph *g, int u);
156
165
172
179
186void graph_export_to_dot(Graph *g, const char* filename);
187
195Iterator* graph_bfs(Graph *g, int start_node);
196
204Iterator* graph_dfs(Graph *g, int start_node);
205
212
219
226
233
240
248
256
264
272
282
290Graph* graph_dijkstra(Graph* g, int source);
291
299
307Graph* graph_prim(Graph* g, int start);
308
317int graph_minimum_distance(Graph* g, int source, int destination);
318
327List* graph_shortest_path(Graph* g, int source, int destination);
328
329#endif /* GRAPH_H */
struct Graph Graph
Definition graph.h:19
edgeType
Definition graph.h:21
@ TREE
Definition graph.h:22
@ FORWARD
Definition graph.h:24
@ BACK
Definition graph.h:25
@ CROSS
Definition graph.h:23
enum edgeType EdgeType
bool graph_is_weighted(Graph *g)
Check if graph is weighted.
int * graph_strong_components(Graph *g)
Create a array of strong components using tarjan algorithm.
Graph * graph_undirected_create()
Creates a new undirected graph.
Graph * graph_tarjan(Graph *g)
Create a new graph with tarjan arc classification as weight of the edges.
int graph_get_edge_weight(Graph *g, int u, int v)
Gets the weight of an edge.
Set * graph_get_neighbors(Graph *g, int node)
Gets the neighbors of a node.
bool graph_is_directed(Graph *g)
Check if graph is weighted.
void graph_remove_edge(Graph *g, int u, int v)
Removes an edge from the graph.
Graph * graph_create()
Creates a new directed graph.
Graph * graph_kruskal(Graph *g)
Run Kruskal algorithm to get the minimum-span tree.
Graph * graph_dijkstra(Graph *g, int source)
Run dijkstra algorithm on the graph.
int graph_max_node_id(Graph *g)
Get the maximum node id on the graph.
Iterator * graph_dfs(Graph *g, int start_node)
Performs a Depth-First Search on a graph.
void graph_add_node(Graph *g, int node)
Adds a node to the graph.
Iterator * graph_bfs(Graph *g, int start_node)
Performs a Breadth-First Search on a graph.
Graph * graph_prim(Graph *g, int start)
Run Prim algorithm to get the minimum-span tree.
void graph_export_to_dot(Graph *g, const char *filename)
Exports the graph to a DOT file for visualization with Graphviz.
Graph * graph_tarjan_create(bool directed)
Creates a new tarjan graph.
List * graph_topological_sort(Graph *g)
Creat a list with the nodes in topological sort.
void graph_add_edge(Graph *g, int u, int v)
Adds an edge to the graph.
void graph_print(Graph *g)
Prints the graph.
bool graph_is_dag(Graph *g)
Check if graph can be classified as Directed Acyclical Graph.
bool graph_has_edge(Graph *g, int u, int v)
Checks if an edge exists in the graph.
bool graph_acyclical(Graph *g)
Check if graph has cycles.
void graph_free(Graph *g)
Frees the memory allocated for the graph.
void graph_remove_node(Graph *g, int node)
Removes a node from the graph.
bool graph_has_node(Graph *g, int u)
Checks if a node exists in the graph.
List * graph_edges_ordered(Graph *g)
List with edges of the graph with (key,data) ordered ascending.
int graph_edges_sum(Graph *g)
Sum of the edge weights. If undirected, calculate (u, v) == (v, u) only once.
List * graph_shortest_path(Graph *g, int source, int destination)
Run dijkstra algorithm and return the shortest path.
void graph_add_edge_with_weight(Graph *g, int u, int v, int weight)
Adds a weighted edge to the graph.
int graph_minimum_distance(Graph *g, int source, int destination)
Run dijkstra algorithm and calculate the minimum distance.
Iterator * graph_nodes_iterator(Graph *g)
Iterate over nodes of the graph.
List * graph_edges(Graph *g)
List with edges of the graph with (key,data).
size_t graph_size(Graph *g)
Get the number of nodes.
struct ListNode List
A singly linked list.
Definition list.h:36
struct Set Set
A basic implementation of a Set.
Definition set.h:27
A generic iterator struct.
Definition iterator.h:13