data_structures
graph_add_edge.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* graph_add_edge.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/22 00:55:53 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:48:50 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "graph.h"
15 
16 void graph_add_edge(t_graph *graph, const void *v1, const void *v2)
17 {
18  t_array *array_v1;
19  t_array *array_v2;
20 
21  if (!(array_v1 = rbt_get(graph->adj, v1)) ||
22  !(array_v2 = rbt_get(graph->adj, v2)))
23  ds_exit_set(EINVAL);
24  array_append(array_v1, v2);
25  array_append(array_v2, v1);
26  graph->e++;
27 }
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
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
s_graph
A graph implemented using a set of arrays.
Definition: graph.h:39
s_array
A resizable array.
Definition: array.h:47
rbt_get
void * rbt_get(const t_rbt *rbt, const void *key)
Returns the value associated with a specified key.
Definition: rbt_get.c:16
graph.h
ds_exit_set
void ds_exit_set(int err)
Set errno to the specified value, print the error message, and exit the process.
Definition: ds_exit_set.c:22
array_append
void array_append(t_array *array, const void *content)
Appends a copy the specified element to the end of this array.
Definition: array_append.c:17