data_structures
bst_new.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* bst_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 21:51:40 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "bst.h"
15 
16 t_bst *bst_new(const t_type *key_type, const t_type *val_type)
17 {
18  t_bst *bst;
19 
20  if (!key_type->cmp)
21  ds_exit_set(EINVAL);
22  bst = ds_xcalloc(sizeof(t_bst), 1);
23  bst->key_type = key_type;
24  bst->val_type = val_type;
25  return (bst);
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_type::cmp
int(* cmp)(const void *, const void *)
(optional) A function ponter used to compare members of this data type
Definition: types.h:52
bst_new
t_bst * bst_new(const t_type *key_type, const t_type *val_type)
Initializes a new empty tree.
Definition: bst_new.c:16
s_bst::val_type
const t_type * val_type
The type of values in the ree.
Definition: bst.h:62
s_bst::key_type
const t_type * key_type
The type of keys in the tree.
Definition: bst.h:61
s_type
A full representation of a data type, used to achieve polymorphism in the implementation of data stru...
Definition: types.h:47
bst.h
s_bst
A binary search tree.
Definition: bst.h:57
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