data_structures
rbt_new.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* rbt_new.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2020/07/17 22:05:33 by unite #+# #+# */
10 /* Updated: 2020/09/07 22:09:27 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "rbt.h"
15 
16 t_rbt *rbt_new(const t_type *key_type, const t_type *val_type)
17 {
18  t_rbt *rbt;
19 
20  if (!key_type || !key_type->cmp || !val_type)
21  ds_exit_set(EINVAL);
22  rbt = ds_xcalloc(sizeof(t_rbt), 1);
23  rbt->key_type = key_type;
24  rbt->val_type = val_type;
25  return (rbt);
26 }
s_rbt
A left-leaning red-black binary search tree.
Definition: rbt.h:72
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_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition: types.h:52
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_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
s_rbt::val_type
const t_type * val_type
The type of values in the ree.
Definition: rbt.h:76
s_rbt::key_type
const t_type * key_type
The type of keys in the tree.
Definition: rbt.h:75
rbt.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