data_structures
graph_new.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* graph_new.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/22 00:44:01 by unite #+# #+# */
10 /* Updated: 2020/09/07 21:46:01 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "graph.h"
15 
16 t_graph *graph_new(const t_type *type)
17 {
18  t_graph *graph;
19 
20  graph = ds_xcalloc(sizeof(t_graph), 1);
21  graph->adj = rbt_new(type, g_type_array);
22  graph->v = 0;
23  graph->e = 0;
24  graph->type = type;
25  return (graph);
26 }
ds_xcalloc
void * ds_xcalloc(size_t count, size_t size)
Replicates behaviour of calloc from libc, but fails on memory allocation errors.
Definition: ds_xcalloc.c:22
s_graph::v
size_t v
The number of vertices.
Definition: graph.h:41
rbt_new
t_rbt * rbt_new(const t_type *key_type, const t_type *val_type)
Initializes a new empty tree.
Definition: rbt_new.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_graph::type
const t_type * type
The type of vertices in the graph.
Definition: graph.h:44
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
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.h
g_type_array
const t_type * g_type_array
A representation of the t_array data type.
Definition: type_array.c:33