data_structures
graph_add_vertex.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* graph_add_vertex.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/22 00:51:16 by unite #+# #+# */
10 /* Updated: 2020/09/07 20:07:59 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "graph.h"
15 
16 void graph_add_vertex(t_graph *graph, const void *v)
17 {
18  t_array *array;
19 
20  if (rbt_contains(graph->adj, v))
21  return ;
22  array = array_new(graph->type);
23  rbt_put(graph->adj, v, array);
24  array_delete(array);
25  graph->v++;
26 }
rbt_contains
int rbt_contains(const t_rbt *rbt, const void *key)
Does the tree contain the specified key?
Definition: rbt_contains.c:16
s_graph::v
size_t v
The number of vertices.
Definition: graph.h:41
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_graph::type
const t_type * type
The type of vertices in the graph.
Definition: graph.h:44
s_array
A resizable array.
Definition: array.h:47
array_delete
void array_delete(t_array *array)
Deletes this array and free all its items and the associated data.
Definition: array_delete.c:16
graph.h
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
rbt_put
void rbt_put(t_rbt *rbt, const void *key, const void *val)
Adds a new item to the tree or overwrites an existing one.
Definition: rbt_put.c:45
array_new
t_array * array_new(const t_type *type)
Initializes a new empty array.
Definition: array_new.c:16