data_structures
graph.h
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* graph.h :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/22 00:10:11 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:34:48 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #ifndef GRAPH_H
15 
16 # define GRAPH_H
17 
18 # include <errno.h>
19 # include <sys/types.h>
20 # include "types.h"
21 # include "array.h"
22 # include "rbt.h"
23 # include "utils.h"
24 
39 typedef struct s_graph
40 {
41  size_t v;
42  size_t e;
44  const t_type *type;
45 } t_graph;
46 
53 t_graph *graph_new(const t_type *type);
54 
60 void graph_add_vertex(t_graph *graph, const void *v);
61 
68 void graph_add_edge(t_graph *graph, const void *v1, const void *v2);
69 
75 void graph_delete(t_graph *graph);
76 
82 t_queue *graph_vertices(const t_graph *graph);
83 
92 t_queue *graph_adjacency(const t_graph *graph, const void *v);
93 
101 int graph_adjacent(const t_graph *graph, const void *v1,
102  const void *v2);
103 
104 #endif
types.h
s_rbt
A left-leaning red-black binary search tree.
Definition: rbt.h:72
graph_adjacency
t_queue * graph_adjacency(const t_graph *graph, const void *v)
Returns the queue with all the vertices in this graph that are adjancent to the specified vertex.
Definition: graph_adjacency.c:16
array.h
s_graph::v
size_t v
The number of vertices.
Definition: graph.h:41
graph_add_edge
void graph_add_edge(t_graph *graph, const void *v1, const void *v2)
Adds an edge between two vertices in the graph.
Definition: graph_add_edge.c:16
graph_vertices
t_queue * graph_vertices(const t_graph *graph)
Returns the queue with all the vertices in this graph.
Definition: graph_vertices.c:16
graph_delete
void graph_delete(t_graph *graph)
Deletes this graph and frees all the associated data.
Definition: graph_delete.c:16
s_graph::e
size_t e
The number of edges.
Definition: graph.h:42
s_graph::adj
t_rbt * adj
The set of arrays, where each arrays represents the adjacency of a given vertex.
Definition: graph.h:43
utils.h
s_graph
A graph implemented using a set of arrays.
Definition: graph.h:39
s_graph::type
const t_type * type
The type of vertices in the graph.
Definition: graph.h:44
s_list
Doubly-linked list of generic items.
Definition: list.h:54
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
rbt.h
graph_adjacent
int graph_adjacent(const t_graph *graph, const void *v1, const void *v2)
Are two vertices in the graph adjacent to each other?
Definition: graph_adjacent.c:16
graph_new
t_graph * graph_new(const t_type *type)
Initializes a new graph with vertices of the specified type.
Definition: graph_new.c:16
graph_add_vertex
void graph_add_vertex(t_graph *graph, const void *v)
Adds a vertex to the graph.
Definition: graph_add_vertex.c:16